Skip to content

Commit

Permalink
feat: GET /shared/posts/dormitory API (kookmin-sw#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin committed May 8, 2024
1 parent 7ac4bd6 commit 5a5805d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/entities/shared-post/shared-post.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,36 @@ export interface SharedPost {
modifiedAt: Date;
modifiedBy: string;
}

export interface DormitorySharedPostListItem {
id: number;
title: string;
content: string;
thumbnail: {
fileName: string;
isThumbNail: boolean;
order: number;
};
publisherAccount: {
memberId: string;
email: string;
nickname: string;
birthYear: string;
gender: string;
phoneNumber: string;
profileImageFileName: string;
createdAt: Date;
createdBy: string;
modifiedAt: Date;
modifiedBy: string;
};
address: {
oldAddress: string;
roadAddress: string;
};
isScrapped: boolean;
createdAt: Date;
createdBy: string;
modifiedAt: Date;
modifiedBy: string;
}
25 changes: 25 additions & 0 deletions src/features/shared/shared.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,28 @@ export const scrapPost = async (postId: number) =>
await axios.get<SuccessBaseDTO>(
`/maru-api/shared/posts/studio/${postId}/scrap`,
);

export const getDormitorySharedPosts = async ({
filter,
search,
page,
}: GetSharedPostsProps) => {
const getURI = () => {
const baseURL = '/maru-api/shared/posts/studio';
let query = '';

if (filter != null) {
query += `filter=${JSON.stringify(filterConvertToValues(filter))}`;
}

if (search != null) {
query += `&search=${search}`;
}

query += `&page=${page}`;

return `${baseURL}?${encodeURI(query)}`;
};

return await axios.get<GetSharedPostsDTO>(getURI());
};
32 changes: 32 additions & 0 deletions src/features/shared/shared.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type DormitorySharedPostListItem,
type SharedPost,
type SharedPostListItem,
} from '@/entities/shared-post';
Expand Down Expand Up @@ -38,3 +39,34 @@ export interface GetSharedPostsDTO extends SuccessBaseDTO {
export interface GetSharedPostDTO extends SuccessBaseDTO {
data: SharedPost;
}

export interface GetDormitorySharedPostsDTO extends SuccessBaseDTO {
data: {
content: DormitorySharedPostListItem[];
pageable: {
pageNumber: number;
pageSize: number;
sort: {
empty: boolean;
unsorted: boolean;
sorted: boolean;
};
offset: number;
paged: boolean;
unpaged: boolean;
};
last: boolean;
totalPages: number;
totalElements: number;
first: boolean;
size: number;
number: number;
sort: {
empty: boolean;
unsorted: boolean;
sorted: boolean;
};
numberOfElements: number;
empty: boolean;
};
}
17 changes: 17 additions & 0 deletions src/features/shared/shared.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import {
createSharedPost,
deleteSharedPost,
getDormitorySharedPosts,
getSharedPost,
getSharedPosts,
scrapPost,
Expand Down Expand Up @@ -386,3 +387,19 @@ export const useScrapSharedPost = () =>
useMutation<AxiosResponse<SuccessBaseDTO>, FailureDTO, number>({
mutationFn: scrapPost,
});

export const useDormitorySharedPosts = ({
filter,
search,
page,
enabled,
}: GetSharedPostsProps & { enabled: boolean }) =>
useQuery({
queryKey: ['/api/shared/posts/studio', { filter, search, page }],
queryFn: async () =>
await getDormitorySharedPosts({ filter, search, page }).then(
response => response.data,
),
staleTime: 60000,
enabled,
});

0 comments on commit 5a5805d

Please sign in to comment.