-
Notifications
You must be signed in to change notification settings - Fork 25
[양재영] sprint9 #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "Next-\uC591\uC7AC\uC601-sprint9"
[양재영] sprint9 #143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| plugins: { | ||
| tailwindcss: {}, | ||
| autoprefixer: {}, | ||
| }, | ||
| } |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const BASE_URL = `${process.env.NEXT_PUBLIC_BASE_URL}/items`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const BASE_URL = `${process.env.NEXT_PUBLIC_BASE_URL}/items`; | |
| const BASE_URL = `${process.env.NEXT_PUBLIC_BASE_URL}`; |
위와 같이 사용해볼 수 있습니다 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swagger 문서를 보면 다음과 같이 스키마의 타입을 알 수 있습니다:
해당 타입으로 다음과 같은 타입을 정의해볼 수 있겠군요 !
interface Item {
id: number;
tenantId: string
name: string;
memo: string;
imageUrl: string;
isCompleted?: boolean;
}그리고 요청 타입과 응답 타입을 정의해볼 수 있습니다 !
interface PatchTodoRequest extends Partial<Omit<TodoItem, 'id'>> {}
interface PatchTodoResponse extends TodoItem {}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(이어서) 그리고 API 함수에 다음에 요청과 응답 타입을 정의해볼 수 있습니다 😉
| export async function patchData( | |
| itemId: number, | |
| updateData: Partial<{ name: string; isCompleted: boolean }> | |
| ) { | |
| try { | |
| const response = await fetch(`${BASE_URL}/${itemId}`, { | |
| method: "PATCH", | |
| headers: { | |
| "Content-Type": "application/json", | |
| }, | |
| body: JSON.stringify(updateData), | |
| }); | |
| if (!response.ok) { | |
| throw new Error("서버 요청 실패" + response.status); | |
| } | |
| const data = response.json(); | |
| return data; | |
| } catch (error) { | |
| console.log("에러 발생", error); | |
| } | |
| } | |
| export async function patchData( | |
| itemId: number, | |
| updateData: PatchTodoRequest | |
| ): Promise<ApiResponse<PatchTodoResponse>> { | |
| try { | |
| const response = await fetch(`${BASE_URL}/${itemId}`, { | |
| method: "PATCH", | |
| headers: { | |
| "Content-Type": "application/json", | |
| }, | |
| body: JSON.stringify(updateData), | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`서버 요청 실패: ${response.status}`); | |
| } | |
| const data: PatchTodoResponse = await response.json(); | |
| return { data }; | |
| } catch (error) { | |
| console.log("에러 발생", error); | |
| return { | |
| error: error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다" | |
| }; | |
| } | |
| } | |
이렇게 정의해두면 요청 타입과 응답 타입이 필요할 때 export 해볼 수 있으며 타입에 별칭이 있어 가독성도 향상될 수 있겠군요 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 파일은
index.tsx보다index.ts확장자가 더 낫겠군요 !해당 파일은 jsx 문법을 사용하고 있지 않기에
.ts로 변경하셔도 무방합니다 😉그럼 확장자만 봐도 JSX 파일인지 아닌지 구분할 수 있겠죠? 😆