diff --git a/deploy.sh b/deploy.sh index 484f45864..4e7ba2a41 100755 --- a/deploy.sh +++ b/deploy.sh @@ -4,7 +4,7 @@ kubectl create namespace piper-kt kubectl apply -f kubernetes/auth.yml helm repo add mongodb https://mongodb.github.io/helm-charts -helm install strimzi-cluster-operator --set replicas=1 --set resources.limits.cpu=500 oci://quay.io/strimzi-helm/strimzi-kafka-operator --namespace piper-kt +helm install strimzi-cluster-operator --set replicas=1 --set resources.limits.cpu=700 oci://quay.io/strimzi-helm/strimzi-kafka-operator --namespace piper-kt kubectl apply -f kubernetes/kafka.yml --namespace piper-kt helm install --set image.tag=0.9.0-arm64 community-operator mongodb/community-operator --namespace piper-kt \ --set watchNamespaces=piper-kt\ @@ -12,7 +12,6 @@ helm install --set image.tag=0.9.0-arm64 community-operator mongodb/community-op microservice_list=("friendships-service" "users-service" "servers-service" "multimedia-service") -#microservice_list=("users-service") for microservice in "${microservice_list[@]}" do helm install $microservice kubernetes/helm-chart/piper-chart --values $microservice/helm-values/micronaut-values.yaml diff --git a/frontend-service/src/main/vue/api/errors.ts b/frontend-service/src/main/vue/api/errors.ts index 2981719a2..e40a216fd 100644 --- a/frontend-service/src/main/vue/api/errors.ts +++ b/frontend-service/src/main/vue/api/errors.ts @@ -2,7 +2,7 @@ import { ErrorResponse } from "./response"; export class InternalServerError extends ErrorResponse { statusCode = 500; - error = "Internal Server Error" as const; + message = "Internal Server Error" as const; errorMessage: unknown; constructor(e: unknown = "") { super(); @@ -12,7 +12,7 @@ export class InternalServerError extends ErrorResponse { export class BadRequest extends ErrorResponse { statusCode = 400; - error = "Bad Request" as const; + message = "Bad Request" as const; missingParams: string[]; missingBody: string[]; missingQuery?: string[]; @@ -26,5 +26,5 @@ export class BadRequest extends ErrorResponse { export class JwtTokenMissingOrInvalid extends ErrorResponse { statusCode = 401; - error = "JWT Token Missing or Invalid" as const; + message = "JWT Token Missing or Invalid" as const; } diff --git a/frontend-service/src/main/vue/api/messages/channel.ts b/frontend-service/src/main/vue/api/messages/channel.ts index 5fa79b58e..9d44316e4 100644 --- a/frontend-service/src/main/vue/api/messages/channel.ts +++ b/frontend-service/src/main/vue/api/messages/channel.ts @@ -44,16 +44,16 @@ export module GetChannelMessagesApi { export module Errors { export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ChannelNotFound | ServerNotFound | UserNotAuthorized; @@ -91,15 +91,15 @@ export module SendMessageInChannelApi { export module Errors { export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ChannelNotFound | ServerNotFound | UserNotAuthorized; } diff --git a/frontend-service/src/main/vue/api/messages/direct.ts b/frontend-service/src/main/vue/api/messages/direct.ts index 198f70933..f73a4961d 100644 --- a/frontend-service/src/main/vue/api/messages/direct.ts +++ b/frontend-service/src/main/vue/api/messages/direct.ts @@ -42,7 +42,7 @@ export module GetDirectMessagesApi { export module Errors { export class DirectNotFound extends ErrorResponse { statusCode = 404; - error = "Direct not found" as const; + message = "Direct not found" as const; } export type Type = DirectNotFound; } @@ -56,7 +56,7 @@ export module SendDirectMessageApi { username: string; }; export type Body = { - message: string; + content: string; }; export type Query = Empty; export const Schema: RequestSchema = { @@ -78,11 +78,11 @@ export module SendDirectMessageApi { export module Errors { export class DirectNotFound extends ErrorResponse { statusCode = 404; - error = "Direct not found" as const; + message = "Direct not found" as const; } export class CannotSendDirectMessageToYourself extends ErrorResponse { statusCode = 400; - error = "Cannot send direct message to yourself" as const; + message = "Cannot send direct message to yourself" as const; } export type Type = DirectNotFound | CannotSendDirectMessageToYourself; } diff --git a/frontend-service/src/main/vue/api/piperchat/channel.ts b/frontend-service/src/main/vue/api/piperchat/channel.ts index 203bfb040..504cdab21 100644 --- a/frontend-service/src/main/vue/api/piperchat/channel.ts +++ b/frontend-service/src/main/vue/api/piperchat/channel.ts @@ -15,32 +15,37 @@ export module GetChannelsApi { Body: {}, }; } + export module Responses { interface Channel { id: string; name: string; - createdAt: Date; - channelType: string; + type: string; description?: string; } + export class Success extends Response { statusCode = 200; message = "Channels retrieved successfully"; + constructor(public channels: Channel[]) { super(); } } + export type Type = Success; } export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } + export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } + export type Type = ServerNotFound | UserNotAuthorized; } export type Response = Responses.Type | Errors.Type; @@ -65,32 +70,35 @@ export module GetChannelByIdApi { export interface Channel { id: string; name: string; - createdAt: Date; - channelType: string; + type: string; description?: string; } + export class Success extends Response { statusCode = 200; message = "Channels retrieved successfully"; + constructor(public channel: Channel) { super(); } } + export type Type = Success; } export module Errors { export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } + export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export type Type = ChannelNotFound | UserNotAuthorized | ServerNotFound; @@ -100,9 +108,10 @@ export module GetChannelByIdApi { export module CreateChannelApi { export enum ChannelType { - Messages = "messages", - Multimedia = "multimedia", + Messages = "TEXT", + Multimedia = "MULTIMEDIA", } + export module Request { export type Type = Body & Params; export type Params = { @@ -132,35 +141,39 @@ export module CreateChannelApi { channelType: string; description?: string; } + export class Success extends Response { statusCode = 200; message = "Channel created successfully"; channel: Channel; + constructor(channel: Channel) { super(); this.channel = channel; } } + export type Type = Success; } export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } + export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class ChannelAlreadyExists extends ErrorResponse { statusCode = 409; - error = "Channel already exists" as const; + message = "Channel already exists" as const; } export class InvalidChannelType extends ErrorResponse { statusCode = 400; - error = "Invalid channel type" as const; + message = "Invalid channel type" as const; } export type Type = @@ -199,26 +212,30 @@ export module UpdateChannelApi { statusCode = 200; message = "Channel updated successfully"; } + export type Type = Success; } export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } + export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } + export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class ChannelAlreadyExists extends ErrorResponse { statusCode = 409; - error = "Channel already exists" as const; + message = "Channel already exists" as const; } + export type Type = | ServerNotFound | ChannelNotFound @@ -249,21 +266,25 @@ export module DeleteChannelApi { statusCode = 200; message = "Channel deleted successfully"; } + export type Type = Success; } export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } + export class ChannelNotFound extends ErrorResponse { statusCode = 404; - error = "Channel not found" as const; + message = "Channel not found" as const; } + export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } + export type Type = ServerNotFound | ChannelNotFound | UserNotAuthorized; } export type Response = Responses.Type | Errors.Type; diff --git a/frontend-service/src/main/vue/api/piperchat/server.ts b/frontend-service/src/main/vue/api/piperchat/server.ts index 0fbf916c4..b916747c8 100644 --- a/frontend-service/src/main/vue/api/piperchat/server.ts +++ b/frontend-service/src/main/vue/api/piperchat/server.ts @@ -27,15 +27,15 @@ export module KickUserFromServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server or user not found" as const; + message = "Server or user not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class OwnerCannotLeave extends ErrorResponse { statusCode = 405; - error = "Owner cannot leave the server" as const; + message = "Owner cannot leave the server" as const; } export type Type = ServerNotFound | UserNotAuthorized | OwnerCannotLeave; } @@ -68,11 +68,11 @@ export module GetServerParticipantsApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -103,11 +103,11 @@ export module JoinServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserAlreadyJoined extends ErrorResponse { statusCode = 403; - error = "User already joined" as const; + message = "User already joined" as const; } export type Type = ServerNotFound | UserAlreadyJoined; } @@ -138,15 +138,15 @@ export module LeaveServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotInServer extends ErrorResponse { statusCode = 403; - error = "User not in server" as const; + message = "User not in server" as const; } export class OwnerCannotLeave extends ErrorResponse { statusCode = 422; - error = "Owner cannot leave the server" as const; + message = "Owner cannot leave the server" as const; } export type Type = ServerNotFound | UserNotInServer | OwnerCannotLeave; } @@ -171,7 +171,6 @@ export module GetServerApi { export interface Channel { id: string; name: string; - createdAt: Date; channelType: string; description?: string; } @@ -180,8 +179,7 @@ export module GetServerApi { name: string; description: string; owner: string; - participants: string[]; - createdAt: Date; + users: string[]; channels: Channel[]; } export class Success extends Response { @@ -195,11 +193,11 @@ export module GetServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -236,15 +234,15 @@ export module UpdateServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export class NameOrDescriptionRequired extends ErrorResponse { statusCode = 422; - error = "Name or description required" as const; + message = "Name or description required" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -275,11 +273,11 @@ export module DeleteServerApi { export module Errors { export class ServerNotFound extends ErrorResponse { statusCode = 404; - error = "Server not found" as const; + message = "Server not found" as const; } export class UserNotAuthorized extends ErrorResponse { statusCode = 403; - error = "User not authorized" as const; + message = "User not authorized" as const; } export type Type = ServerNotFound | UserNotAuthorized; } @@ -301,7 +299,7 @@ export module GetServersApi { id: string; name: string; createdAt: Date; - channelType: string; + type: string; description?: string; } export interface Server { @@ -309,7 +307,7 @@ export module GetServersApi { name: string; description: string; owner: string; - participants: string[]; + users: string[]; createdAt: Date; channels: Channel[]; } @@ -324,7 +322,7 @@ export module GetServersApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -362,7 +360,7 @@ export module CreateServerApi { export module Errors { export class NameOrDescriptionRequired extends ErrorResponse { statusCode = 422; - error = "Name or description required" as const; + message = "Name or description required" as const; } export type Type = NameOrDescriptionRequired; } diff --git a/frontend-service/src/main/vue/api/response.ts b/frontend-service/src/main/vue/api/response.ts index 3fb4a95f8..24f41ad5f 100644 --- a/frontend-service/src/main/vue/api/response.ts +++ b/frontend-service/src/main/vue/api/response.ts @@ -16,5 +16,5 @@ export abstract class Response { } export abstract class ErrorResponse extends Response { - abstract error: string; + abstract message: string; } diff --git a/frontend-service/src/main/vue/api/users/auth.ts b/frontend-service/src/main/vue/api/users/auth.ts index c46c07293..bcef27ff6 100644 --- a/frontend-service/src/main/vue/api/users/auth.ts +++ b/frontend-service/src/main/vue/api/users/auth.ts @@ -61,12 +61,12 @@ export module RegisterApi { export module Errors { export class UserAlreadyExists extends ErrorResponse { statusCode = 409; - error = "User already exists" as const; + message = "User already exists" as const; } export class EmailAlreadyExists extends ErrorResponse { statusCode = 409; - error = "Email already exists" as const; + message = "Email already exists" as const; } export type Type = UserAlreadyExists | EmailAlreadyExists; @@ -116,7 +116,7 @@ export module LoginApi { export module Errors { export class UsernameOrPasswordIncorrect extends ErrorResponse { statusCode = 401; - error = "Username or password incorrect" as const; + message = "Username or password incorrect" as const; } export type Type = UsernameOrPasswordIncorrect; } @@ -149,7 +149,7 @@ export module LogoutApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -185,11 +185,11 @@ export module RefreshTokenApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export class InvalidRefreshToken extends ErrorResponse { statusCode = 401; - error = "Refresh token is missing or invalid" as const; + message = "Refresh token is missing or invalid" as const; } export type Type = UserNotFound | InvalidRefreshToken; } diff --git a/frontend-service/src/main/vue/api/users/friends.ts b/frontend-service/src/main/vue/api/users/friends.ts index c895f862e..177b19241 100644 --- a/frontend-service/src/main/vue/api/users/friends.ts +++ b/frontend-service/src/main/vue/api/users/friends.ts @@ -23,7 +23,7 @@ export module GetFriendsApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -51,7 +51,7 @@ export module GetFriendsRequestsApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -83,19 +83,19 @@ export module SendFriendRequestApi { export module Errors { export class InvalidAction extends ErrorResponse { statusCode = 400; - error: string; + message: string; constructor(action: string) { super(); - this.error = `Invalid 'action' parameter in body: '${action}'`; + this.message = `Invalid 'action' parameter in body: '${action}'`; } } export class FriendRequestAlreadySent extends ErrorResponse { statusCode = 409; - error = "Friend request already sent" as const; + message = "Friend request already sent" as const; } export class FriendRequestNotFound extends ErrorResponse { statusCode = 404; - error = "Friend request not found" as const; + message = "Friend request not found" as const; } export type Type = @@ -131,15 +131,15 @@ export module AcceptFriendRequestApi { export module Errors { export class InvalidAction extends ErrorResponse { statusCode = 400; - error: string; + message: string; constructor(action: string) { super(); - this.error = `Invalid 'action' parameter in body: '${action}'`; + this.message = `Invalid 'action' parameter in body: '${action}'`; } } export class FriendRequestNotFound extends ErrorResponse { statusCode = 404; - error = "Friend request not found" as const; + message = "Friend request not found" as const; } export type Type = FriendRequestNotFound; @@ -172,16 +172,16 @@ export module DeclineFriendRequestApi { export module Errors { export class InvalidAction extends ErrorResponse { statusCode = 400; - error: string; + message: string; constructor(action: string) { super(); - this.error = `Invalid 'action' parameter in body: '${action}'`; + this.message = `Invalid 'action' parameter in body: '${action}'`; } } export class FriendRequestNotFound extends ErrorResponse { statusCode = 404; - error = "Friend request not found" as const; + message = "Friend request not found" as const; } export type Type = InvalidAction | FriendRequestNotFound; diff --git a/frontend-service/src/main/vue/api/users/user.ts b/frontend-service/src/main/vue/api/users/user.ts index 6df8dcb8a..fab71a7d8 100644 --- a/frontend-service/src/main/vue/api/users/user.ts +++ b/frontend-service/src/main/vue/api/users/user.ts @@ -71,7 +71,7 @@ export module GetUserStatusApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -109,7 +109,7 @@ export module GetUserPhotoApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } @@ -147,7 +147,7 @@ export module GetUserDescriptionApi { export module Errors { export class UserNotFound extends ErrorResponse { statusCode = 404; - error = "User not found" as const; + message = "User not found" as const; } export type Type = UserNotFound; } diff --git a/frontend-service/src/main/vue/components/home/left-bar/ChannelsList.vue b/frontend-service/src/main/vue/components/home/left-bar/ChannelsList.vue index 79474808c..0340a490b 100644 --- a/frontend-service/src/main/vue/components/home/left-bar/ChannelsList.vue +++ b/frontend-service/src/main/vue/components/home/left-bar/ChannelsList.vue @@ -121,7 +121,7 @@ function leaveServer() { separator class="text-white text-h5" v-for="channel in appStore.selectedServer?.channels?.filter( - (c) => c.channelType == CreateChannelApi.ChannelType.Messages + (c) => c.type == CreateChannelApi.ChannelType.Messages )" :key="channel.id" @click="appStore.selectChannel(channel)" @@ -136,7 +136,7 @@ function leaveServer() { separator class="text-white text-h5" v-for="channel in appStore.selectedServer?.channels?.filter( - (c) => c.channelType == CreateChannelApi.ChannelType.Multimedia + (c) => c.type == CreateChannelApi.ChannelType.Multimedia )" :key="channel.id" > diff --git a/frontend-service/src/main/vue/components/home/left-bar/menu/ServerMenu.vue b/frontend-service/src/main/vue/components/home/left-bar/menu/ServerMenu.vue index bb5aa9f22..f00697d0f 100644 --- a/frontend-service/src/main/vue/components/home/left-bar/menu/ServerMenu.vue +++ b/frontend-service/src/main/vue/components/home/left-bar/menu/ServerMenu.vue @@ -236,7 +236,7 @@ onMounted(() => {
Partecipants
p !== userStore.username )" :key="user" diff --git a/frontend-service/src/main/vue/controllers/axios-controller.ts b/frontend-service/src/main/vue/controllers/axios-controller.ts index 22080b9c4..d3e4d1bf5 100644 --- a/frontend-service/src/main/vue/controllers/axios-controller.ts +++ b/frontend-service/src/main/vue/controllers/axios-controller.ts @@ -39,7 +39,10 @@ export abstract class AxiosController { const errorResponse = e.response.data as InternalServerError; throw new Error(errorResponse.toString()); } else { - return e.response.data as Response; + return { + statusCode: e.response.status, + ...e.response.data, + } as Response; } } } diff --git a/frontend-service/src/main/vue/controllers/piperchat/server/server-controller-impl.ts b/frontend-service/src/main/vue/controllers/piperchat/server/server-controller-impl.ts index f30963ed5..6db6e76b2 100644 --- a/frontend-service/src/main/vue/controllers/piperchat/server/server-controller-impl.ts +++ b/frontend-service/src/main/vue/controllers/piperchat/server/server-controller-impl.ts @@ -59,7 +59,7 @@ export class ServerControllerImpl ): Promise { const params = request as GetServerParticipantsApi.Request.Params; return await this.get( - `/servers/${params.serverId}/participants` + `/servers/${params.serverId}/users` ); } @@ -68,7 +68,7 @@ export class ServerControllerImpl ): Promise { const params = request as JoinServerApi.Request.Params; return await this.post( - `/servers/${params.serverId}/participants` + `/servers/${params.serverId}/users` ); } @@ -77,7 +77,7 @@ export class ServerControllerImpl ): Promise { const params = request as LeaveServerApi.Request.Params; return await this.delete( - `/servers/${params.serverId}/participants` + `/servers/${params.serverId}/users` ); } @@ -87,7 +87,7 @@ export class ServerControllerImpl const params = request as KickUserFromServerApi.Request.Params; const body = request as KickUserFromServerApi.Request.Body; return await this.delete( - `/servers/${params.serverId}/participants/${params.username}`, + `/servers/${params.serverId}/users/${params.username}`, body ); } diff --git a/frontend-service/src/main/vue/main.ts b/frontend-service/src/main/vue/main.ts index 6ec9d1059..c4cf91a69 100644 --- a/frontend-service/src/main/vue/main.ts +++ b/frontend-service/src/main/vue/main.ts @@ -22,6 +22,7 @@ pinia.use(piniaPluginPersistedState); router.beforeEach((to, from, next) => { const userStore = useUserStore(); if (to.meta.requiresAuth && !userStore.isLoggedIn) { + console.log("Requires auth"); next("/login"); } else { next(); diff --git a/frontend-service/src/main/vue/stores/app.ts b/frontend-service/src/main/vue/stores/app.ts index 7eed56bf9..6604273b8 100644 --- a/frontend-service/src/main/vue/stores/app.ts +++ b/frontend-service/src/main/vue/stores/app.ts @@ -31,13 +31,13 @@ export const useAppStore = defineStore( () => (selectedDirect.value !== null && !inDirectCall.value) || (selectedChannel.value !== null && - selectedChannel.value.channelType !== "multimedia") + selectedChannel.value.type !== "MULTIMEDIA") ); const isVideoSection = computed( () => (selectedChannel.value !== null && - selectedChannel.value.channelType == "multimedia") || + selectedChannel.value.type == "MULTIMEDIA") || (selectedDirect.value !== null && inDirectCall.value) ); diff --git a/frontend-service/src/main/vue/stores/friend.ts b/frontend-service/src/main/vue/stores/friend.ts index bd3875f6d..e50ed6b59 100644 --- a/frontend-service/src/main/vue/stores/friend.ts +++ b/frontend-service/src/main/vue/stores/friend.ts @@ -63,7 +63,7 @@ export const useFriendStore = defineStore( const response = await friendsController.sendFriendRequest(username); if (response.statusCode !== 200) { const typed = response as DeclineFriendRequestApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } @@ -73,7 +73,7 @@ export const useFriendStore = defineStore( await refresh(); } else { const typed = response as DeclineFriendRequestApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } @@ -83,7 +83,7 @@ export const useFriendStore = defineStore( await refresh(); } else { const typed = response as DeclineFriendRequestApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } diff --git a/frontend-service/src/main/vue/stores/messages.ts b/frontend-service/src/main/vue/stores/messages.ts index 08d800b0a..91201981c 100644 --- a/frontend-service/src/main/vue/stores/messages.ts +++ b/frontend-service/src/main/vue/stores/messages.ts @@ -27,7 +27,7 @@ export const useMessageStore = defineStore("message", () => { > = computed(() => { if ( appStore.selectedChannel !== null && - appStore.selectedChannel.channelType !== "multimedia" + appStore.selectedChannel.type !== "MULTIMEDIA" ) return ContentArea.Channel; if (appStore.selectedDirect !== null) return ContentArea.Direct; @@ -94,7 +94,7 @@ export const useMessageStore = defineStore("message", () => { } else { const info = currentSectionInfo.value as { username: string }; response = await directController.sendDirectMessage({ - message: content, + content: content, username: info.username, }); } diff --git a/frontend-service/src/main/vue/stores/photo.ts b/frontend-service/src/main/vue/stores/photo.ts index b8acef235..8a7aaa379 100644 --- a/frontend-service/src/main/vue/stores/photo.ts +++ b/frontend-service/src/main/vue/stores/photo.ts @@ -8,33 +8,9 @@ export const usePhotoStore = defineStore("photo", () => { const userController: UserController = new UserControllerImpl(); const usersPhotos = ref>({}); - async function reloadUserPhoto(targetUsername: string) { - try { - const response = await userController.getUserPhoto({ - username: targetUsername, - }); - if (response.statusCode === 200) { - const typed = response as GetUserPhotoApi.Responses.Success; - if (typed.photo.data !== undefined) { - usersPhotos.value[targetUsername] = - "data:image/jpeg;base64," + - btoa( - new Uint8Array((typed.photo.data as any).data).reduce( - (data, byte) => data + String.fromCharCode(byte), - "" - ) - ); - } - } - } catch (e) { - console.log(e); - } - } + async function reloadUserPhoto(targetUsername: string) {} function getUserPhoto(targetUsername: string): Ref { - if (usersPhotos.value[targetUsername] === undefined) { - reloadUserPhoto(targetUsername); - } return computed(() => usersPhotos.value[targetUsername]); } diff --git a/frontend-service/src/main/vue/stores/server.ts b/frontend-service/src/main/vue/stores/server.ts index 0adabaa4e..73e67d5d8 100644 --- a/frontend-service/src/main/vue/stores/server.ts +++ b/frontend-service/src/main/vue/stores/server.ts @@ -86,7 +86,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as CreateServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -106,7 +106,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as CreateChannelApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -116,7 +116,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as JoinServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -126,7 +126,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as JoinServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -139,7 +139,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as KickUserFromServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -152,7 +152,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as KickUserFromServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -170,7 +170,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as UpdateServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } @@ -190,7 +190,7 @@ export const useServerStore = defineStore( await refresh(); } else { const typed = response as UpdateServerApi.Errors.Type; - throw new Error(String(typed.error)); + throw new Error(String(typed.message)); } } diff --git a/frontend-service/src/main/vue/stores/user.ts b/frontend-service/src/main/vue/stores/user.ts index b045e20c5..f3f49b848 100644 --- a/frontend-service/src/main/vue/stores/user.ts +++ b/frontend-service/src/main/vue/stores/user.ts @@ -23,8 +23,8 @@ export const useUserStore = defineStore( async function refresh() { if (refreshing) return; refreshing = true; - console.log("Refreshing user"); await whoami(); + console.log("Refreshing user"); refreshing = false; } @@ -40,10 +40,9 @@ export const useUserStore = defineStore( if (response.statusCode === 200) { isLoggedIn.value = true; jwt.value = (response as LoginApi.Responses.Success).access_token; - await whoami(); } else { const typed = response as LoginApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } @@ -59,7 +58,7 @@ export const useUserStore = defineStore( }); if (response.statusCode !== 200) { const typed = response as RegisterApi.Errors.Type; - throw new Error(typed.error); + throw new Error(typed.message); } } @@ -71,10 +70,15 @@ export const useUserStore = defineStore( // ==================== USER ==================== // async function whoami() { try { - const response = - (await userController.whoami()) as WhoamiApi.Responses.Success; - username.value = response.username; - email.value = response.email; + const response: WhoamiApi.Response = await userController.whoami(); + if (response.statusCode === 200) { + const typed = response as WhoamiApi.Responses.Success; + username.value = typed.username; + email.value = typed.email; + } else { + await logout(); + console.log("automatic logout"); + } } catch (e) { await logout(); console.log("automatic logout", e); diff --git a/kubernetes/frontend.yml b/kubernetes/frontend.yml index 428498ee5..f0d772c80 100644 --- a/kubernetes/frontend.yml +++ b/kubernetes/frontend.yml @@ -17,7 +17,7 @@ spec: spec: containers: - name: frontend-service - image: zuccherosintattico/piperkt-frontend-service + image: zuccherosintattico/piperkt-frontend-service:test imagePullPolicy: Always ports: - name: http diff --git a/kubernetes/helm-chart/piper-chart/templates/micronaut.yml b/kubernetes/helm-chart/piper-chart/templates/micronaut.yml index ae58bf6d1..b37b8f1b2 100644 --- a/kubernetes/helm-chart/piper-chart/templates/micronaut.yml +++ b/kubernetes/helm-chart/piper-chart/templates/micronaut.yml @@ -23,7 +23,7 @@ spec: serviceAccountName: micronaut-service # <1> containers: - name: {{.Values.serviceName}} - image: zuccherosintattico/piperkt-{{.Values.serviceName}} + image: zuccherosintattico/piperkt-{{.Values.serviceName}}:test imagePullPolicy: Always # <3> ports: - name: http diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/application/ChannelService.kt b/servers-service/src/main/kotlin/piperkt/services/servers/application/ChannelService.kt index 5c5bf46fb..cf75bffa9 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/application/ChannelService.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/application/ChannelService.kt @@ -136,8 +136,8 @@ open class ChannelService( return Result.success( ChannelQuery.GetMessagesFromChannelId.Response( channel.messages.subList( - request.from, - request.to.coerceAtMost(channel.messages.size) + request.from.coerceAtMost(channel.messages.size), + (request.from + request.limit).coerceAtMost(channel.messages.size) ) ) ) diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/application/api/query/ChannelQuery.kt b/servers-service/src/main/kotlin/piperkt/services/servers/application/api/query/ChannelQuery.kt index e22c0ef96..1cfdb38c6 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/application/api/query/ChannelQuery.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/application/api/query/ChannelQuery.kt @@ -12,7 +12,7 @@ sealed interface ChannelQuery { val serverId: ServerId, val channelId: ChannelId, val from: Int, - val to: Int, + val limit: Int, override val requestFrom: String, ) : GetMessagesFromChannelId, ServiceRequest diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/domain/Channel.kt b/servers-service/src/main/kotlin/piperkt/services/servers/domain/Channel.kt index 3a0b2f6ba..5d59d0195 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/domain/Channel.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/domain/Channel.kt @@ -7,25 +7,13 @@ enum class ChannelType { MULTIMEDIA } -open class Channel( +data class Channel( override val id: ChannelId = ChannelId(), var name: String, val type: ChannelType, var description: String, val messages: MutableList = mutableListOf(), ) : Entity(id) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is Channel) return false - - if (id != other.id) return false - - return true - } - - override fun hashCode(): Int { - return id.hashCode() - } fun addMessage(message: Message) { messages.add(message) diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImpl.kt b/servers-service/src/main/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImpl.kt index b44b653f7..fffa6cdb0 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImpl.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImpl.kt @@ -8,6 +8,7 @@ import piperkt.services.servers.application.ServerRepository import piperkt.services.servers.domain.Server import piperkt.services.servers.domain.ServerId import piperkt.services.servers.infrastructure.persistence.model.ChannelEntity +import piperkt.services.servers.infrastructure.persistence.model.MessageEntity import piperkt.services.servers.infrastructure.persistence.model.ServerEntity import piperkt.services.servers.infrastructure.persistence.model.ServerModelRepository @@ -44,7 +45,8 @@ class ServerRepositoryImpl(private val serverModelRepository: ServerModelReposit id = it.id.value, name = it.name, description = it.description, - channelType = it.type.toString() + channelType = it.type.toString(), + messages = it.messages.map(MessageEntity::fromDomain) ) } serverModelRepository.update( @@ -54,7 +56,7 @@ class ServerRepositoryImpl(private val serverModelRepository: ServerModelReposit description = entity.description, owner = entity.owner, users = entity.users, - channels = channelEntities + channels = channelEntities, ) ) } diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/ChannelHttpController.kt b/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/ChannelHttpController.kt index 00cdb4199..975eba8f6 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/ChannelHttpController.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/ChannelHttpController.kt @@ -30,7 +30,7 @@ class ChannelHttpController(private val channelService: ChannelService) : Channe ChannelCommand.CreateNewChannelInServer.Request( name = request.name, description = request.description, - type = request.type, + type = request.channelType, requestFrom = principal.name, serverId = ServerId(serverId) ) @@ -107,7 +107,7 @@ class ChannelHttpController(private val channelService: ChannelService) : Channe serverId: String, channelId: String, from: Int, - to: Int, + limit: Int, principal: Principal, ): ChannelApi.GetChannelMessagesApi.Response { val response = @@ -118,7 +118,7 @@ class ChannelHttpController(private val channelService: ChannelService) : Channe channelId = ChannelId(channelId), serverId = ServerId(serverId), from = from, - to = to + limit = limit ) ) .getOrThrow() @@ -139,7 +139,7 @@ class ChannelHttpController(private val channelService: ChannelService) : Channe .addMessageInChannel( ChannelCommand.AddMessageInChannel.Request( channelId = ChannelId(channelId), - content = request.message, + content = request.content, requestFrom = principal.name, serverId = ServerId(serverId) ) @@ -150,7 +150,7 @@ class ChannelHttpController(private val channelService: ChannelService) : Channe message = MessageDTO( id = response.messageId.value, - content = request.message, + content = request.content, sender = principal.name, ) ) diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/ChannelHttpControllerApi.kt b/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/ChannelHttpControllerApi.kt index 4b84bdfe1..69a93e573 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/ChannelHttpControllerApi.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/ChannelHttpControllerApi.kt @@ -76,7 +76,7 @@ interface ChannelHttpControllerApi { @PathVariable serverId: String, @PathVariable channelId: String, @QueryValue from: Int, - @QueryValue to: Int, + @QueryValue limit: Int, principal: Principal ): ChannelApi.GetChannelMessagesApi.Response diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/interactions/ChannelApi.kt b/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/interactions/ChannelApi.kt index f3503b0c9..5c31987ff 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/interactions/ChannelApi.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/interfaces/web/api/interactions/ChannelApi.kt @@ -9,7 +9,7 @@ sealed interface ChannelApi { sealed interface CreateChannelApi : ChannelApi { @Serdeable - data class Request(val name: String, val description: String, val type: String) : + data class Request(val name: String, val description: String, val channelType: String) : CreateChannelApi @Serdeable data class Response(val channelId: String) : CreateChannelApi @@ -40,7 +40,7 @@ sealed interface ChannelApi { sealed interface SendMessageToChannelApi : ChannelApi { - @Serdeable data class Request(val message: String) : SendMessageToChannelApi + @Serdeable data class Request(val content: String) : SendMessageToChannelApi @Serdeable data class Response(val channelId: String, val message: MessageDTO) : diff --git a/servers-service/src/test/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImplTest.kt b/servers-service/src/test/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImplTest.kt index 1c916eac1..7f3d643bf 100644 --- a/servers-service/src/test/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImplTest.kt +++ b/servers-service/src/test/kotlin/piperkt/services/servers/infrastructure/persistence/repository/ServerRepositoryImplTest.kt @@ -5,6 +5,7 @@ import io.kotest.matchers.shouldBe import piperkt.services.servers.application.ServerRepository import piperkt.services.servers.domain.ChannelType import piperkt.services.servers.domain.factory.ChannelFactory +import piperkt.services.servers.domain.factory.MessageFactory import piperkt.services.servers.domain.factory.ServerFactory class ServerRepositoryImplTest(private val serverRepository: ServerRepository) : IntegrationTest() { @@ -94,6 +95,7 @@ class ServerRepositoryImplTest(private val serverRepository: ServerRepository) : val server = ServerFactory.createServer("serverName", "serverDescription", "owner") val channel = ChannelFactory.createFromType("channelName", "channelDescription", "TEXT") server.addChannel(channel) + serverRepository.save(server) channel.name = "newChannelName" channel.description = "newChannelDescription" serverRepository.update(server) @@ -103,4 +105,22 @@ class ServerRepositoryImplTest(private val serverRepository: ServerRepository) : it.channels[0].description shouldBe "newChannelDescription" } } + + @Test + fun `should add a message to a channel`() { + val server = ServerFactory.createServer("serverName", "serverDescription", "owner") + val channel = ChannelFactory.createFromType("channelName", "channelDescription", "TEXT") + server.addChannel(channel) + serverRepository.save(server) + val message = MessageFactory.createMessage(sender = "sender", content = "content") + channel.addMessage(message) + serverRepository.update(server) + serverRepository.findById(server.id)?.let { + it.channels.size shouldBe 1 + it.channels[0].messages.size shouldBe 1 + it.channels[0].messages[0].id shouldBe message.id + it.channels[0].messages[0].sender shouldBe "sender" + it.channels[0].messages[0].content shouldBe "content" + } + } } diff --git a/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpClient.kt b/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpClient.kt index cc380fcca..b4908d722 100644 --- a/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpClient.kt +++ b/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpClient.kt @@ -57,7 +57,7 @@ interface ChannelHttpClient { @PathVariable serverId: String, @PathVariable channelId: String, @QueryValue from: Int, - @QueryValue to: Int, + @QueryValue limit: Int, @Header(HttpHeaders.AUTHORIZATION) authorization: String = authOf("user") ): HttpResponse diff --git a/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpControllerTest.kt b/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpControllerTest.kt index bdd82477f..d20b03500 100644 --- a/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpControllerTest.kt +++ b/servers-service/src/test/kotlin/piperkt/services/servers/interfaces/web/channel/ChannelHttpControllerTest.kt @@ -33,7 +33,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra ChannelApi.CreateChannelApi.Request( name = "name", description = "description", - type = "TEXT" + channelType = "TEXT" ) ) .body() @@ -49,7 +49,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra ChannelApi.CreateChannelApi.Request( name = "name", description = "description", - type = "TEXT" + channelType = "TEXT" ) ) response.status() shouldBe HttpStatus.OK @@ -169,7 +169,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra serverId = basicServerId, channelId = it, from = 0, - to = 10 + limit = 10 ) } response.status() shouldBe HttpStatus.OK @@ -182,7 +182,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra serverId = basicServerId, channelId = "channelId", from = 0, - to = 10 + limit = 10 ) response.status() shouldBe HttpStatus.NOT_FOUND } @@ -195,7 +195,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra serverId = basicServerId, channelId = channelId, from = 0, - to = 10, + limit = 10, authorization = authOf("anotherUser") ) } @@ -210,7 +210,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra client.sendMessageToChannel( serverId = basicServerId, channelId = channelId, - request = ChannelApi.SendMessageToChannelApi.Request(message = "message") + request = ChannelApi.SendMessageToChannelApi.Request(content = "message") ) } response.status() shouldBe HttpStatus.OK @@ -222,7 +222,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra client.sendMessageToChannel( serverId = basicServerId, channelId = "channelId", - request = ChannelApi.SendMessageToChannelApi.Request(message = "message") + request = ChannelApi.SendMessageToChannelApi.Request(content = "message") ) response.status() shouldBe HttpStatus.NOT_FOUND } @@ -234,7 +234,7 @@ class ChannelHttpControllerTest(private var client: ChannelHttpClient) : Integra client.sendMessageToChannel( serverId = basicServerId, channelId = channelId, - request = ChannelApi.SendMessageToChannelApi.Request(message = "message"), + request = ChannelApi.SendMessageToChannelApi.Request(content = "message"), authorization = authOf("anotherUser") ) }