Feat: 알림 관련 api 추가
This commit is contained in:
parent
d436397d82
commit
7f643a8ecb
22
frontend/src/api/alarmApi.ts
Normal file
22
frontend/src/api/alarmApi.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import api from '@/api/axiosConfig';
|
||||
import { AlarmResponse } from '@/types';
|
||||
|
||||
export async function getAlarmList() {
|
||||
return api.get<AlarmResponse[]>('/alarm').then(({ data }) => data);
|
||||
}
|
||||
|
||||
export async function createTestAlarm() {
|
||||
return api.post('/alarm/test').then(({ data }) => data);
|
||||
}
|
||||
|
||||
export async function readAlarm(alarmId: number) {
|
||||
return api.put(`/alarm/${alarmId}`).then(({ data }) => data);
|
||||
}
|
||||
|
||||
export async function deleteAlarm(alarmId: number) {
|
||||
return api.delete(`/alarm/${alarmId}`).then(({ data }) => data);
|
||||
}
|
||||
|
||||
export async function deleteAllAlarm() {
|
||||
return api.delete('/alarm').then(({ data }) => data);
|
||||
}
|
13
frontend/src/queries/alarms/useCreateTestAlarmQuery.ts
Normal file
13
frontend/src/queries/alarms/useCreateTestAlarmQuery.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { createTestAlarm } from '@/api/alarmApi';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
export default function useCreateTestAlarmQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: createTestAlarm,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alarmList'] });
|
||||
},
|
||||
});
|
||||
}
|
13
frontend/src/queries/alarms/useDeleteAlarmQuery.ts
Normal file
13
frontend/src/queries/alarms/useDeleteAlarmQuery.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { deleteAlarm } from '@/api/alarmApi';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
export default function useDeleteAlarmQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (alarmId: number) => deleteAlarm(alarmId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alarmList'] });
|
||||
},
|
||||
});
|
||||
}
|
13
frontend/src/queries/alarms/useDeleteAllAlarmQuery.ts
Normal file
13
frontend/src/queries/alarms/useDeleteAllAlarmQuery.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { deleteAllAlarm } from '@/api/alarmApi';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
export default function useDeleteAllAlarmQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: deleteAllAlarm,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alarmList'] });
|
||||
},
|
||||
});
|
||||
}
|
9
frontend/src/queries/alarms/useGetAlarmListQuery.ts
Normal file
9
frontend/src/queries/alarms/useGetAlarmListQuery.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { getAlarmList } from '@/api/alarmApi';
|
||||
import { useSuspenseQuery } from '@tanstack/react-query';
|
||||
|
||||
export default function useGetAlarmListQuery() {
|
||||
return useSuspenseQuery({
|
||||
queryKey: ['alarmList'],
|
||||
queryFn: getAlarmList,
|
||||
});
|
||||
}
|
13
frontend/src/queries/alarms/useReadAlarmQuery.ts
Normal file
13
frontend/src/queries/alarms/useReadAlarmQuery.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { readAlarm } from '@/api/alarmApi';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
export default function useReadAlarmQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (alarmId: number) => readAlarm(alarmId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alarmList'] });
|
||||
},
|
||||
});
|
||||
}
|
@ -346,3 +346,10 @@ export interface ReportResponse {
|
||||
epochTime: number;
|
||||
leftSecond: number;
|
||||
}
|
||||
|
||||
export interface AlarmResponse {
|
||||
id: number;
|
||||
isRead: boolean;
|
||||
createdAt: string;
|
||||
type: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user