1
1
import { AuthError } from '@/lib/error' ;
2
2
import {
3
+ Board ,
3
4
CommentList ,
4
5
PostBoardType ,
5
6
PostCommentType ,
6
7
PostImageType ,
7
8
} from '@/types/types' ;
8
9
9
10
export async function postBoard ( postBoardData : PostBoardType ) {
10
- const url = `endpoint/api/board/register` ;
11
+ const url = `/ endpoint/api/board/register` ;
11
12
12
13
const response = await fetch ( url , {
13
14
method : 'POST' ,
@@ -24,7 +25,7 @@ export async function postImageBoard(
24
25
boardId : number ,
25
26
postImageData : PostImageType ,
26
27
) {
27
- const url = `endpoint/api/file/upload?boardId=${ boardId } ` ;
28
+ const url = `/ endpoint/api/file/upload?boardId=${ boardId } ` ;
28
29
const response = await fetch ( url , {
29
30
method : 'POST' ,
30
31
credentials : 'include' ,
@@ -56,6 +57,26 @@ export async function getBoardList(pageParam: number) {
56
57
}
57
58
}
58
59
60
+ export async function getBoard ( boardId : number ) : Promise < Board > {
61
+ const url = `/endpoint/api/board/${ boardId } ` ;
62
+ try {
63
+ const response = await fetch ( url ) ;
64
+ if ( response . status === 401 ) {
65
+ throw new AuthError ( '로그인이 필요한 서비스입니다.' ) ;
66
+ }
67
+ if ( ! response . ok ) {
68
+ throw new Error ( `서버오류:${ response . status } ` ) ;
69
+ }
70
+ return await response . json ( ) ;
71
+ } catch ( error ) {
72
+ if ( error instanceof AuthError ) {
73
+ window . location . replace ( '/auth/login' ) ;
74
+ alert ( error . message ) ;
75
+ }
76
+ throw error ;
77
+ }
78
+ }
79
+
59
80
export async function deleteBoard ( boardId : number ) {
60
81
const url = `/endpoint/api/board/remove/${ boardId } ` ;
61
82
try {
@@ -83,7 +104,7 @@ export async function deleteBoard(boardId: number) {
83
104
}
84
105
85
106
export async function postComment ( postCommentData : PostCommentType ) {
86
- const url = `endpoint/api/reply/register` ;
107
+ const url = `/ endpoint/api/reply/register` ;
87
108
const response = await fetch ( url , {
88
109
method : 'POST' ,
89
110
credentials : 'include' ,
@@ -148,7 +169,7 @@ export async function deleteComment(boardId: number, replyId: number) {
148
169
}
149
170
150
171
export async function addBookmarkBoard ( boardId : number ) {
151
- const url = `endpoint/api/bookmark/add?boardId=${ boardId } ` ;
172
+ const url = `/ endpoint/api/bookmark/add?boardId=${ boardId } ` ;
152
173
try {
153
174
const response = await fetch ( url , {
154
175
method : 'POST' ,
@@ -174,7 +195,7 @@ export async function addBookmarkBoard(boardId: number) {
174
195
}
175
196
176
197
export async function deleteBookmarkBoard ( boardId : number ) {
177
- const url = `endpoint/api/bookmark/delete?boardId=${ boardId } ` ;
198
+ const url = `/ endpoint/api/bookmark/delete?boardId=${ boardId } ` ;
178
199
try {
179
200
const response = await fetch ( url , {
180
201
method : 'DELETE' ,
@@ -200,7 +221,7 @@ export async function deleteBookmarkBoard(boardId: number) {
200
221
}
201
222
202
223
export async function updateBoardLike ( boardId : number ) {
203
- const url = `endpoint/api/boardLike/like?boardId=${ boardId } ` ;
224
+ const url = `/ endpoint/api/boardLike/like?boardId=${ boardId } ` ;
204
225
try {
205
226
const response = await fetch ( url , {
206
227
method : 'POST' ,
@@ -226,7 +247,7 @@ export async function updateBoardLike(boardId: number) {
226
247
}
227
248
228
249
export async function deleteBoardLike ( boardId : number ) {
229
- const url = `endpoint/api/boardLike/deleteLike?boardId=${ boardId } ` ;
250
+ const url = `/ endpoint/api/boardLike/deleteLike?boardId=${ boardId } ` ;
230
251
try {
231
252
const response = await fetch ( url , {
232
253
method : 'DELETE' ,
0 commit comments