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
2 changes: 1 addition & 1 deletion src/app/app-download/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AuthLayout from "@/widgets/layout/auth-layout/ui/AuthLayout";
export default function AppDownloadPage() {
return (
<AuthLayout>
<div className="w-full max-w-[27.5rem] rounded-[20px] bg-white px-7 py-10 shadow-[0_12px_40px_rgba(0,0,0,0.06)]">
<div className="w-full max-w-110 rounded-[20px] bg-white px-7 py-10 shadow-[0_12px_40px_rgba(0,0,0,0.06)]">
<div className="mb-10 flex justify-center">
<div className="flex items-center gap-[0.41rem] w-auto">
<WasherLogo />
Expand Down
14 changes: 7 additions & 7 deletions src/entities/dashboard/api/getDashboardSummary.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { axiosInstance } from "@/shared";
import { dashboardUrl, get } 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 axiosInstance.get(
"/api/v2/admin/dashboard",
)) as BaseResponseType<DashboardSummaryDTO>;
const response = await get<BaseResponseType<unknown>>(
dashboardUrl.getSummary(),
);

return response.data;
}
return dashboardSummarySchema.parse(response.data);
}
1 change: 1 addition & 0 deletions src/entities/dashboard/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { getDashboardSummary } from "./getDashboardSummary";
export { useGetDashboardSummary } from "./useGetDashboardSummary";
11 changes: 11 additions & 0 deletions src/entities/dashboard/api/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

export const dashboardSummarySchema = z.object({
activeReservations: z.number(),
pendingMalfunctionReports: z.number(),
processingMalfunctionReports: z.number(),
completedMalfunctionReports: z.number(),
totalMachines: z.number(),
malfunctionMachines: z.number(),
suspendedStudents: z.number(),
});
17 changes: 17 additions & 0 deletions src/entities/dashboard/api/useGetDashboardSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useQuery } from "@tanstack/react-query";
import { dashboardQueryKeys } from "@/shared/api";
import { getDashboardSummary } from "./getDashboardSummary";

interface UseGetDashboardSummaryOptions {
enabled?: boolean;
}

export const useGetDashboardSummary = ({
enabled = true,
}: UseGetDashboardSummaryOptions = {}) => {
return useQuery({
queryKey: dashboardQueryKeys.summary(),
queryFn: getDashboardSummary,
enabled,
});
};
7 changes: 5 additions & 2 deletions src/entities/dashboard/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from "./api";
export { useGetDashboardSummary } from "./api";
export { mapDashboard } from "./lib/mapDashboard";
export * from "./model/types";
export type {
DashboardItem,
DashboardSummaryDTO,
} from "./model/types";
17 changes: 6 additions & 11 deletions src/entities/dashboard/model/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
export type DashboardSummaryDTO = {
activeReservations: number;
pendingMalfunctionReports: number;
processingMalfunctionReports: number;
completedMalfunctionReports: number;
totalMachines: number;
malfunctionMachines: number;
suspendedStudents: number;
};
import type { z } from "zod";
import type { dashboardSummarySchema } from "../api/schemas";

export type DashboardItem = {
export type DashboardSummaryDTO = z.infer<typeof dashboardSummarySchema>;

export interface DashboardItem {
label: string;
value: string;
};
}
39 changes: 39 additions & 0 deletions src/entities/machine/api/getMachines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { get, machineUrl } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import { mapMachines } from "../lib/mapMachine";
import type {
MachineItem,
MachineParamsType,
MachineType,
} from "../model/types";
import { machineResponseSchema } from "./schemas";

async function getMachinesByType(
machineType: MachineType,
params?: MachineParamsType,
): Promise<MachineItem[]> {
const response = await get<BaseResponseType<unknown>>(
machineUrl.getMachines(),
{
params: {
...params,
type: machineType,
},
},
);

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

return mapMachines(parsedData.machines);
}

export async function getMachines(
params?: MachineParamsType,
): Promise<MachineItem[]> {
const [washers, dryers] = await Promise.all([
getMachinesByType("WASHER", params),
getMachinesByType("DRYER", params),
]);

return [...washers, ...dryers];
}
42 changes: 42 additions & 0 deletions src/entities/machine/api/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { z } from "zod";

// 기기 타입
export const machineTypeSchema = z.enum(["WASHER", "DRYER"]);

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

// 기기 사용 가능 상태
export const machineAvailabilityStatusSchema = z.enum([
"AVAILABLE",
"IN_USE",
"RESERVED",
"UNAVAILABLE",
]);

// 기기 배치 위치
export const machinePositionSchema = z.enum(["LEFT", "RIGHT"]);

// 기기 한 건의 API 응답 구조
export const adminMachineDTOSchema = z.object({
id: z.number(),
name: z.string(),
type: machineTypeSchema,
floor: z.number(),
position: machinePositionSchema,
number: z.number(),
status: machineConditionStatusSchema,
availability: machineAvailabilityStatusSchema,
deviceId: z.string(),
});

// 기기 목록 API의 data 응답 구조
export const machineResponseSchema = z.object({
machines: z.array(adminMachineDTOSchema),
totalCount: z.number(),
totalPages: z.number(),
currentPage: z.number(),
});
43 changes: 17 additions & 26 deletions src/entities/machine/api/useGetMachines.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import { useQuery } from "@tanstack/react-query";
import { get, machineQueryKeys, machineUrl } from "@/shared/api";
import type { BaseResponseType } from "@/shared/api/types";
import { machineQueryKeys } from "@/shared/api";
import { STALE_TIME } from "@/shared/constants/queryOptions";
import type { MachineResponseType } from "../model/types";
import type { MachineParamsType } from "../model/types";
import { getMachines as fetchMachines } from "./getMachines";

interface UseGetMachinesOptions {
enabled?: boolean;
}

export const useGetMachines = (
params?: MachineParamsType,
options?: UseGetMachinesOptions,
) => {
const queryKey = machineQueryKeys.getMachines(params ?? {});

export const useGetMachines = (params: { floor?: number } = {}) => {
return useQuery({
staleTime: STALE_TIME.MACHINE,
queryKey: machineQueryKeys.getMachines(params),
queryFn: async () => {
const [washers, dryers] = await Promise.all([
get<BaseResponseType<MachineResponseType>>(machineUrl.getMachines(), {
params: { ...params, type: "WASHER" },
}),
get<BaseResponseType<MachineResponseType>>(machineUrl.getMachines(), {
params: { ...params, type: "DRYER" },
}),
]);

return {
...washers,
data: {
machines: [...washers.data.machines, ...dryers.data.machines],
totalCount: washers.data.totalCount + dryers.data.totalCount,
totalPages: Math.max(washers.data.totalPages, dryers.data.totalPages),
currentPage: washers.data.currentPage,
},
};
},
queryKey,
queryFn: () => fetchMachines(params),
enabled: options?.enabled,
});
};
};
64 changes: 33 additions & 31 deletions src/entities/machine/model/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export type MachineType = "WASHER" | "DRYER";

export type MachineConditionStatusDTO = "NORMAL" | "MALFUNCTION";

export type MachineAvailabilityStatusDTO =
| "AVAILABLE"
| "IN_USE"
| "RESERVED"
| "UNAVAILABLE";

import type { z } from "zod";
import type {
adminMachineDTOSchema,
machineAvailabilityStatusSchema,
machineConditionStatusSchema,
machinePositionSchema,
machineResponseSchema,
machineTypeSchema,
} from "../api/schemas";

// UI 타입
export type MachineStatusLabel =
| "사용중"
| "미사용"
Expand All @@ -16,8 +17,6 @@ export type MachineStatusLabel =
| "확인필요"
| "고장";

export type MachinePosition = "LEFT" | "RIGHT";

export interface MachineItem {
id: number;
name: string;
Expand All @@ -28,27 +27,30 @@ export interface MachineItem {
deviceStatus?: string;
}

export interface AdminMachineDTO {
id: number;
name: string;
type: MachineType;
floor: number;
position: MachinePosition;
number: number;
status: MachineConditionStatusDTO;
availability: MachineAvailabilityStatusDTO;
deviceId: string;
}

export interface MachineResponseType {
machines: AdminMachineDTO[];
totalCount: number;
totalPages: number;
currentPage: number;
}

export interface MachineStatusOption {
value: MachineConditionStatusDTO;
title: string;
description: string;
}

// API 응답 타입
export type MachineType = z.infer<typeof machineTypeSchema>;

export type MachineConditionStatusDTO = z.infer<
typeof machineConditionStatusSchema
>;

export type MachineAvailabilityStatusDTO = z.infer<
typeof machineAvailabilityStatusSchema
>;

export type MachinePosition = z.infer<typeof machinePositionSchema>;

export type AdminMachineDTO = z.infer<typeof adminMachineDTOSchema>;

export type MachineResponseType = z.infer<typeof machineResponseSchema>;

// 조회 파라미터
export interface MachineParamsType {
floor?: number;
}
18 changes: 14 additions & 4 deletions src/entities/report/api/getMalfunctionReports.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { get, 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<ReportResponseType>>(
const response = await get<BaseResponseType<unknown>>(
reportUrl.getMalfunctionReports(),
{
params,
},
);
return response;
};

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

return {
...response,
data: parsedData,
};
};
32 changes: 32 additions & 0 deletions src/entities/report/api/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { z } from "zod";

// 고장 신고 상태
export const reportStatusSchema = z.enum([
"PENDING",
"IN_PROGRESS",
"RESOLVED",
]);

// 고장 신고 한 건의 API 응답 구조
export const reportItemSchema = z.object({
id: z.number(),
machineId: z.number(),
machineName: z.string(),
reporterId: z.number(),
reporterName: z.string(),
description: z.string(),
status: reportStatusSchema,
reportedAt: z.string(),
processingStartedAt: z.string().nullable(),
resolvedAt: z.string().nullable(),
createdAt: z.string(),
updatedAt: z.string(),
});

// 고장 신고 목록 API의 data 응답 구조
export const reportResponseSchema = z.object({
reports: z.array(reportItemSchema),
totalCount: z.number(),
totalPages: z.number(),
currentPage: z.number(),
});
Loading
Loading