Skip to content

Commit

Permalink
feat: base for chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Smotrych committed Jun 3, 2024
1 parent 1067c55 commit 1f3c0e4
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 710 deletions.
75 changes: 49 additions & 26 deletions src/app/core/services/rest-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import {
PaginationParams,
DownloadFileResponse,
FileInfo,
ChatRepresentation,
ChatCreateRequest,
ChatSearchResponse,
ChatUpdateRequest,
ChatAddMemberRequest,
ChatLeaveResponse,
ChatParticipantsResponse,
MessageRepresentation,
MessageCreateRequest,
MessageSeenByResponse,
} from 'src/app/interfaces/api-interfaces';

const httpOptions = {
Expand Down Expand Up @@ -161,61 +171,74 @@ downloadFile(fileId: string): Observable<{blob: Blob, filename: string}> {
return this.http.get<FileInfo>(`${GlobalComponent.API_URL}common/file/${fileId}/info`);
}

// Create a new chat
createChat(chatData: any): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/chat`, chatData);
}
createChat(chatData: ChatCreateRequest): Observable<ChatRepresentation> {
return this.http.post<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat`, chatData);
}

// Get all chats
getChats(): Observable<any[]> {
return this.http.get<any[]>(`${GlobalComponent.API_URL}communication/chat`);
getChats(page: number = 1, pageSize: number = 10, name?: string): Observable<ChatRepresentation[]> {
let queryParams = `?page=${page}&page_size=${pageSize}`;
if (name) {
queryParams += `&name=${encodeURIComponent(name)}`;
}
return this.http.get<ChatSearchResponse>(`${GlobalComponent.API_URL}communication/chat${queryParams}`).pipe(
map(response => response.content)
);
}

// Get specific chat by ID
getChat(chatId: string): Observable<any> {
return this.http.get(`${GlobalComponent.API_URL}communication/chat/${chatId}`);
getChat(chatId: string): Observable<ChatRepresentation> {
return this.http.get<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat/${chatId}`);
}

// Update specific chat
updateChat(chatId: string, updateData: any): Observable<any> {
return this.http.patch(`${GlobalComponent.API_URL}communication/chat/${chatId}`, updateData);
updateChat(chatId: string, updateData: ChatUpdateRequest): Observable<ChatRepresentation> {
return this.http.patch<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat/${chatId}`, updateData);
}

// Add member to chat
addChatMember(chatId: string, userId: string): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/chat/${chatId}/add_member`, { userId });
addChatMember(chatId: string, accountIds: string[]): Observable<ChatRepresentation> {
const requestData: ChatAddMemberRequest = { account_ids: accountIds };
return this.http.post<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat/${chatId}/add_member`, requestData);
}

// Leave a chat
leaveChat(chatId: string): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/chat/${chatId}/leave`, {});
leaveChat(chatId: string): Observable<ChatLeaveResponse> {
return this.http.post<ChatLeaveResponse>(`${GlobalComponent.API_URL}communication/chat/${chatId}/leave`, {});
}

// Get chat participants
getChatParticipants(chatId: string): Observable<any[]> {
return this.http.get<any[]>(`${GlobalComponent.API_URL}communication/chat/${chatId}/participants`);
}
getChatParticipants(chatId: string, page: number = 1, pageSize: number = 10, name?: string): Observable<ChatParticipantsResponse> {
let params = new HttpParams()
.set('page', page.toString())
.set('page_size', pageSize.toString());

if (name) {
params = params.set('name', name);
}

return this.http.get<ChatParticipantsResponse>(`${GlobalComponent.API_URL}communication/chat/${chatId}/participants`, { params });
}

// Messaging services
createMessage(messageData: any): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/message`, messageData);
createMessage(messageData: MessageCreateRequest): Observable<MessageRepresentation> {
return this.http.post<MessageRepresentation>(`${GlobalComponent.API_URL}communication/message`, messageData);
}

getMessage(messageId: string): Observable<any> {
return this.http.get(`${GlobalComponent.API_URL}communication/message/${messageId}`);
getMessage(messageId: string): Observable<MessageRepresentation> {
return this.http.get<MessageRepresentation>(`${GlobalComponent.API_URL}communication/message/${messageId}`);
}

updateMessage(messageId: string, messageData: any): Observable<any> {
return this.http.put(`${GlobalComponent.API_URL}communication/message/${messageId}`, messageData);
}

markMessageSeen(messageId: string): Observable<any> {
return this.http.patch(`${GlobalComponent.API_URL}communication/message/${messageId}/seen`, {});
markMessageSeen(messageId: string): Observable<void> {
return this.http.patch<void>(`${GlobalComponent.API_URL}communication/message/${messageId}/seen`, {});
}

// Get who has seen the message
getMessageSeenBy(messageId: string): Observable<any[]> {
return this.http.get<any[]>(`${GlobalComponent.API_URL}communication/message/${messageId}/seen_by`);
getMessageSeenBy(messageId: string): Observable<MessageSeenByResponse> {
return this.http.get<MessageSeenByResponse>(`${GlobalComponent.API_URL}communication/message/${messageId}/seen_by`);
}

// Delete
Expand Down
75 changes: 75 additions & 0 deletions src/app/interfaces/api-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,78 @@ export interface Chat {
name: string;
_links: any;
}


export interface ChatCreateRequest {
name: string | null;
participants: string[] | null;
}

export interface ChatRepresentation {
chat_id: string;
name: string;
_links: any;
}

export interface ChatSearchResponse {
meta: {
total: number;
page: number;
page_size: number;
total_pages: number;
};
content: ChatRepresentation[];
}

export interface ChatUpdateRequest {
name: string | null;
}

export interface ChatAddMemberRequest {
account_ids: string[];
}

export interface ChatLeaveResponse {
message: string;
}

export interface ChatParticipantsResponse {
meta: {
total: number;
page: number;
page_size: number;
total_pages: number;
};
content: ChatParticipant[];
}

export interface ChatParticipant {
account_id: string;
name: string;
}

export interface MessageCreateRequest {
chat_id: string;
text: string | null;
file_id: string | null;
}

export interface MessageRepresentation {
chat_id: string;
message_id: string;
sender_id: string;
text: string | null;
file_id: string | null;
created_at: string;
updated_at: string;
_links: any;
}

export interface MessageSeenByResponse {
seen_by: SeenBy[];
}

export interface SeenBy {
user_id: string;
seen_at: string;
}
24 changes: 11 additions & 13 deletions src/app/layouts/sidebar/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ import { MenuItem } from "./menu.model";

export const MENU: MenuItem[] = [
{
id: 1,
label: 'MENUITEMS.MENU.TEXT',
id: 0,
label: 'ПАНЕЛЬ ЗАВІДУВАЧА КАФЕДРОЮ',
isTitle: true
},
{
id: 2,
label: 'MENUITEMS.MENU.StudentTasks',
icon: 'ph-list-checks',
link: '/tickets/list',
parentId: 8
id: 1,
label: 'МЕНЮ',
isTitle: true
},
{
id: 3,
label: 'MENUITEMS.DASHBOARD.LIST.LEARNING',
link: '/learning',
icon: 'ph-gauge',
parentId: 2
id: 2,
label: 'Список Інструкторів',
icon: 'bx bx-list-ul',
link: '/learning/list-of-instructors',
parentId: 34
},
{
id: 4,
label: 'MENUITEMS.APPS.LIST.CHAT',
label: 'Чат',
icon: 'ph-chats',
link: '/apps/chat',
parentId: 8
Expand Down
Loading

0 comments on commit 1f3c0e4

Please sign in to comment.