Skip to content

Commit

Permalink
Feat: api함수들 타입 수정, 타입 export
Browse files Browse the repository at this point in the history
리스폰스 타입들이 잘못 작성되어서 수정하였습니다.
선언한 타입들을 재사용 가능하도록 export시켰습니다. module에서 같이 import 할 수 있습니다.
  • Loading branch information
foxholic9 committed Jun 10, 2024
1 parent 07e1f2b commit 667c52d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 104 deletions.
42 changes: 14 additions & 28 deletions src/api/authorization/apiAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,41 @@
import instance from '../axiosInstance';
import { handleResponse } from '../errorHandler';

interface LoginBody {
export interface LoginBody {
email: string;
password: string;
}

interface ChangePasswordBody {
export interface ChangePasswordBody {
password: string;
newPassword: string;
}

interface LoginResponse {
status: number;
message?: string;
data: {
user: {
id: number;
email: string;
nickname: string;
profileImageUrl?: string;
createdAt: string;
updatedAt: string;
};
accessToken: string;
export interface LoginResponse {
user: {
id: number;
email: string;
nickname: string;
profileImageUrl?: string;
createdAt: string;
updatedAt: string;
};
}

interface ChangePasswordResponse {
status: number;
message?: string;
accessToken: string;
}

// 로그인 요청 api
export async function apiLoginRequest(body: LoginBody): Promise<LoginResponse> {
const res = await instance.post<LoginResponse>('/auth/login', body);
const responseData = await handleResponse(res);
const token = responseData.data.accessToken;
const token = responseData.accessToken;
if (token) {
localStorage.setItem('Token', token);
}
return responseData;
}

// 비밀번호 변경 요청 api
export async function apiChangePassword(
body: ChangePasswordBody,
): Promise<string | ChangePasswordResponse> {
const res = await instance.put<ChangePasswordResponse>(
'/auth/password',
body,
);
export async function apiChangePassword(body: ChangePasswordBody) {
const res = await instance.put('/auth/password', body);
return handleResponse(res);
}
46 changes: 15 additions & 31 deletions src/api/cards/apiCards.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import instance from '../axiosInstance';
import { handleResponse } from '../errorHandler';

interface CreateCardBody {
export interface CreateCardBody {
assigneeUserId: number;
dashboardId: number;
columnId: number;
Expand All @@ -12,7 +12,7 @@ interface CreateCardBody {
imageUrl?: string;
}

interface UpdateCardBody {
export interface UpdateCardBody {
columnId: number;
assigneeUserId: number;
title: string;
Expand All @@ -22,7 +22,7 @@ interface UpdateCardBody {
imageUrl?: string;
}

interface CardOverAll {
export interface CardOverAll {
id: number;
title: string;
description: string;
Expand All @@ -34,38 +34,24 @@ interface CardOverAll {
id: number;
};
imageUrl?: string;
teamId: string;
columnId: number;
createdAt: string;
updatedAt: string;
}

interface CardOverAllResponse {
status: number;
data: CardOverAll;
}

interface GetCardListResponse {
status: number;
data: {
cursorId: number;
totalCount: number;
cards: CardOverAll[];
};
}

interface DeleteCardResponse {
status: number;
message?: string;
export interface GetCardListResponse {
cursorId: number;
totalCount: number;
cards: CardOverAll[];
}

// 여기부터 api 함수 선언부분입니다. **************************

// 카드 생성 api
export async function apiCreateCard(
body: CreateCardBody,
): Promise<CardOverAllResponse> {
const res = await instance.post<CardOverAllResponse>('/cards', body);
): Promise<CardOverAll> {
const res = await instance.post<CardOverAll>('/cards', body);
return handleResponse(res);
}

Expand All @@ -91,23 +77,21 @@ export async function apiGetCardList(
export async function apiUpdateCard(
body: UpdateCardBody,
cardId: number,
): Promise<CardOverAllResponse> {
const res = await instance.put<CardOverAllResponse>(`/cards/${cardId}`, body);
): Promise<CardOverAll> {
const res = await instance.put<CardOverAll>(`/cards/${cardId}`, body);
return handleResponse(res);
}

// 카드 조회 api
// cardId를 파라미터로 받습니다.
export async function apiCardDetails(cardId: number): Promise<CardOverAllResponse> {
const res = await instance.get<CardOverAllResponse>(`/cards/${cardId}`);
export async function apiCardDetails(cardId: number): Promise<CardOverAll> {
const res = await instance.get<CardOverAll>(`/cards/${cardId}`);
return handleResponse(res);
}

// 카드 삭제 api
// cardId를 파라미터로 받습니다.
export async function apiDeleteCard(
cardId: number,
): Promise<DeleteCardResponse> {
const res = await instance.delete<DeleteCardResponse>(`/cards/${cardId}`);
export async function apiDeleteCard(cardId: number) {
const res = await instance.delete(`/cards/${cardId}`);
return handleResponse(res);
}
11 changes: 2 additions & 9 deletions src/api/columns/apiColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ interface GetColumnResponse {
};
}

interface DeleteColumnResponse {
status: number;
message?: string;
}

interface UploadCardImageResponse {
status: number;
imageUrl: string;
Expand Down Expand Up @@ -84,10 +79,8 @@ export async function apiUpdateColumn(

// 컬럼 삭제
// columnId를 파라미터로 받습니다.
export async function apiDeleteColumn(
columnId: number,
): Promise<DeleteColumnResponse> {
const res = await instance.delete<DeleteColumnResponse>(`/cards/${columnId}`);
export async function apiDeleteColumn(columnId: number) {
const res = await instance.delete(`/cards/${columnId}`);
return handleResponse(res);
}

Expand Down
57 changes: 21 additions & 36 deletions src/api/comments/apiComments.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import instance from '../axiosInstance';
import { handleResponse } from '../errorHandler';

interface CommentOverAll {
id: number;
content: string;
createdAt: string;
updatedAt: string;
cardId: number;
author: {
profileImageUrl: string;
nickname: string;
id: number;
};
}

interface CreateCommentBody {
content: string;
cardId: number;
Expand All @@ -25,29 +12,31 @@ interface UpdateCommentBody {
content: string;
}

interface CommentOverAllResponse {
status: number;
data: CommentOverAll;
interface CommentOverAll {
id: number;
content: string;
createdAt: string;
updatedAt: string;
cardId: number;
author: {
profileImageUrl: string;
nickname: string;
id: number;
};
}

interface GetCommentResponse {
status: number;
interface GetCommentListResponse {
cursorId: number;
data?: CommentOverAll[];
}

interface DeleteCommentResponse {
status: number;
message?: string;
comments: CommentOverAll[];
}

// 여기부터 api 함수 선언부분입니다. **************************

// 댓글 생성 api
export async function apiCreateComments(
body: CreateCommentBody,
): Promise<CommentOverAllResponse> {
const res = await instance.post<CommentOverAllResponse>('/comments', body);
): Promise<CommentOverAll> {
const res = await instance.post<CommentOverAll>('/comments', body);
return handleResponse(res);
}

Expand All @@ -58,8 +47,8 @@ export async function apiGetCommentList(
cardId: number,
cursorId: number = 0,
size: number = 10,
): Promise<GetCommentResponse> {
const res = await instance.get<GetCommentResponse>('/comments', {
): Promise<GetCommentListResponse> {
const res = await instance.get<GetCommentListResponse>('/comments', {
params: {
size,
cursorId,
Expand All @@ -74,8 +63,8 @@ export async function apiGetCommentList(
export async function apiUpdateComment(
body: UpdateCommentBody,
commentId: number,
): Promise<CommentOverAllResponse> {
const res = await instance.put<CommentOverAllResponse>(
): Promise<CommentOverAll> {
const res = await instance.put<CommentOverAll>(
`/comments/${commentId}`,
body,
);
Expand All @@ -84,11 +73,7 @@ export async function apiUpdateComment(

// 댓글 삭제 api
// commentId를 파라미터로 받습니다.
export async function apiDeleteComment(
commentId: number,
): Promise<DeleteCommentResponse> {
const res = await instance.delete<DeleteCommentResponse>(
`/comments/${commentId}`,
);
export async function apiDeleteComment(commentId: number) {
const res = await instance.delete(`/comments/${commentId}`);
return handleResponse(res);
}

0 comments on commit 667c52d

Please sign in to comment.