Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app/app-download/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export default function AppDownloadPage() {
rel="noopener noreferrer"
className="flex-1 flex items-center justify-center gap-4 rounded-xl bg-[#1D1D1F] hover:bg-black text-white py-3.5 px-4 transition-all duration-200 shadow-sm hover:shadow-md hover:-translate-y-0.5"
>
<svg viewBox="0 0 384 512" className="w-5 h-5 fill-current" role="img" aria-label="Apple Logo">
<svg
viewBox="0 0 384 512"
className="w-5 h-5 fill-current"
role="img"
aria-label="Apple Logo"
>
<path d="M318.7 268.7c-.2-36.7 16.4-64.4 50-84.8-18.8-26.9-47.2-41.7-84.7-44.6-35.5-2.8-74.3 20.7-88.5 20.7-15 0-49.4-19.7-76.4-19.7C63.3 141.2 4 184.8 4 273.5q0 39.3 14.4 81.2c12.8 36.7 59 126.7 107.2 125.2 25.2-.6 43-17.9 75.8-17.9 31.8 0 48.3 17.9 76.4 17.9 48.6-.7 90.4-82.5 102.6-119.3-65.2-30.7-61.7-90-61.7-91.9zm-56.6-164.2c27.3-32.4 24.8-61.9 24-72.5-24.1 1.4-52 16.4-67.9 34.9-17.5 19.8-27.8 44.3-25.6 71.9 26.1 2 49.9-11.4 69.5-34.3z" />
</svg>
<div className="flex flex-col items-start text-left">
Expand Down
16 changes: 10 additions & 6 deletions src/entities/dashboard/api/getDashboardSummary.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { dashboardUrl, get } from "@/shared/api";
import { dashboardUrl, get, normalizeApiError } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import type { DashboardSummaryDTO } from "../model/types";
import { dashboardSummarySchema } from "./schemas";

export async function getDashboardSummary(): Promise<DashboardSummaryDTO> {
const response = await get<BaseResponseType<unknown>>(
dashboardUrl.getSummary(),
);
try {
const response = await get<BaseResponseType<unknown>>(
dashboardUrl.getSummary(),
);

return dashboardSummarySchema.parse(response.data);
}
return dashboardSummarySchema.parse(response.data);
} catch (error) {
throw normalizeApiError(error);
}
}
2 changes: 1 addition & 1 deletion src/entities/dashboard/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { getDashboardSummary } from "./getDashboardSummary";
export { useGetDashboardSummary } from "./useGetDashboardSummary";
export { useGetDashboardSummary } from "./useGetDashboardSummary";
2 changes: 1 addition & 1 deletion src/entities/dashboard/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const dashboardSummarySchema = z.object({
totalMachines: z.number(),
malfunctionMachines: z.number(),
suspendedStudents: z.number(),
});
});
2 changes: 1 addition & 1 deletion src/entities/dashboard/api/useGetDashboardSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const useGetDashboardSummary = ({
queryFn: getDashboardSummary,
enabled,
});
};
};
2 changes: 1 addition & 1 deletion src/entities/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { mapDashboard } from "./lib/mapDashboard";
export type {
DashboardItem,
DashboardSummaryDTO,
} from "./model/types";
} from "./model/types";
2 changes: 1 addition & 1 deletion src/entities/dashboard/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export type DashboardSummaryDTO = z.infer<typeof dashboardSummarySchema>;
export interface DashboardItem {
label: string;
value: string;
}
}
9 changes: 9 additions & 0 deletions src/entities/machine/api/deleteMachine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { del, machineUrl, normalizeApiError } from "@/shared/api";

export async function deleteMachine(id: number): Promise<void> {
try {
await del(machineUrl.deleteMachine(id));
} catch (error) {
throw normalizeApiError(error);
}
}
18 changes: 11 additions & 7 deletions src/entities/machine/api/getMachines.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, machineUrl } from "@/shared/api";
import { get, machineUrl, normalizeApiError } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import { mapMachines } from "../lib/mapMachine";
import type {
Expand Down Expand Up @@ -30,10 +30,14 @@ async function getMachinesByType(
export async function getMachines(
params?: MachineParamsType,
): Promise<MachineItem[]> {
const [washers, dryers] = await Promise.all([
getMachinesByType("WASHER", params),
getMachinesByType("DRYER", params),
]);
try {
const [washers, dryers] = await Promise.all([
getMachinesByType("WASHER", params),
getMachinesByType("DRYER", params),
]);

return [...washers, ...dryers];
}
return [...washers, ...dryers];
} catch (error) {
throw normalizeApiError(error);
}
}
7 changes: 2 additions & 5 deletions src/entities/machine/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { z } from "zod";
export const machineTypeSchema = z.enum(["WASHER", "DRYER"]);

// 기기 고장 상태
export const machineConditionStatusSchema = z.enum([
"NORMAL",
"MALFUNCTION",
]);
export const machineConditionStatusSchema = z.enum(["NORMAL", "MALFUNCTION"]);

// 기기 사용 가능 상태
export const machineAvailabilityStatusSchema = z.enum([
Expand Down Expand Up @@ -39,4 +36,4 @@ export const machineResponseSchema = z.object({
totalCount: z.number(),
totalPages: z.number(),
currentPage: z.number(),
});
});
20 changes: 20 additions & 0 deletions src/entities/machine/api/updateMachineStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { machineUrl, normalizeApiError, put } from "@/shared/api";
import type { MachineConditionStatusDTO } from "../model/types";

type UpdateMachineStatusParams = {
id: number;
status: MachineConditionStatusDTO;
};

export async function updateMachineStatus({
id,
status,
}: UpdateMachineStatusParams): Promise<void> {
try {
await put(machineUrl.updateMachineStatus(id), {
status,
});
} catch (error) {
throw normalizeApiError(error);
}
}
5 changes: 3 additions & 2 deletions src/entities/machine/api/useDeleteMachine.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { del, machineQueryKeys, machineUrl } from "@/shared/api";
import { machineQueryKeys } from "@/shared/api";
import { deleteMachine } from "./deleteMachine";

export const useDeleteMachine = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: (id: number) => del(machineUrl.deleteMachine(id)),
mutationFn: deleteMachine,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: machineQueryKeys.all,
Expand Down
2 changes: 1 addition & 1 deletion src/entities/machine/api/useGetMachines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export const useGetMachines = (
queryFn: () => fetchMachines(params),
enabled: options?.enabled,
});
};
};
12 changes: 3 additions & 9 deletions src/entities/machine/api/useUpdateMachineStatus.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { machineQueryKeys, machineUrl, put } from "@/shared/api";
import type { MachineConditionStatusDTO } from "../model/types";
import { machineQueryKeys } from "@/shared/api";
import { updateMachineStatus } from "./updateMachineStatus";

export const useUpdateMachineStatus = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: ({
id,
status,
}: {
id: number;
status: MachineConditionStatusDTO;
}) => put(machineUrl.updateMachineStatus(id), { status }),
mutationFn: updateMachineStatus,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: machineQueryKeys.all,
Expand Down
2 changes: 1 addition & 1 deletion src/entities/machine/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ export type MachineResponseType = z.infer<typeof machineResponseSchema>;
// 조회 파라미터
export interface MachineParamsType {
floor?: number;
}
}
35 changes: 18 additions & 17 deletions src/entities/report/api/getMalfunctionReports.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { get, reportUrl } from "@/shared/api";
import { get, normalizeApiError, reportUrl } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import type {
ReportParamsType,
ReportResponseType,
} from "../model/types";
import type { ReportParamsType, ReportResponseType } from "../model/types";
import { reportResponseSchema } from "./schemas";

export const getMalfunctionReports = async (
params?: ReportParamsType,
): Promise<BaseResponseType<ReportResponseType>> => {
const response = await get<BaseResponseType<unknown>>(
reportUrl.getMalfunctionReports(),
{
params,
},
);
try {
const response = await get<BaseResponseType<unknown>>(
reportUrl.getMalfunctionReports(),
{
params,
},
);

const parsedData = reportResponseSchema.parse(response.data);
const parsedData = reportResponseSchema.parse(response.data);

return {
...response,
data: parsedData,
};
};
return {
...response,
data: parsedData,
};
} catch (error) {
throw normalizeApiError(error);
}
};
2 changes: 1 addition & 1 deletion src/entities/report/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export const reportResponseSchema = z.object({
totalCount: z.number(),
totalPages: z.number(),
currentPage: z.number(),
});
});
24 changes: 24 additions & 0 deletions src/entities/report/api/updateReportStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { normalizeApiError, put, reportUrl } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import type { ReportStatusType } from "../model/types";

type UpdateReportStatusParams = {
id: number;
status: ReportStatusType;
};

export async function updateReportStatus({
id,
status,
}: UpdateReportStatusParams): Promise<void> {
try {
await put<BaseResponseType<null>>(
reportUrl.updateMalfunctionReportStatus(id),
{
status,
},
);
} catch (error) {
throw normalizeApiError(error);
}
}
20 changes: 10 additions & 10 deletions src/entities/report/api/useUpdateReportStatus.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { put, reportUrl, reportQueryKeys } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import type { ReportStatusType } from "../model/types";
import { reportQueryKeys } from "@/shared/api";
import { updateReportStatus } from "./updateReportStatus";

export function useUpdateReportStatus() {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({ id, status }: { id: number; status: ReportStatusType }) => {
await put<BaseResponseType<null>>(reportUrl.updateMalfunctionReportStatus(id), {
status,
});
},
mutationFn: updateReportStatus,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: reportQueryKeys.all,
});

alert("신고 상태가 변경되었습니다.");
},
onError: () => {
alert("신고 상태 변경 중 오류가 발생했습니다.");
onError: (error) => {
alert(
error instanceof Error
? error.message
: "신고 상태 변경 중 오류가 발생했습니다.",
);
},
});
}
2 changes: 1 addition & 1 deletion src/entities/report/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export type ReportResponseType = z.infer<typeof reportResponseSchema>;
// 고장 신고 목록 조회 요청 파라미터
export interface ReportParamsType {
status?: ReportStatusType;
}
}
10 changes: 7 additions & 3 deletions src/entities/reservation/api/deleteReservation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { del, reservationUrl } from "@/shared/api";
import { del, normalizeApiError, reservationUrl } from "@/shared/api";

export async function deleteReservation(id: number) {
await del(reservationUrl.deleteReservation(id));
export async function deleteReservation(id: number): Promise<void> {
try {
await del(reservationUrl.deleteReservation(id));
} catch (error) {
throw normalizeApiError(error);
}
}
29 changes: 19 additions & 10 deletions src/entities/reservation/api/getMachineReservationHistory.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import { get, reservationUrl } from "@/shared/api";
import { get, normalizeApiError, reservationUrl } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import { mapMachineReservationHistory } from "../lib/mapReservationHistory";
import type {
MachineReservationHistory,
MachineReservationHistoryParamsType,
MachineReservationHistoryResponseType,
} from "../model/historyTypes";
import { machineReservationHistoryResponseSchema } from "./schemas";

export async function getMachineReservationHistory(
params?: MachineReservationHistoryParamsType,
): Promise<MachineReservationHistory | null> {
const response = await get<
BaseResponseType<MachineReservationHistoryResponseType>
>(reservationUrl.getMachineReservationHistory(), {
params,
});
try {
const response = await get<BaseResponseType<unknown>>(
reservationUrl.getMachineReservationHistory(),
{
params,
},
);

const machine = response.data.machines[0];
const parsedData = machineReservationHistoryResponseSchema.parse(
response.data,
);

if (!machine) return null;
const machine = parsedData.machines[0];

return mapMachineReservationHistory(machine);
if (!machine) return null;

return mapMachineReservationHistory(machine);
} catch (error) {
throw normalizeApiError(error);
}
}
Loading
Loading