11import { sendRequest } from "../request" ;
2- import { lambdaInstance , adminInstance } from "../instance" ;
2+ import { lambdaInstance } from "../instance" ;
33import type { LostItemType } from "@/pages/notice/types/lostItems" ;
4- import { useLostStore } from "@/stores/useLostStore" ;
54import type { LostDetailType } from "@/pages/lost-detail/types/lostDetails" ;
65
76interface LostListResponse {
@@ -10,79 +9,9 @@ interface LostListResponse {
109}
1110
1211export const LostListAPI = async ( ) => {
13- const response = await sendRequest < LostListResponse > (
14- lambdaInstance ,
15- "GET" ,
16- "/losts"
17- ) ;
18-
19- if ( response . success ) {
20- useLostStore . getState ( ) . setLostList ( response . data . item_lists ) ;
21- return response . data ;
22- } else {
23- return response . error ;
24- }
12+ return sendRequest < LostListResponse > ( lambdaInstance , "GET" , "/losts" ) ;
2513} ;
2614
2715export const LostDetailAPI = async ( lostId : number ) => {
28- const response = await sendRequest < LostDetailType > (
29- lambdaInstance ,
30- "GET" ,
31- `/losts/${ lostId } `
32- ) ;
33-
34- if ( response . success ) {
35- useLostStore . getState ( ) . setLostDetail ( response . data ) ;
36- return response . data ;
37- } else {
38- return response . error ;
39- }
40- } ;
41-
42- export const LostPostAPI = async ( formData : FormData ) => {
43- const response = await sendRequest < string > (
44- adminInstance ,
45- "POST" ,
46- `/festa/losts` ,
47- formData
48- ) ;
49-
50- if ( response . success ) {
51- await LostListAPI ( ) ;
52- return { success : true } ;
53- } else {
54- return { success : false } ;
55- }
56- } ;
57-
58- export const LostPatchAPI = async ( formData : FormData ) => {
59- const response = await sendRequest < string > (
60- adminInstance ,
61- "PATCH" ,
62- `/festa/losts` ,
63- formData ,
64- { "Content-Type" : "multipart/form-data" }
65- ) ;
66-
67- if ( response . success ) {
68- await LostListAPI ( ) ;
69- return { success : true } ;
70- } else {
71- return { success : false } ;
72- }
73- } ;
74-
75- export const LostDeleteAPI = async ( lostId : number ) => {
76- const response = await sendRequest < string > (
77- adminInstance ,
78- "DELETE" ,
79- `/festa/losts/${ lostId } `
80- ) ;
81-
82- if ( response . data ) {
83- const newList = await LostListAPI ( ) ;
84- return { success : true , newList } ;
85- } else {
86- return { success : false } ;
87- }
16+ return sendRequest < LostDetailType > ( lambdaInstance , "GET" , `/losts/${ lostId } ` ) ;
8817} ;
0 commit comments