Skip to content

Commit 930a193

Browse files
authored
Merge pull request #130 from part3-4team-Taskify/feature/Gnb
[Refactor] api 컨벤션 통일 / 배포 에러 fix 위해 teamId 하드코딩 제거
2 parents a071e4b + bd30d59 commit 930a193

File tree

24 files changed

+244
-285
lines changed

24 files changed

+244
-285
lines changed

src/api/apiRoutes.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
11
import { TEAM_ID } from "@/constants/team";
22

33
export const apiRoutes = {
4-
//로그인
5-
Login: () => `/${TEAM_ID}/auth/login`, //post
6-
//비밀번호변경
7-
Password: () => `/${TEAM_ID}/auth/password`, //put
8-
//카드
9-
Cards: () => `/${TEAM_ID}/cards`, //post,get
10-
CardDetail: (cardId: number) => `/${TEAM_ID}/cards/${cardId}`, //get,put,delete
11-
//컬럼
12-
Columns: () => `/${TEAM_ID}/columns`, //post,get
13-
ColumnDetail: (columnId: number) => `/${TEAM_ID}/columns/${columnId}`, //put,delete
14-
ColumnCardImage: (columnId: number) =>
4+
// 로그인
5+
login: () => `/${TEAM_ID}/auth/login`, //post
6+
7+
// 비밀번호 변경
8+
password: () => `/${TEAM_ID}/auth/password`, //put
9+
10+
// 카드
11+
cards: () => `/${TEAM_ID}/cards`, //post,get
12+
cardDetail: (cardId: number) => `/${TEAM_ID}/cards/${cardId}`, //get,put,delete
13+
14+
// 칼럼
15+
columns: () => `/${TEAM_ID}/columns`, //post,get
16+
columnDetail: (columnId: number) => `/${TEAM_ID}/columns/${columnId}`, //put,delete
17+
columnCardImage: (columnId: number) =>
1518
`/${TEAM_ID}/columns/${columnId}/card-image`, //post
16-
//댓글
17-
Comments: () => `/${TEAM_ID}/comments`, //post,get
18-
CommentsDetail: (commentId: number) => `/${TEAM_ID}/comments/${commentId}`, //put,delete
19-
//대시보드
20-
Dashboards: () => `/${TEAM_ID}/dashboards`, //post,get
21-
DashboardDetail: (dashboardId: number) =>
19+
20+
// 댓글
21+
comments: () => `/${TEAM_ID}/comments`, //post,get
22+
commentsDetail: (commentId: number) => `/${TEAM_ID}/comments/${commentId}`, //put,delete
23+
24+
// 대시보드
25+
dashboards: () => `/${TEAM_ID}/dashboards`, //post,get
26+
dashboardDetail: (dashboardId: number) =>
2227
`/${TEAM_ID}/dashboards/${dashboardId}`, //get,put,delete
23-
//대시보드 초대하기
24-
DashboardInvite: (dashboardId: number) =>
28+
29+
// 대시보드 초대하기
30+
dashboardInvite: (dashboardId: number) =>
2531
`/${TEAM_ID}/dashboards/${dashboardId}/invitations`, //post,get
26-
DashboardInviteDelete: (dashboardId: number, invitationId: number) =>
32+
dashboardInviteDelete: (dashboardId: number, invitationId: number) =>
2733
`/${TEAM_ID}/dashboards/${dashboardId}/invitations/${invitationId}`, //delete
28-
//초대 받은 대시보드
29-
Invitations: () => `/${TEAM_ID}/invitations`, //get
34+
35+
// 초대받은 대시보드
36+
invitations: () => `/${TEAM_ID}/invitations`, //get
3037
invitationDetail: (invitationId: number) =>
3138
`/${TEAM_ID}/invitations/${invitationId}`, //put
32-
// [Members]
39+
40+
// Members
3341
members: () => `/${TEAM_ID}/members`, //get
34-
memberDetail: (memberId: number) => `/${TEAM_ID}/members/${memberId}`, //put
42+
memberDetail: (memberId: number) => `/${TEAM_ID}/members/${memberId}`, //delete
3543

36-
// [Users]
44+
// Users
3745
users: () => `/${TEAM_ID}/users`, //post
38-
userMe: () => `/${TEAM_ID}/users/me`, //get,put
46+
usersMe: () => `/${TEAM_ID}/users/me`, //get,put
3947
userMeImage: () => `/${TEAM_ID}/users/me/image`, //post
4048
};

src/api/auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import axiosInstance from "./axiosInstance";
22
import { apiRoutes } from "./apiRoutes";
3-
import { UserResponse } from "./users";
3+
import { UserType } from "@/types/users";
44

5-
interface AuthResponse extends UserResponse {
5+
interface AuthResponse extends UserType {
66
accessToken: string;
77
}
88

@@ -13,7 +13,7 @@ export const postAuthData = async ({
1313
email: string;
1414
password: string;
1515
}) => {
16-
const response = await axiosInstance.post<AuthResponse>(apiRoutes.Login(), {
16+
const response = await axiosInstance.post<AuthResponse>(apiRoutes.login(), {
1717
email,
1818
password,
1919
});

src/api/card.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import { apiRoutes } from "@/api/apiRoutes";
44

55
/** 1. 카드 이미지 업로드 */
66
export const uploadCardImage = async ({
7-
teamId,
87
columnId,
98
imageFile,
109
}: {
11-
teamId: string;
1210
columnId: number;
1311
imageFile: File;
1412
}): Promise<string> => {
1513
const formData = new FormData();
1614
formData.append("image", imageFile);
1715

1816
const response = await axiosInstance.post(
19-
`/${teamId}/columns/${columnId}/card-image`,
17+
apiRoutes.columnCardImage(columnId),
2018
formData,
2119
{
2220
headers: {
@@ -30,7 +28,6 @@ export const uploadCardImage = async ({
3028

3129
/** 2. 카드 생성 */
3230
export const createCard = async ({
33-
teamId,
3431
assigneeUserId,
3532
dashboardId,
3633
columnId,
@@ -40,7 +37,6 @@ export const createCard = async ({
4037
tags,
4138
imageUrl,
4239
}: {
43-
teamId: string;
4440
assigneeUserId: number;
4541
dashboardId: number;
4642
columnId: number;
@@ -50,7 +46,7 @@ export const createCard = async ({
5046
tags: string[];
5147
imageUrl?: string;
5248
}) => {
53-
const response = await axiosInstance.post(`/${teamId}/cards`, {
49+
const response = await axiosInstance.post(apiRoutes.cards(), {
5450
assigneeUserId,
5551
dashboardId,
5652
columnId,
@@ -66,17 +62,15 @@ export const createCard = async ({
6662

6763
/** 3. 대시보드 멤버 조회 (담당자용) */
6864
export const getDashboardMembers = async ({
69-
teamId,
7065
dashboardId,
7166
page = 1,
7267
size = 20,
7368
}: {
74-
teamId: string;
7569
dashboardId: number;
7670
page?: number;
7771
size?: number;
7872
}) => {
79-
const res = await axiosInstance.get(`/${teamId}/members`, {
73+
const res = await axiosInstance.get(apiRoutes.members(), {
8074
params: {
8175
page,
8276
size,
@@ -89,7 +83,6 @@ export const getDashboardMembers = async ({
8983

9084
/** 4. 카드 수정 */
9185
export const updateCard = async ({
92-
teamId,
9386
cardId,
9487
columnId,
9588
assigneeUserId,
@@ -99,7 +92,6 @@ export const updateCard = async ({
9992
tags,
10093
imageUrl,
10194
}: {
102-
teamId: string;
10395
cardId: number;
10496
columnId: number;
10597
assigneeUserId: number;
@@ -109,7 +101,7 @@ export const updateCard = async ({
109101
tags: string[];
110102
imageUrl?: string;
111103
}) => {
112-
const response = await axiosInstance.put(`/${teamId}/cards/${cardId}`, {
104+
const response = await axiosInstance.put(apiRoutes.cardDetail(cardId), {
113105
columnId,
114106
assigneeUserId,
115107
title,
@@ -122,21 +114,43 @@ export const updateCard = async ({
122114
return response.data;
123115
};
124116

125-
//카드조회
117+
// 카드 목록 조회
118+
export const getCardsByColumn = async ({
119+
columnId,
120+
cursorId,
121+
size = 10,
122+
}: {
123+
columnId: number;
124+
cursorId?: number;
125+
size?: number;
126+
}) => {
127+
const res = await axiosInstance.get(apiRoutes.cards(), {
128+
params: {
129+
columnId,
130+
cursorId,
131+
size,
132+
},
133+
});
134+
135+
return res.data;
136+
};
137+
138+
// 카드 상세 조회
126139
export async function getCardDetail(cardId: number): Promise<CardType> {
127140
try {
128141
// apiRoutes를 사용하여 URL 동적 생성
129-
const url = apiRoutes.CardDetail(cardId);
142+
const url = apiRoutes.cardDetail(cardId);
130143
const response = await axiosInstance.get(url);
131144
return response.data as CardType;
132145
} catch (error) {
133146
console.error("대시보드 데이터를 불러오는 데 실패했습니다.", error);
134147
throw error;
135148
}
136149
}
137-
//카드 삭제 api
138-
export const deleteCard = async (teamId: string, cardId: number) => {
139-
const url = apiRoutes.CardDetail(cardId);
150+
151+
// 카드 삭제
152+
export const deleteCard = async (cardId: number) => {
153+
const url = apiRoutes.cardDetail(cardId);
140154
const response = await axiosInstance.delete(url);
141155
return response.data;
142156
};

src/api/changepassword.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios from "./axiosInstance";
22
import { apiRoutes } from "./apiRoutes";
33
import { isAxiosError } from "axios";
44

5+
// 비밀번호 변경
56
export const changePassword = async ({
67
password,
78
newPassword,
@@ -10,7 +11,7 @@ export const changePassword = async ({
1011
newPassword: string;
1112
}) => {
1213
try {
13-
const response = await axios.put(apiRoutes.Password(), {
14+
const response = await axios.put(apiRoutes.password(), {
1415
password,
1516
newPassword,
1617
});

src/api/columns.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { ColumnType } from "@/types/task";
2+
import axiosInstance from "./axiosInstance";
3+
import { apiRoutes } from "./apiRoutes";
4+
5+
// 칼럼 생성
6+
export const createColumn = async ({
7+
title,
8+
dashboardId,
9+
}: {
10+
title: string;
11+
dashboardId: number;
12+
}): Promise<ColumnType> => {
13+
const res = await axiosInstance.post(apiRoutes.columns(), {
14+
title,
15+
dashboardId,
16+
});
17+
18+
return res.data;
19+
};
20+
21+
// 칼럼 목록 조회
22+
export const getColumns = async ({ dashboardId }: { dashboardId: number }) => {
23+
const res = await axiosInstance.get(apiRoutes.columns(), {
24+
params: {
25+
dashboardId,
26+
},
27+
});
28+
29+
return res.data;
30+
};
31+
32+
// 칼럼 수정
33+
export const updateColumn = async ({
34+
columnId,
35+
title,
36+
}: {
37+
columnId: number;
38+
title: string;
39+
}) => {
40+
const res = await axiosInstance.put(apiRoutes.columnDetail(columnId), {
41+
title,
42+
});
43+
return res.data;
44+
};
45+
46+
// 칼럼 삭제
47+
export const deleteColumn = async ({ columnId }: { columnId: number }) => {
48+
const res = await axiosInstance.delete(apiRoutes.columnDetail(columnId));
49+
return res;
50+
};

src/api/comment.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ import {
55
UpdateCommenttype,
66
DeleteCommentParams,
77
} from "../types/comments";
8-
//댓글 생성
8+
9+
// 댓글 생성
910
export const createComment = async (data: CreateCommentType) => {
10-
const response = await axiosInstance.post(apiRoutes.Comments(), data);
11+
const response = await axiosInstance.post(apiRoutes.comments(), data);
1112
return response.data;
1213
};
13-
//댓글 목록
14+
15+
// 댓글 목록
1416
export async function getComments({
1517
cardId,
1618
pageParam,
1719
}: {
1820
cardId: number;
1921
pageParam: number;
2022
}) {
21-
const response = await axiosInstance.get(apiRoutes.Comments(), {
23+
const response = await axiosInstance.get(apiRoutes.comments(), {
2224
params: {
2325
cardId,
2426
page: pageParam,
@@ -31,21 +33,21 @@ export async function getComments({
3133
};
3234
}
3335

34-
//댓글 수정
36+
// 댓글 수정
3537
export const updateComment = async (
3638
commentId: number,
3739
data: UpdateCommenttype
3840
) => {
3941
const response = await axiosInstance.put(
40-
apiRoutes.CommentsDetail(commentId),
42+
apiRoutes.commentsDetail(commentId),
4143
data
4244
);
4345
return response.data;
4446
};
45-
//댓글 삭제
47+
// 댓글 삭제
4648
export const deleteComment = async ({ commentId }: DeleteCommentParams) => {
4749
const response = await axiosInstance.delete(
48-
apiRoutes.CommentsDetail(commentId)
50+
apiRoutes.commentsDetail(commentId)
4951
);
5052
return response.data;
5153
};

0 commit comments

Comments
 (0)