| [700e2f9] | 1 | import { apiClient } from "@/api/client";
|
|---|
| 2 |
|
|---|
| 3 | export interface Comment {
|
|---|
| 4 | idComment: number;
|
|---|
| 5 | content: string;
|
|---|
| 6 | dateOfComment: string;
|
|---|
| 7 | patientId: number;
|
|---|
| 8 | patientUsername: string;
|
|---|
| 9 | patientName: string;
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | export interface BlogPost {
|
|---|
| 13 | idBlog: number;
|
|---|
| 14 | title: string;
|
|---|
| 15 | content: string;
|
|---|
| 16 | dateOfPost: string;
|
|---|
| 17 | patientId: number;
|
|---|
| 18 | patientUsername: string;
|
|---|
| 19 | patientName: string;
|
|---|
| 20 | likesCount: number;
|
|---|
| 21 | commentsCount: number;
|
|---|
| 22 | likedByCurrentUser: boolean;
|
|---|
| 23 | comments: Comment[];
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | export interface CreateBlogRequest {
|
|---|
| 27 | title: string;
|
|---|
| 28 | content: string;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | export interface UpdateBlogRequest {
|
|---|
| 32 | title: string;
|
|---|
| 33 | content: string;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | export const blogApi = {
|
|---|
| 37 | getAllBlogs: async (): Promise<BlogPost[]> =>
|
|---|
| 38 | apiClient.get<BlogPost[]>("/blogs"),
|
|---|
| 39 |
|
|---|
| 40 | getBlog: async (id: number): Promise<BlogPost> =>
|
|---|
| 41 | apiClient.get<BlogPost>(`/blogs/${id}`),
|
|---|
| 42 |
|
|---|
| 43 | createBlog: async (data: CreateBlogRequest): Promise<BlogPost> =>
|
|---|
| 44 | apiClient.post<BlogPost>("/blogs", data),
|
|---|
| 45 |
|
|---|
| 46 | updateBlog: async (id: number, data: UpdateBlogRequest): Promise<BlogPost> =>
|
|---|
| 47 | apiClient.put<BlogPost>(`/blogs/${id}`, data),
|
|---|
| 48 |
|
|---|
| 49 | deleteBlog: async (id: number): Promise<void> =>
|
|---|
| 50 | apiClient.delete<void>(`/blogs/${id}`),
|
|---|
| 51 |
|
|---|
| 52 | toggleLike: async (id: number): Promise<void> =>
|
|---|
| 53 | apiClient.post<void>(`/blogs/${id}/like`),
|
|---|
| 54 |
|
|---|
| 55 | addComment: async (blogId: number, content: string): Promise<Comment> =>
|
|---|
| 56 | apiClient.post<Comment>(`/blogs/${blogId}/comments`, { content }),
|
|---|
| 57 |
|
|---|
| 58 | updateComment: async (commentId: number, content: string): Promise<Comment> =>
|
|---|
| 59 | apiClient.put<Comment>(`/blogs/comments/${commentId}`, { content }),
|
|---|
| 60 |
|
|---|
| 61 | deleteComment: async (commentId: number): Promise<void> =>
|
|---|
| 62 | apiClient.delete<void>(`/blogs/comments/${commentId}`),
|
|---|
| 63 | };
|
|---|