Skip to content

Commit ca9bdaa

Browse files
committed
fix: api 명세서 기준으로 user api 수정
1 parent 102f083 commit ca9bdaa

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed
Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11
import { api } from '@/api/core';
2-
import { Follow, GetUserPayload, UpdateMePayload, User } from '@/types/service/user';
2+
import {
3+
FollowParams,
4+
GetUserParams,
5+
UpdateMePayload,
6+
UpdateMyImagePayload,
7+
UpdateMyNotiParams,
8+
User,
9+
} from '@/types/service/user';
310

411
export const userServiceRemote = () => ({
5-
// 1. 사용자 단건 조회
6-
getUser: async (payload: GetUserPayload) => api.get<User>(`/users/${payload.userId}`),
7-
812
// 2. 프로필 편집
9-
updateMe: async (payload: UpdateMePayload) => api.patch<User>('/users', payload),
13+
updateMe: async (payload: UpdateMePayload) => {
14+
return api.patch<User>('/users', payload);
15+
},
1016

11-
// 3. 회원탈퇴
12-
deleteMe: async () => api.delete<User>(`/users`),
13-
// 4. 사용자 프로필 이미지 변경
17+
// 3. 프로필 이미지 편집
18+
updateMyImage: async (payload: UpdateMyImagePayload) => {
19+
return api.patch<User>(`/users/profile-image`, payload);
20+
},
21+
22+
// 4. 알림 설정 변경
23+
updatMyNotification: async (payload: UpdateMyNotiParams) => {
24+
return api.patch<User>(`/users/notification/${payload.isNotificationEnabled}`);
25+
},
26+
27+
// 5. 사용자 단건 조회
28+
getUser: async (payload: GetUserParams) => {
29+
return api.get<User>(`/users/${payload.userId}`);
30+
},
1431

15-
// 5. 사용자 팔로우
16-
followUser: async (payload: Follow) => api.post<void>(`/follows`, payload),
32+
// 1. 사용자 팔로우
33+
followUser: async (payload: FollowParams) => {
34+
return api.post<void>(`/follows/${payload.followNickname}`);
35+
},
1736

1837
// 6. 사용자 언팔로우
19-
unfollowUser: async (payload: Follow) => api.delete<void>(`/follows/${payload.followeeId}`),
38+
unfollowUser: async (payload: FollowParams) => {
39+
return api.delete<void>(`/follows/${payload.followNickname}`);
40+
},
41+
42+
// 7. 회원탈퇴
43+
deleteMe: async () => api.delete<User>(`/users`),
44+
45+
// 8. 사용자 프로필 이미지 변경
2046
});

src/hooks/use-user/use-user-follow/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
22

33
import { API } from '@/api';
44
import { userKeys } from '@/lib/query-key/query-key-user';
5-
import { Follow } from '@/types/service/user';
5+
import { FollowParams } from '@/types/service/user';
66

7-
export const useFollowUser = (payload: Follow) => {
7+
export const useFollowUser = (payload: FollowParams) => {
88
const queryClient = useQueryClient();
99
const query = useMutation({
1010
mutationFn: () => API.userService.followUser(payload),
1111
onSuccess: (_data, _variables, _context) => {
12-
queryClient.invalidateQueries({ queryKey: userKeys.item(payload.followeeId) });
12+
// todo: GetUser는 ID로 호출, follow는 nickname으로 진행 => querykey 타입 불일치로 인한 전체 querykey 삭제 적용 (임시)
13+
queryClient.invalidateQueries({ queryKey: userKeys.all });
1314
console.log('요청 성공');
1415
},
1516
onError: () => {

src/hooks/use-user/use-user-get/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { useQuery } from '@tanstack/react-query';
22

33
import { API } from '@/api';
44
import { userKeys } from '@/lib/query-key/query-key-user';
5-
import { GetUserPayload } from '@/types/service/user';
5+
import { GetUserParams } from '@/types/service/user';
66

7-
export const useGetUser = ({ userId }: GetUserPayload) => {
7+
export const useGetUser = ({ userId }: GetUserParams) => {
88
const query = useQuery({
99
queryKey: userKeys.item(userId),
1010
queryFn: () => API.userService.getUser({ userId }),

src/hooks/use-user/use-user-unfollow/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
22

33
import { API } from '@/api';
44
import { userKeys } from '@/lib/query-key/query-key-user';
5-
import { Follow } from '@/types/service/user';
5+
import { FollowParams } from '@/types/service/user';
66

7-
export const useUnfollowUser = (payload: Follow) => {
7+
export const useUnfollowUser = (payload: FollowParams) => {
88
const queryClient = useQueryClient();
99
const query = useMutation({
1010
mutationFn: () => API.userService.unfollowUser(payload),
1111
onSuccess: (_data, _variables, _context) => {
12-
queryClient.invalidateQueries({ queryKey: userKeys.item(payload.followeeId) });
12+
queryClient.invalidateQueries({ queryKey: userKeys.all });
1313
console.log('요청 성공');
1414
},
1515
onError: () => {

src/types/service/user.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@ export interface User {
1414
isFollowing: boolean;
1515
}
1616

17-
export interface GetUserPayload {
17+
export interface GetUserParams {
1818
userId: number;
1919
}
2020

21-
export type GetUserResponse = User;
22-
2321
export interface UpdateMePayload {
2422
nickName?: string;
25-
profileImage?: string;
2623
mbti?: string;
2724
profileMessage?: string;
2825
}
2926

30-
export type UpdateMeResponse = GetUserResponse;
27+
export interface UpdateMyImagePayload {
28+
file: File;
29+
}
30+
31+
export interface UpdateMyNotiParams {
32+
isNotificationEnabled: boolean;
33+
}
3134

32-
export interface Follow {
33-
followeeId: number;
35+
export interface FollowParams {
36+
followNickname: string;
3437
}

0 commit comments

Comments
 (0)