사용자 계정 관리 기능 구현 및 API 오류 수정
- 사용자 로그인 인증정보 관리 기능 구현 (이메일/휴대폰 추가/삭제) - 사용자 추가 기능 구현 (실시간 ID 중복 검증 포함) - 사용자 목록 조회 기능 구현 - API 엔드포인트 오류 수정 (userExistsUserid: GET → POST, URL 경로 수정) - TypeScript 타입 오류 수정 (UseQueryOptions, UserCreateParams/Response) - 이메일/휴대폰 형식 검증 및 중복 방지 로직 추가 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,24 +1,50 @@
|
||||
import axios from 'axios';
|
||||
import { API_URL } from '@/shared/api/urls';
|
||||
import { resultify } from '@/shared/lib/resultify';
|
||||
import { API_URL_USER } from '@/shared/api/api-url-user';
|
||||
import { CBDCAxiosError } from '@/shared/@types/error';
|
||||
import {
|
||||
import {
|
||||
UserCreateParams,
|
||||
UserCreateResponse
|
||||
} from '../model/types';
|
||||
import {
|
||||
|
||||
interface UserCreateMutationResponse {
|
||||
status: boolean;
|
||||
data?: UserCreateResponse;
|
||||
error?: {
|
||||
root: string;
|
||||
errKey: string;
|
||||
code: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
details: Record<string, string>;
|
||||
};
|
||||
}
|
||||
|
||||
import {
|
||||
useMutation,
|
||||
UseMutationOptions
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
export const userCreate = (params: UserCreateParams) => {
|
||||
return resultify(
|
||||
axios.post<UserCreateResponse>(API_URL.userCreate(), params),
|
||||
);
|
||||
export const userCreate = async (params: UserCreateParams): Promise<UserCreateMutationResponse> => {
|
||||
try {
|
||||
const response = await axios.post<UserCreateResponse>(API_URL_USER.userCreate(), params);
|
||||
return { status: true, data: response.data };
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: false,
|
||||
error: {
|
||||
root: 'USER_CREATE',
|
||||
errKey: error.response?.data?.errKey || 'UNKNOWN_ERROR',
|
||||
code: error.response?.status?.toString() || '500',
|
||||
message: error.response?.data?.message || error.message || 'Unknown error',
|
||||
timestamp: new Date().toISOString(),
|
||||
details: error.response?.data?.details || {}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const useUserCreateMutation = (options?: UseMutationOptions<UserCreateResponse, CBDCAxiosError, UserCreateParams>) => {
|
||||
const mutation = useMutation<UserCreateResponse, CBDCAxiosError, UserCreateParams>({
|
||||
export const useUserCreateMutation = (options?: UseMutationOptions<UserCreateMutationResponse, CBDCAxiosError, UserCreateParams>) => {
|
||||
const mutation = useMutation<UserCreateMutationResponse, CBDCAxiosError, UserCreateParams>({
|
||||
...options,
|
||||
mutationFn: (params: UserCreateParams) => userCreate(params),
|
||||
});
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import axios from 'axios';
|
||||
import { API_URL } from '@/shared/api/urls';
|
||||
import { API_URL_USER } from '@/shared/api/api-url-user';
|
||||
import { resultify } from '@/shared/lib/resultify';
|
||||
import { CBDCAxiosError } from '@/shared/@types/error';
|
||||
import {
|
||||
UserExistsUseridParams,
|
||||
UserExistsUseridResponse
|
||||
} from '../model/types';
|
||||
import {
|
||||
@@ -11,16 +10,16 @@ import {
|
||||
UseMutationOptions
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
export const userExistsUserid = (params: UserExistsUseridParams) => {
|
||||
export const userExistsUserid = (usrId: string) => {
|
||||
return resultify(
|
||||
axios.post<UserExistsUseridResponse>(API_URL.userExistsUserid(), params),
|
||||
axios.post<UserExistsUseridResponse>(API_URL_USER.userExistsUserid(usrId)),
|
||||
);
|
||||
};
|
||||
|
||||
export const useUserExistsUseridMutation = (options?: UseMutationOptions<UserExistsUseridResponse, CBDCAxiosError, UserExistsUseridParams>) => {
|
||||
const mutation = useMutation<UserExistsUseridResponse, CBDCAxiosError, UserExistsUseridParams>({
|
||||
export const useUserExistsUseridMutation = (options?: UseMutationOptions<UserExistsUseridResponse, CBDCAxiosError, string>) => {
|
||||
const mutation = useMutation<UserExistsUseridResponse, CBDCAxiosError, string>({
|
||||
...options,
|
||||
mutationFn: (params: UserExistsUseridParams) => userExistsUserid(params),
|
||||
mutationFn: (usrId: string) => userExistsUserid(usrId),
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
31
src/entities/user/api/use-user-exists-userid-query.ts
Normal file
31
src/entities/user/api/use-user-exists-userid-query.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import axios from 'axios';
|
||||
import { API_URL_USER } from '@/shared/api/api-url-user';
|
||||
import { CBDCAxiosError } from '@/shared/@types/error';
|
||||
import {
|
||||
UserExistsUseridResponse
|
||||
} from '../model/types';
|
||||
import {
|
||||
useQuery,
|
||||
UseQueryOptions
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
export const userExistsUserid = async (usrid: string) => {
|
||||
const response = await axios.post<UserExistsUseridResponse>(API_URL_USER.userExistsUserid(usrid));
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const useUserExistsUseridQuery = (
|
||||
usrid: string,
|
||||
options?: Omit<UseQueryOptions<UserExistsUseridResponse, CBDCAxiosError>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
const query = useQuery<UserExistsUseridResponse, CBDCAxiosError>({
|
||||
queryKey: ['userExistsUserid', usrid],
|
||||
queryFn: async () => await userExistsUserid(usrid),
|
||||
enabled: !!usrid && usrid.trim().length > 0, // usrid가 있을 때만 실행
|
||||
...options,
|
||||
});
|
||||
|
||||
return {
|
||||
...query,
|
||||
};
|
||||
};
|
||||
29
src/entities/user/api/use-user-find-authmethod-mutation.ts
Normal file
29
src/entities/user/api/use-user-find-authmethod-mutation.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import axios from 'axios';
|
||||
import { API_URL_USER } from '@/shared/api/api-url-user';
|
||||
import { resultify } from '@/shared/lib/resultify';
|
||||
import { CBDCAxiosError } from '@/shared/@types/error';
|
||||
import {
|
||||
UserFindAuthMethodParams,
|
||||
UserFindAuthMethodResponse
|
||||
} from '../model/types';
|
||||
import {
|
||||
useMutation,
|
||||
UseMutationOptions
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
export const userFindAuthMethod = (params: UserFindAuthMethodParams) => {
|
||||
return resultify(
|
||||
axios.post<UserFindAuthMethodResponse>(API_URL_USER.findAuthMethod(), params),
|
||||
);
|
||||
};
|
||||
|
||||
export const useUserFindAuthMethodMutation = (options?: UseMutationOptions<UserFindAuthMethodResponse, CBDCAxiosError, UserFindAuthMethodParams>) => {
|
||||
const mutation = useMutation<UserFindAuthMethodResponse, CBDCAxiosError, UserFindAuthMethodParams>({
|
||||
...options,
|
||||
mutationFn: (params: UserFindAuthMethodParams) => userFindAuthMethod(params),
|
||||
});
|
||||
|
||||
return {
|
||||
...mutation,
|
||||
};
|
||||
};
|
||||
29
src/entities/user/api/use-user-find-mutation.ts
Normal file
29
src/entities/user/api/use-user-find-mutation.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import axios from 'axios';
|
||||
import { API_URL_USER } from '@/shared/api/api-url-user';
|
||||
import { resultify } from '@/shared/lib/resultify';
|
||||
import { CBDCAxiosError } from '@/shared/@types/error';
|
||||
import {
|
||||
UserFindParams,
|
||||
UserFindResponse
|
||||
} from '../model/types';
|
||||
import {
|
||||
useMutation,
|
||||
UseMutationOptions
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
export const userFind = (params: UserFindParams) => {
|
||||
return resultify(
|
||||
axios.post<UserFindResponse>(API_URL_USER.findUser(), params),
|
||||
);
|
||||
};
|
||||
|
||||
export const useUserFindMutation = (options?: UseMutationOptions<UserFindResponse, CBDCAxiosError, UserFindParams>) => {
|
||||
const mutation = useMutation<UserFindResponse, CBDCAxiosError, UserFindParams>({
|
||||
...options,
|
||||
mutationFn: (params: UserFindParams) => userFind(params),
|
||||
});
|
||||
|
||||
return {
|
||||
...mutation,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user