Skip to content

Commit ebd0504

Browse files
committed
refactor: 계산에도 파라미터
1 parent 8b93508 commit ebd0504

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/entities/post/api/posts.api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ export const postApi = {
1717
remove(id: number): Promise<void> {
1818
return http.delete<void>(`/posts/${id}`);
1919
},
20-
async getByTag(tag: string, params?: Pick<PostsParams, "sortBy" | "order">): Promise<PostsResponse> {
20+
async getByTag(
21+
tag: string,
22+
params?: Pick<PostsParams, "limit" | "skip" | "sortBy" | "order">,
23+
): Promise<PostsResponse> {
2124
return http.get<PostsResponse>(`/posts/tag/${tag}`, { params });
2225
},
23-
async search(query: string, params?: Pick<PostsParams, "sortBy" | "order">): Promise<PostsResponse> {
26+
async search(
27+
query: string,
28+
params?: Pick<PostsParams, "limit" | "skip" | "sortBy" | "order">,
29+
): Promise<PostsResponse> {
2430
return http.get<PostsResponse>(`/posts/search`, { params: { q: query, ...params } });
2531
},
2632
async getTags(): Promise<Tag[]> {

src/features/post-load/api/post-load.api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export const postLoadApi = {
1111
}));
1212
return { posts: postsWithUsers, total };
1313
},
14-
async getByTagWithAuthors(tag: string, params?: Pick<PostsParams, "sortBy" | "order">): Promise<PostsResponse> {
14+
async getByTagWithAuthors(
15+
tag: string,
16+
params?: Pick<PostsParams, "limit" | "skip" | "sortBy" | "order">,
17+
): Promise<PostsResponse> {
1518
const [{ posts, total }, users] = await Promise.all([postApi.getByTag(tag, params), userApi.getProfile()]);
1619
const postsWithUsers = posts.map((post) => ({
1720
...post,

src/features/post-load/model/post-load.query.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export const postsListQuery = (params: PostsParams) => ({
1111
queryFn: (): Promise<PostsResponse> => postLoadApi.getWithAuthors(params),
1212
});
1313

14-
export const postsByTagQuery = (tag: string, params?: Pick<PostsParams, "sortBy" | "order">) => ({
14+
export const postsByTagQuery = (tag: string, params?: Pick<PostsParams, "limit" | "skip" | "sortBy" | "order">) => ({
1515
queryKey: postsQueryKeys.byTag(tag),
1616
queryFn: (): Promise<PostsResponse> => postLoadApi.getByTagWithAuthors(tag, params),
1717
});
1818

19-
export const postsSearchQuery = (query: string, params?: Pick<PostsParams, "sortBy" | "order">) => ({
19+
export const postsSearchQuery = (query: string, params?: Pick<PostsParams, "limit" | "skip" | "sortBy" | "order">) => ({
2020
queryKey: postsQueryKeys.search(query),
2121
queryFn: (): Promise<PostsResponse> => postApi.search(query, params),
2222
});
@@ -34,8 +34,8 @@ export const buildPostsQuery = (params: BuildPostsQueryParams) => {
3434
const search = params.search?.trim();
3535
const normalizedSortBy = params.sortBy && params.sortBy !== "none" ? params.sortBy : undefined;
3636
const sortParams = normalizedSortBy ? { sortBy: normalizedSortBy, order: params.sortOrder } : undefined;
37-
if (search) return postsSearchQuery(search, sortParams);
38-
if (params.tag) return postsByTagQuery(params.tag, sortParams);
37+
if (search) return postsSearchQuery(search, { ...sortParams, limit: params.limit, skip: params.skip });
38+
if (params.tag) return postsByTagQuery(params.tag, { ...sortParams, limit: params.limit, skip: params.skip });
3939
if (typeof params.limit === "number" && typeof params.skip === "number") {
4040
return postsListQuery({
4141
limit: params.limit,

0 commit comments

Comments
 (0)