Skip to content

Commit 6368265

Browse files
committed
👽 mis en place des api des reponses
1 parent be5a741 commit 6368265

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

resources/js/api/comments.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { jsonFetch } from '@helpers/api.js'
2+
3+
/**
4+
* Représentation d'un commentaire de l'API
5+
* @typedef {{id: number, username: string, avatar: string, content: string, createdAt: number, replies: ReplyResource[]}} ReplyResource
6+
*/
7+
8+
/**
9+
* @param {number} target
10+
* @return {Promise<ReplyResource[]>}
11+
*/
12+
export async function findAllReplies (target) {
13+
return await jsonFetch(`/api/replies/${target}`)
14+
}
15+
16+
/**
17+
* @param {{target: number, username: ?string, email: ?string, content: string}} data
18+
* @return {Promise<Object>}
19+
*/
20+
export async function addReply (body) {
21+
return jsonFetch('/api/replies', {
22+
method: 'POST',
23+
body
24+
})
25+
}
26+
27+
/**
28+
* @param {int} id
29+
* @param {int} userId
30+
* @return {Promise<Object>}
31+
*/
32+
export async function likeReply(id, userId) {
33+
return jsonFetch(`/api/like/${id}`, {
34+
method: 'POST',
35+
body: JSON.stringify({ userId })
36+
})
37+
}
38+
39+
/**
40+
* @param {int} id
41+
* @return {Promise<null>}
42+
*/
43+
export async function deleteReply (id) {
44+
return jsonFetch(`/api/replies/${id}`, {
45+
method: 'DELETE'
46+
})
47+
}
48+
49+
/**
50+
* @param {int} id
51+
* @param {string} body
52+
* @return {Promise<ReplyResource>}
53+
*/
54+
export async function updateReply (id, body) {
55+
return jsonFetch(`/api/replies/${id}`, {
56+
method: 'PUT',
57+
body: JSON.stringify({ body })
58+
})
59+
}

0 commit comments

Comments
 (0)