Feat: 알림 관련 api 추가

This commit is contained in:
홍창기 2024-09-27 18:27:34 +09:00
parent d436397d82
commit 7f643a8ecb
7 changed files with 90 additions and 0 deletions

View 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);
}

View 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'] });
},
});
}

View 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'] });
},
});
}

View 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'] });
},
});
}

View 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,
});
}

View 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'] });
},
});
}

View File

@ -346,3 +346,10 @@ export interface ReportResponse {
epochTime: number;
leftSecond: number;
}
export interface AlarmResponse {
id: number;
isRead: boolean;
createdAt: string;
type: string;
}