Files
memegoat/frontend/src/services/comment.service.ts
Mathis HERRIOT 0976850c0c feat: add comment replies and liking functionality
- Introduced support for nested comment replies in both frontend and backend.
- Added comment liking and unliking features, including like count and "isLiked" state tracking.
- Updated database schema with `parentId` and new `comment_likes` table.
- Enhanced UI for threaded comments and implemented display of like counts and reply actions.
- Refactored APIs and repositories to support replies, likes, and enriched comment data.
2026-01-29 15:26:54 +01:00

49 lines
1013 B
TypeScript

import api from "@/lib/api";
export interface Comment {
id: string;
text: string;
parentId?: string;
likesCount: number;
isLiked: boolean;
createdAt: string;
updatedAt: string;
user: {
uuid: string;
username: string;
displayName?: string;
avatarUrl?: string;
};
}
export const CommentService = {
async getByContentId(contentId: string): Promise<Comment[]> {
const { data } = await api.get<Comment[]>(`/contents/${contentId}/comments`);
return data;
},
async create(
contentId: string,
text: string,
parentId?: string,
): Promise<Comment> {
const { data } = await api.post<Comment>(`/contents/${contentId}/comments`, {
text,
parentId,
});
return data;
},
async remove(commentId: string): Promise<void> {
await api.delete(`/comments/${commentId}`);
},
async like(commentId: string): Promise<void> {
await api.post(`/comments/${commentId}/like`);
},
async unlike(commentId: string): Promise<void> {
await api.delete(`/comments/${commentId}/like`);
},
};