From c8059f3fae203e197a1714f81adec5c571881094 Mon Sep 17 00:00:00 2001 From: bicochan Date: Wed, 11 Jun 2025 15:52:28 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=20>=20=ED=9A=8C=EC=9B=90=20=EB=AA=A9=EB=A1=9D=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/cs/app/(with-base-layout)/users/page.tsx | 2 + apps/cs/src/entities/user/api/user-service.ts | 213 ++++++++++++ apps/cs/src/entities/user/index.ts | 5 + .../src/entities/user/model/user-interface.ts | 308 ++++++++++++++++++ apps/cs/src/pages/users/index.ts | 1 + .../src/pages/users/model/table-columns.tsx | 54 +++ apps/cs/src/pages/users/ui/users-page.tsx | 270 +++++++++++++++ 7 files changed, 853 insertions(+) create mode 100644 apps/cs/app/(with-base-layout)/users/page.tsx create mode 100644 apps/cs/src/entities/user/api/user-service.ts create mode 100644 apps/cs/src/entities/user/index.ts create mode 100644 apps/cs/src/entities/user/model/user-interface.ts create mode 100644 apps/cs/src/pages/users/index.ts create mode 100644 apps/cs/src/pages/users/model/table-columns.tsx create mode 100644 apps/cs/src/pages/users/ui/users-page.tsx diff --git a/apps/cs/app/(with-base-layout)/users/page.tsx b/apps/cs/app/(with-base-layout)/users/page.tsx new file mode 100644 index 000000000..35a8db5ae --- /dev/null +++ b/apps/cs/app/(with-base-layout)/users/page.tsx @@ -0,0 +1,2 @@ +import { UsersPage } from "@/pages/users"; +export default UsersPage; diff --git a/apps/cs/src/entities/user/api/user-service.ts b/apps/cs/src/entities/user/api/user-service.ts new file mode 100644 index 000000000..d7718c523 --- /dev/null +++ b/apps/cs/src/entities/user/api/user-service.ts @@ -0,0 +1,213 @@ +import { client } from "@/shared/api"; +import { ENDPOINT } from "@/shared/config"; +import type { + UserService, + UserSearchParams, + UserList, + UserDetailResponse, + UserSttsStatsList, + UserUpdateData, + UserPasswordUpdateData, + UserFindPasswordUpdateData, + UserPasswordMatchData, + UserUpdateInfoData, + UserSaveData, + UserFindPasswordSaveData, + UserVerifyData, + UserEmailData, + UserIdData, +} from "../model/user-interface"; + +export class UserApiService implements UserService { + // 사용자 목록 조회 + public async findPageUser(params: UserSearchParams): Promise { + const response = await client.get( + `${ENDPOINT.USER_SERVICE.USERS}`, + { params }, + ); + return response.data; + } + + // 사용자 단건 조회 + public async findByUserUnqId(userUnqId: string): Promise { + const response = await client.get( + `${ENDPOINT.USER_SERVICE.USERS}/${userUnqId}`, + ); + return response.data; + } + + // 로그인한 사용자 정보 조회 + public async findByUserUnqIdByLogin(): Promise { + const response = await client.get( + `${ENDPOINT.USER_SERVICE.USERS}/info/me`, + ); + return response.data; + } + + // 사용자 회원상태 통계 조회 + public async selectUserSttsStats(): Promise { + const response = await client.get( + `${ENDPOINT.USER_SERVICE.USERS}/stts/stats`, + ); + return response.data; + } + + // 사용자 저장 + public async saveUser(data: UserSaveData): Promise { + const response = await client.post( + `${ENDPOINT.USER_SERVICE.USERS}`, + data, + ); + return response.data; + } + + // 사용자 수정 + public async updateUser( + userUnqId: string, + data: UserUpdateData, + ): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/${userUnqId}`, + data, + ); + return response.data; + } + + // 사용자 삭제 + public async deleteUser(userUnqId: string): Promise { + const response = await client.delete( + `${ENDPOINT.USER_SERVICE.USERS}/delete/${userUnqId}`, + ); + return response.data; + } + + // 사용자 계정잠금 처리 + public async lockUser(userUnqId: string): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/lock/${userUnqId}`, + ); + return response.data; + } + + // 사용자 계정잠금 해제처리 + public async unlockUser(userUnqId: string): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/unlock/${userUnqId}`, + ); + return response.data; + } + + // 리프레시 토큰 정보 재발급 + public async refreshToken(): Promise { + await client.put(`${ENDPOINT.USER_SERVICE.USERS}/token/refresh`); + } + + // 사용자 비밀번호 변경 + public async updatePassword(data: UserPasswordUpdateData): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/password/update`, + data, + ); + return response.data; + } + + // 사용자 비밀번호 초기화(관리자용) + public async initializePassword( + userUnqId: string, + data: UserPasswordUpdateData, + ): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/password/initialize/${userUnqId}`, + data, + ); + return response.data; + } + + // 사용자 비밀번호 찾기 변경 + public async changePassword( + data: UserFindPasswordUpdateData, + ): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/password/change`, + data, + ); + return response.data; + } + + // 사용자 비밀번호 확인 + public async matchPassword(data: UserPasswordMatchData): Promise { + const response = await client.post( + `${ENDPOINT.USER_SERVICE.USERS}/password/match`, + data, + ); + return response.data; + } + + // 사용자 비밀번호 찾기 + public async findPasswordUser( + data: UserFindPasswordSaveData, + ): Promise { + const response = await client.post( + `${ENDPOINT.USER_SERVICE.USERS}/password/find`, + data, + ); + return response.data; + } + + // 사용자 비밀번호 찾기 유효성 확인 + public async validPassword(token: string): Promise { + const response = await client.get( + `${ENDPOINT.USER_SERVICE.USERS}/password/valid/${token}`, + ); + return response.data; + } + + // 사용자 회원정보 변경 + public async updateInfo( + userUnqId: string, + data: UserUpdateInfoData, + ): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/info/${userUnqId}`, + data, + ); + return response.data; + } + + // 사용자 승인처리 + public async applyUser(userUnqId: string): Promise { + const response = await client.put( + `${ENDPOINT.USER_SERVICE.USERS}/apply/${userUnqId}`, + ); + return response.data; + } + + // 사용자 회원탈퇴 + public async leaveUser(data: UserVerifyData): Promise { + const response = await client.post( + `${ENDPOINT.USER_SERVICE.USERS}/leave`, + data, + ); + return response.data; + } + + // 사용자 이메일 중복 체크 + public async existsEmail(data: UserEmailData): Promise { + const response = await client.post( + `${ENDPOINT.USER_SERVICE.USERS}/exists`, + data, + ); + return response.data; + } + + // 사용자 아이디 중복 체크 + public async existsUserId(data: UserIdData): Promise { + const response = await client.post( + `${ENDPOINT.USER_SERVICE.USERS}/existsUserId`, + data, + ); + return response.data; + } +} + +export const UserApi = new UserApiService(); diff --git a/apps/cs/src/entities/user/index.ts b/apps/cs/src/entities/user/index.ts new file mode 100644 index 000000000..937942481 --- /dev/null +++ b/apps/cs/src/entities/user/index.ts @@ -0,0 +1,5 @@ +export { UserApi } from "./api/user-service"; +export { + type UserSearchParams, + type UserListResponse, +} from "./model/user-interface"; diff --git a/apps/cs/src/entities/user/model/user-interface.ts b/apps/cs/src/entities/user/model/user-interface.ts new file mode 100644 index 000000000..7860039b4 --- /dev/null +++ b/apps/cs/src/entities/user/model/user-interface.ts @@ -0,0 +1,308 @@ +import { z } from "zod"; +import type { PageableList, PageableParams } from "@/shared/model"; + +// 사용자 검색 파라미터 +export interface UserSearchParams extends PageableParams { + keywordType?: string; + keyword?: string; + userStateCode?: string; + aprvYn?: string; + grpId?: string; + frDateYmd?: string; + toDateYmd?: string; +} + +// 사용자 목록 응답 인터페이스 +export interface UserListResponse { + userId: string; + userName: string; + email: string; + roleId: string; + roleName: string; + userStateCode: string; + userStateCodeName: string; + lastLoginDate: string; + loginFailCount: number; + userUnqId: string; + mphn: string; + telno: string; + aprvYn: string; + regDt: string; + laeSeCd: string; + laeSeNm: string; + ogdpSeCd: string; + ogdpSeNm: string; + instSeCd: string; + instSeNm: string; + aprvYmd: string; +} + +// 사용자 상세 응답 인터페이스 +export interface UserDetailResponse { + regDt: string; + mdfcnDt: string; + rgtr: string; + mdfr: string; + userUnqId: string; + userId: string; + userName: string; + email: string; + encryptedPassword: string; + refreshToken: string; + userStateCode: string; + lastLoginDate: string; + loginFailCount: number; + pswdHnt: string; + pswdAns: string; + mphn: string; + telno: string; + zip: string; + addr: string; + daddr: string; + laeSeCd: string; + ogdpSeCd: string; + aprvYn: string; + autzrId: string; + expryYmd: string; + lastPswdChgDt: string; + googleId: string; + kakaoId: string; + naverId: string; + isSocialUser: boolean; + hasPassword: boolean; + twoFactorEnabled: boolean; + adminRoleYn: string; + instSeCd: string; + aprvYmd: string; + enoCd: string; + laeSeNm: string; + ogdpSeNm: string; + instSeNm: string; + userStateNm: string; + pswdHntNm: string; + ecoNm: string; +} + +// 사용자 상태 통계 응답 인터페이스 +export interface UserSttsStatsResponse { + sttsCd: string; + sttsNm: string; + cnt: number; +} + +// 사용자 수정 요청 스키마 +export const userUpdateSchema = z.object({ + userId: z.string().optional(), + userName: z.string(), + email: z.string().email().optional(), + password: z + .string() + .regex(/((?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20})|()/) + .optional(), + roleId: z.string().optional(), + userStateCode: z.string(), + pswdHnt: z.string().max(10), + pswdAns: z.string().max(100).optional(), + mphn: z.string().max(11).optional(), + telno: z.string().max(11).optional(), + zip: z.string().max(5).optional(), + addr: z.string().max(200).optional(), + daddr: z.string().max(200).optional(), + laeSeCd: z.string().max(10), + ogdpSeCd: z.string().max(10), + aprvYn: z.string(), + autzrId: z.string().uuid().optional(), + expryYmd: z.string().max(8), + instSeCd: z.string().optional(), + aprvYmd: z.string().max(8).optional(), + enoCd: z.string().optional(), +}); + +// 사용자 비밀번호 변경 스키마 +export const userPasswordUpdateSchema = z.object({ + password: z + .string() + .regex(/((?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20})|()/) + .optional() + .describe("기존 패스워드"), + provider: z.string().optional().describe("공급자(기본값:password)"), + token: z.string().optional(), + newPassword: z + .string() + .regex(/(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20}/) + .describe("신규 패스워드"), + newPasswordConfirm: z + .string() + .regex(/(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20}/) + .describe("신규 패스워드 확인"), +}); + +// 사용자 비밀번호 찾기 변경 스키마 +export const userFindPasswordUpdateSchema = z.object({ + tokenValue: z.string(), + password: z + .string() + .regex(/(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20}/), +}); + +// 사용자 비밀번호 확인 스키마 +export const userPasswordMatchSchema = z.object({ + password: z + .string() + .regex(/(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20}/), +}); + +// 사용자 회원정보 변경 스키마 +export const userUpdateInfoSchema = z.object({ + password: z + .string() + .regex(/((?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20})|()/) + .optional() + .describe("기존 패스워드"), + provider: z.string().optional().describe("공급자(기본값:password)"), + token: z.string().optional(), + userName: z.string(), + email: z.string().email().optional(), +}); + +// 사용자 저장 스키마 +export const userSaveSchema = z.object({ + userId: z.string().describe("사용자 ID"), + userName: z.string().describe("사용자명"), + email: z.string().email().optional().describe("이메일"), + password: z + .string() + .regex(/(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20}/) + .describe("패스워드"), + pswdHnt: z.string().max(10).describe("비밀번호 힌트"), + pswdAns: z.string().max(100).optional().describe("비밀번호 답변"), + mphn: z.string().max(11).optional().describe("휴대폰 번호"), + telno: z.string().max(11).optional().describe("전화번호"), + zip: z.string().max(5).optional().describe("우편번호"), + addr: z.string().max(200).optional().describe("주소"), + daddr: z.string().max(200).optional().describe("상세 주소"), + laeSeCd: z.string().max(10).describe("법적 구분 코드"), + ogdpSeCd: z.string().max(10).describe("조직 구분 코드"), + expryYmd: z.string().max(8).describe("만료 일자(YYYYMMDD)"), + instSeCd: z.string().optional().describe("기관구분코드"), + enoCd: z.string().optional().describe("환경청코드"), +}); + +// 사용자 비밀번호 찾기 저장 스키마 +export const userFindPasswordSaveSchema = z.object({ + userName: z.string(), + emailAddr: z.string().email(), + mainUrl: z.string(), + changePasswordUrl: z.string(), +}); + +// 사용자 인증 요청 스키마 +export const userVerifySchema = z.object({ + password: z + .string() + .regex(/((?=.*[0-9])(?=.*[a-zA-Z])(?=.*\W)(?=\S+$).{8,20})|()/) + .optional() + .describe("기존 패스워드"), + provider: z.string().optional().describe("공급자(기본값:password)"), + token: z.string().optional(), +}); + +// 사용자 이메일 요청 스키마 +export const userEmailSchema = z.object({ + userId: z.string().optional(), + email: z.string().email(), +}); + +// 사용자 ID 요청 스키마 +export const userIdSchema = z.object({ + userId: z.string(), +}); + +// Zod 스키마 타입 정의 +export type UserUpdateData = z.infer; +export type UserPasswordUpdateData = z.infer; +export type UserFindPasswordUpdateData = z.infer< + typeof userFindPasswordUpdateSchema +>; +export type UserPasswordMatchData = z.infer; +export type UserUpdateInfoData = z.infer; +export type UserSaveData = z.infer; +export type UserFindPasswordSaveData = z.infer< + typeof userFindPasswordSaveSchema +>; +export type UserVerifyData = z.infer; +export type UserEmailData = z.infer; +export type UserIdData = z.infer; + +// 페이지네이션 타입 정의 +export type UserList = PageableList; +export type UserSttsStatsList = UserSttsStatsResponse[]; + +// 사용자 서비스 인터페이스 +export interface UserService { + // 사용자 목록 조회 + findPageUser: (params: UserSearchParams) => Promise; + + // 사용자 단건 조회 + findByUserUnqId: (userUnqId: string) => Promise; + + // 로그인한 사용자 정보 조회 + findByUserUnqIdByLogin: () => Promise; + + // 사용자 회원상태 통계 조회 + selectUserSttsStats: () => Promise; + + // 사용자 저장 + saveUser: (data: UserSaveData) => Promise; + + // 사용자 수정 + updateUser: (userUnqId: string, data: UserUpdateData) => Promise; + + // 사용자 삭제 + deleteUser: (userUnqId: string) => Promise; + + // 사용자 계정잠금 처리 + lockUser: (userUnqId: string) => Promise; + + // 사용자 계정잠금 해제처리 + unlockUser: (userUnqId: string) => Promise; + + // 리프레시 토큰 정보 재발급 + refreshToken: () => Promise; + + // 사용자 비밀번호 변경 + updatePassword: (data: UserPasswordUpdateData) => Promise; + + // 사용자 비밀번호 초기화(관리자용) + initializePassword: ( + userUnqId: string, + data: UserPasswordUpdateData, + ) => Promise; + + // 사용자 비밀번호 찾기 변경 + changePassword: (data: UserFindPasswordUpdateData) => Promise; + + // 사용자 비밀번호 확인 + matchPassword: (data: UserPasswordMatchData) => Promise; + + // 사용자 비밀번호 찾기 + findPasswordUser: (data: UserFindPasswordSaveData) => Promise; + + // 사용자 비밀번호 찾기 유효성 확인 + validPassword: (token: string) => Promise; + + // 사용자 회원정보 변경 + updateInfo: (userUnqId: string, data: UserUpdateInfoData) => Promise; + + // 사용자 승인처리 + applyUser: (userUnqId: string) => Promise; + + // 사용자 회원탈퇴 + leaveUser: (data: UserVerifyData) => Promise; + + // 사용자 이메일 중복 체크 + existsEmail: (data: UserEmailData) => Promise; + + // 사용자 아이디 중복 체크 + existsUserId: (data: UserIdData) => Promise; +} diff --git a/apps/cs/src/pages/users/index.ts b/apps/cs/src/pages/users/index.ts new file mode 100644 index 000000000..03ca6d940 --- /dev/null +++ b/apps/cs/src/pages/users/index.ts @@ -0,0 +1 @@ +export { UsersPage } from "./ui/users-page"; diff --git a/apps/cs/src/pages/users/model/table-columns.tsx b/apps/cs/src/pages/users/model/table-columns.tsx new file mode 100644 index 000000000..a51ce557f --- /dev/null +++ b/apps/cs/src/pages/users/model/table-columns.tsx @@ -0,0 +1,54 @@ +import type { UserListResponse } from "@/entities/user"; +import type { ColumnDef } from "@tanstack/react-table"; + +export const columns: ColumnDef[] = [ + { + id: "no", + header: "No", + cell: ({ row }) => row.index + 1, + }, + { + accessorKey: "userId", + header: "아이디", + }, + { + accessorKey: "userName", + header: "이름", + }, + { + accessorKey: "telno", + header: "전화번호", + }, + { + accessorKey: "email", + header: "이메일", + }, + { + accessorKey: "laeSeNm", + header: "구분", + }, + { + accessorKey: "ogdpSeNm", + header: "소속", + }, + { + accessorKey: "instSeNm", + header: "기관/부서", + }, + { + accessorKey: "userStateCodeName", + header: "회원상태", + }, + { + accessorKey: "aprvYmd", + header: "승인일자", + }, + { + accessorKey: "loginFailCount", + header: "로그인실패횟수", + }, + { + accessorKey: "lastLoginDate", + header: "최종접속일", + }, +]; diff --git a/apps/cs/src/pages/users/ui/users-page.tsx b/apps/cs/src/pages/users/ui/users-page.tsx new file mode 100644 index 000000000..9bae6dedf --- /dev/null +++ b/apps/cs/src/pages/users/ui/users-page.tsx @@ -0,0 +1,270 @@ +"use client"; + +import dayjs from "dayjs"; +import { useState } from "react"; +import { useForm } from "react-hook-form"; +import { useRouter } from "next/navigation"; +import { useQuery } from "@tanstack/react-query"; +import { + getCoreRowModel, + useReactTable, + type PaginationState, +} from "@tanstack/react-table"; +import { + Button, + Checkbox, + DataTable, + DateRangePicker, + Input, + Label, + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@common/components"; +import { CodeApi } from "@/entities/code"; +import { UserApi, type UserSearchParams } from "@/entities/user"; +import { ENDPOINT } from "@/shared/config"; +import { columns } from "../model/table-columns"; + +type DateRange = { + from: Date | undefined; + to?: Date | undefined; +}; + +function UsersPage() { + const router = useRouter(); + + const [pagination, setPagination] = useState({ + pageIndex: 0, + pageSize: 10, + }); + const [dateRange, setDateRange] = useState(); + + const { register, watch, setValue, getValues } = useForm({ + defaultValues: { + keywordType: "all", + keyword: "", + userStateCode: "", + aprvYn: "", + grpId: "", + frDateYmd: "", + toDateYmd: "", + sort: ["aprvYmd,desc"], + }, + }); + + const { data: users, refetch } = useQuery({ + queryKey: [ENDPOINT.USER_SERVICE.USERS, pagination, watch("sort")], + queryFn: () => + UserApi.findPageUser({ + ...getValues(), + page: pagination.pageIndex, + size: pagination.pageSize, + }), + }); + + const { data: userStateCode } = useQuery({ + queryKey: [ENDPOINT.CMS_SERVICE.CODE], + queryFn: () => CodeApi.getCode("USERSTTS"), + }); + + const table = useReactTable({ + data: users?.content ?? [], + columns, + state: { + pagination, + }, + rowCount: users?.totalElements ?? 0, + manualPagination: true, + getCoreRowModel: getCoreRowModel(), + onPaginationChange: setPagination, + }); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + refetch(); + }; + + const handleRowClick = (row: unknown) => { + console.log(row); + }; + + const handlePresetDateRange = (value: string) => { + let presetDateRange: DateRange | undefined; + switch (value) { + case "1M": + presetDateRange = { + from: dayjs().subtract(1, "month").toDate(), + to: dayjs().toDate(), + }; + break; + case "3M": + presetDateRange = { + from: dayjs().subtract(3, "month").toDate(), + to: dayjs().toDate(), + }; + break; + case "6M": + presetDateRange = { + from: dayjs().subtract(6, "month").toDate(), + to: dayjs().toDate(), + }; + break; + default: + presetDateRange = undefined; + } + setDateRange(presetDateRange); + setValue("frDateYmd", dayjs(presetDateRange?.from).format("YYYYMMDD")); + setValue("toDateYmd", dayjs(presetDateRange?.to).format("YYYYMMDD")); + }; + + return ( +
+
+
+
+
+ + + +
+
+ + {/* Select */} +
+
+ + { + setDateRange(value); + setValue("frDateYmd", dayjs(value?.from).format("YYYYMMDD")); + setValue("toDateYmd", dayjs(value?.to).format("YYYYMMDD")); + }} + > +
+ +
+
+
+
+
+ +
+ {userStateCode?.map((item) => ( +
+ { + setValue( + "userStateCode", + checked + ? getValues("userStateCode") + ? `${getValues("userStateCode")},${item.lwpoCd}` + : item.lwpoCd + : getValues("userStateCode") + ?.split(",") + .filter((code) => code !== item.lwpoCd) + .join(","), + ); + }} + /> + +
+ ))} +
+
+
+ + +
+
+
+
+

회원 목록

+
+ + + +
+
+
+
+ +
+
+
+ ); +} + +export { UsersPage };