source: frontend/src/api/blog.ts@ 700e2f9

main
Last change on this file since 700e2f9 was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago

Init

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import { apiClient } from "@/api/client";
2
3export interface Comment {
4 idComment: number;
5 content: string;
6 dateOfComment: string;
7 patientId: number;
8 patientUsername: string;
9 patientName: string;
10}
11
12export 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
26export interface CreateBlogRequest {
27 title: string;
28 content: string;
29}
30
31export interface UpdateBlogRequest {
32 title: string;
33 content: string;
34}
35
36export 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};
Note: See TracBrowser for help on using the repository browser.