refactor: 그룹 서비스 및 인터페이스 엔티티 폴더로 이동
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
import { client } from "@/shared/api";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import type {
|
||||
GroupService,
|
||||
GroupSearchParams,
|
||||
GroupList,
|
||||
GroupResponseDto,
|
||||
GroupFormData,
|
||||
} from "../model/groups-interface";
|
||||
|
||||
export class GroupsApiService implements GroupService {
|
||||
// 그룹 목록 조회
|
||||
public async findPageGroup(params: GroupSearchParams): Promise<GroupList> {
|
||||
const response = await client.get<GroupList>(
|
||||
`${ENDPOINT.CMS_SERVICE.GROUPS}`,
|
||||
{ params },
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// 그룹 단건 조회
|
||||
public async findGroupById(groupId: string): Promise<GroupResponseDto> {
|
||||
const response = await client.get<GroupResponseDto>(
|
||||
`${ENDPOINT.CMS_SERVICE.GROUPS}/${groupId}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// 그룹 저장
|
||||
public async saveGroup(data: GroupFormData): Promise<GroupResponseDto> {
|
||||
const response = await client.post<GroupResponseDto>(
|
||||
`${ENDPOINT.CMS_SERVICE.GROUPS}`,
|
||||
data,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// 그룹 수정
|
||||
public async updateGroup(
|
||||
groupId: string,
|
||||
data: GroupFormData,
|
||||
): Promise<GroupResponseDto> {
|
||||
const response = await client.put<GroupResponseDto>(
|
||||
`${ENDPOINT.CMS_SERVICE.GROUPS}/${groupId}`,
|
||||
data,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// 그룹 삭제
|
||||
public async deleteGroup(groupId: string): Promise<boolean> {
|
||||
const response = await client.delete<boolean>(
|
||||
`${ENDPOINT.CMS_SERVICE.GROUPS}/${groupId}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const GroupsApi = new GroupsApiService();
|
||||
@@ -1,87 +0,0 @@
|
||||
import { z } from "zod";
|
||||
import type { PageableList, PageableParams } from "@/shared/model";
|
||||
|
||||
// 그룹 검색 파라미터 인터페이스
|
||||
export interface GroupSearchParams extends PageableParams {
|
||||
keywordType?: string;
|
||||
keyword?: string;
|
||||
groupId?: string;
|
||||
groupNm?: string;
|
||||
groupSeCd?: string;
|
||||
delYn?: string;
|
||||
authrtId?: string;
|
||||
siteId?: string;
|
||||
groupExpln?: string;
|
||||
roleId?: string;
|
||||
mngrYn?: string;
|
||||
}
|
||||
|
||||
// 그룹 목록 응답 인터페이스
|
||||
export interface GroupListResponseDto {
|
||||
groupId: string;
|
||||
groupNm: string;
|
||||
groupSeCd: string;
|
||||
groupSeNm: string;
|
||||
delYn: string;
|
||||
authrtId: string;
|
||||
groupExpln: string;
|
||||
siteId: string;
|
||||
mngrYn: string;
|
||||
roleId: string;
|
||||
roleNm: string;
|
||||
mdfcnDt: string;
|
||||
mdfrNm: string;
|
||||
}
|
||||
|
||||
// 그룹 상세 응답 인터페이스
|
||||
export interface GroupResponseDto {
|
||||
groupId: string;
|
||||
groupNm: string;
|
||||
groupSeCd: string;
|
||||
groupSeNm: string;
|
||||
groupExpln: string;
|
||||
delYn: string;
|
||||
regDt: string;
|
||||
rgtr: string;
|
||||
mdfcnDt: string;
|
||||
mdfr: string;
|
||||
authrtId: string;
|
||||
siteId: string;
|
||||
mngrYn: string;
|
||||
}
|
||||
|
||||
// 그룹 저장 데이터 스키마
|
||||
export const groupFormSchema = z.object({
|
||||
groupId: z.string().min(1, { message: "그룹 ID를 입력해주세요." }),
|
||||
groupNm: z.string().min(1, { message: "그룹명을 입력해주세요." }),
|
||||
groupSeCd: z.string().min(1, { message: "그룹구분을 선택해주세요." }),
|
||||
groupExpln: z.string().optional(),
|
||||
delYn: z.string().default("N"),
|
||||
authrtId: z.string().min(1, { message: "권한ID를 선택해주세요." }),
|
||||
siteId: z.string().optional(),
|
||||
mngrYn: z.string().default("N"),
|
||||
});
|
||||
|
||||
export type GroupList = PageableList<GroupListResponseDto>;
|
||||
export type GroupFormData = z.infer<typeof groupFormSchema>;
|
||||
|
||||
// 그룹 서비스 인터페이스
|
||||
export interface GroupService {
|
||||
// 그룹 목록 조회
|
||||
findPageGroup: (params: GroupSearchParams) => Promise<GroupList>;
|
||||
|
||||
// 그룹 단건 조회
|
||||
findGroupById: (groupId: string) => Promise<GroupResponseDto>;
|
||||
|
||||
// 그룹 저장
|
||||
saveGroup: (data: GroupFormData) => Promise<GroupResponseDto>;
|
||||
|
||||
// 그룹 수정
|
||||
updateGroup: (
|
||||
groupId: string,
|
||||
data: GroupFormData,
|
||||
) => Promise<GroupResponseDto>;
|
||||
|
||||
// 그룹 삭제
|
||||
deleteGroup: (groupId: string) => Promise<boolean>;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type ColumnDef } from "@tanstack/react-table";
|
||||
import { Button } from "@common/components";
|
||||
import { type GroupListResponseDto } from "./groups-interface";
|
||||
import { type GroupListResponseDto } from "@/entities/group";
|
||||
import { MenuAuthorityDialog } from "../ui/menu-authority-dialog";
|
||||
import { GroupsDialog } from "../ui/groups-dialog";
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ import {
|
||||
} from "@/shared/ui/form";
|
||||
import { CodeSelect } from "@/entities/code";
|
||||
import { SiteSelect } from "@/entities/site";
|
||||
import type { GroupFormData } from "@/entities/group";
|
||||
import { RoleSelect } from "./role-select";
|
||||
import type { GroupFormData } from "../model/groups-interface";
|
||||
|
||||
type GroupFormProps = {
|
||||
form: UseFormReturn<GroupFormData>;
|
||||
|
||||
@@ -15,12 +15,15 @@ import {
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
} from "@common/components";
|
||||
import { Form } from "@/shared/ui/form";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import {
|
||||
GroupApi,
|
||||
groupFormSchema,
|
||||
type GroupFormData,
|
||||
} from "@/entities/group";
|
||||
import { useAlertStore, useMutationWrapper } from "@/shared/lib";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import { Form } from "@/shared/ui/form";
|
||||
import { GroupForm } from "./group-form";
|
||||
import { GroupsApi } from "../api/groups-service";
|
||||
import { groupFormSchema, type GroupFormData } from "../model/groups-interface";
|
||||
|
||||
type GroupsDialogProps = {
|
||||
groupId?: string;
|
||||
@@ -39,12 +42,12 @@ const GroupsDialog = memo(
|
||||
|
||||
const { data: group } = useQuery({
|
||||
queryKey: [ENDPOINT.CMS_SERVICE.GROUPS, groupId],
|
||||
queryFn: () => GroupsApi.findGroupById(groupId!),
|
||||
queryFn: () => GroupApi.findGroupById(groupId!),
|
||||
enabled: !!groupId,
|
||||
});
|
||||
|
||||
const { mutateAsync: createGroup } = useMutationWrapper({
|
||||
mutationFn: (data: GroupFormData) => GroupsApi.saveGroup(data),
|
||||
mutationFn: (data: GroupFormData) => GroupApi.saveGroup(data),
|
||||
onSuccess: () => {
|
||||
alert("등록되었습니다.", () => {
|
||||
setOpen(false);
|
||||
@@ -55,7 +58,7 @@ const GroupsDialog = memo(
|
||||
|
||||
const { mutateAsync: updateGroup } = useMutationWrapper({
|
||||
mutationFn: (data: GroupFormData) =>
|
||||
GroupsApi.updateGroup(groupId ?? "", data),
|
||||
GroupApi.updateGroup(groupId ?? "", data),
|
||||
onSuccess: () => {
|
||||
alert("수정되었습니다.", () => {
|
||||
setOpen(false);
|
||||
|
||||
@@ -4,10 +4,10 @@ import { useState } from "react";
|
||||
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
||||
import { getCoreRowModel, type PaginationState } from "@tanstack/react-table";
|
||||
import { Button } from "@common/components";
|
||||
import { GroupApi } from "@/entities/group";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import { useDataTable } from "@/shared/lib";
|
||||
import { columns } from "../model/groups-table-columns";
|
||||
import { GroupsApi } from "../api/groups-service";
|
||||
import { GroupsDialog } from "./groups-dialog";
|
||||
|
||||
type GroupsSectionProps = {
|
||||
@@ -23,7 +23,7 @@ function GroupsSection({ handleSelectedGroup }: GroupsSectionProps) {
|
||||
const query = useQuery({
|
||||
queryKey: [ENDPOINT.CMS_SERVICE.GROUPS, pagination],
|
||||
queryFn: () =>
|
||||
GroupsApi.findPageGroup({
|
||||
GroupApi.findPageGroup({
|
||||
page: pagination.pageIndex,
|
||||
size: pagination.pageSize,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user