-
Notifications
You must be signed in to change notification settings - Fork 1
무한 스크롤 기능 구현 및 공용 UI, 유틸, API 관련 파일 추가 #22
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
Changes from 1 commit
3abaf80
df42eae
2f82de3
1eae942
ac7905b
8ca94b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { httpClient } from '@/shared/api/http-client'; | ||
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. FSD에서는 index.ts를 통해서만 외부로 공개하는 걸 원칙으로 두고 있는데 세그먼트에서 코드를 직접적으로 가져오는 것은 캡슐화 원칙을 깨는 것 아닐까 하는 생각이 듭니다. Shared에서는 segment 하나당 별도의 공개 API를 적용하는게 추천된다고 하네요. 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. 우선은 팀원인 선오님과 배럴 파일을 따로 생성할지 말지 논의하다가 |
||
import { CreatePostDTO, Post, UpdatePostDTO } from '@/shared/types/post-types'; | ||
|
||
// 게시글 생성 (POST /posts) | ||
export const createPost = async (postData: CreatePostDTO): Promise<Post> => { | ||
return httpClient<Post>('/posts', { | ||
method: 'POST', | ||
body: JSON.stringify(postData), | ||
}); | ||
}; | ||
|
||
// 모든 게시글 조회 (GET /posts) | ||
export const getPosts = async (): Promise<Post[]> => { | ||
return httpClient<Post[]>('/posts'); | ||
}; | ||
|
||
// 특정 게시글 조회 (GET /posts/{id}) | ||
export const getPostById = async (postId: string): Promise<Post> => { | ||
return httpClient<Post>(`/posts/${postId}`); | ||
}; | ||
|
||
// 게시글 수정 (PUT /posts/{id}) | ||
export const updatePost = async ( | ||
postId: string, | ||
updatedData: UpdatePostDTO | ||
): Promise<Post> => { | ||
return httpClient<Post>(`/posts/${postId}`, { | ||
method: 'PUT', | ||
body: JSON.stringify(updatedData), | ||
}); | ||
}; | ||
|
||
// 게시글 삭제 (DELETE /posts/{id}) | ||
export const deletePost = async ( | ||
postId: string | ||
): Promise<{ message: string }> => { | ||
return httpClient<{ message: string }>(`/posts/${postId}`, { | ||
method: 'DELETE', | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const BASE_URL = 'http://localhost:4000/api'; | ||
|
||
export const httpClient = async <T>( | ||
endpoint: string, | ||
options?: RequestInit | ||
): Promise<T> => { | ||
const response = await fetch(`${BASE_URL}${endpoint}`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
...options, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`API 요청 실패: ${response.status}`); | ||
} | ||
|
||
return response.json(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export interface Post { | ||
id: string; | ||
title: string; | ||
content: string; | ||
author: string; | ||
createdAt: string; | ||
updatedAt?: string; | ||
} | ||
|
||
export type CreatePostDTO = Pick<Post, 'title' | 'content' | 'author'>; | ||
export type UpdatePostDTO = Partial<CreatePostDTO>; | ||
|
||
interface CursorPaginationResponse<T> { | ||
data: T[]; | ||
nextCursor: string | null; | ||
hasMore: boolean; | ||
} | ||
interface OffsetPaginationResponse<T> { | ||
data: T[]; | ||
currentPage: number; | ||
totalPages: number; | ||
hasMore: boolean; | ||
} | ||
Comment on lines
+13
to
+23
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.
혹시 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. 현재는 게시글 기능을 기준으로 작성했습니다. |
||
|
||
export type GetPostsCursor = CursorPaginationResponse<Post>; | ||
export type GetPostsOffset = OffsetPaginationResponse<Post>; |
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.
entities 슬라이스에, model 세그먼트에 아래코드를 작성하셨는지 이유가 있을까요?
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.
@dgd03146 님 리뷰 감사합니다!😊
@rmkim7 님과 논의하여 해당 파일을 배치하였는데 처음에는 해당 코드를 단순하게 데이터를 다루는 요소의 일부라는 저의 생각 하에 model에 배치했던 것 같습니다.
리뷰를 통해 다시 논의해본 결과, API는 데이터를 가져오는 역할이고, 모델은 데이터를 가공하고 사용하는 역할이라고 의견을 모았습니다. 예를 들어,
PostViewModel
같은 파일을 만든다면model
폴더에 두겠지만, API는api
폴더에 있는 게 더 명확해 보일 거란 의견을 주고 받았습니다.따라서 데이터 소스 역할을 하는 해당 파일은
entities/post/api/
에 두고, 파일명 또한post-api.ts
로 변경할 예정입니다. 이 부분은 빠른 시일 내에 업데이트하도록 하겠습니다.좋은 관점 제공해주셔서 감사합니다!🙂