Skip to content

Commit

Permalink
feat: GET /shared/posts/dormitory/{postId} 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 5a5805d commit 9dd1431
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
50 changes: 49 additions & 1 deletion src/entities/shared-post/shared-post.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface SharedPost {
};
};
participants: Array<{ memberId: string; profileImage: string }>;
roomImages: Set<{
roomImages: Array<{
fileName: string;
isThumbnail: boolean;
order: number;
Expand Down Expand Up @@ -137,3 +137,51 @@ export interface DormitorySharedPostListItem {
modifiedAt: Date;
modifiedBy: string;
}

export interface DormitorySharedPost {
id: number;
title: string;
content: string;
roomMateFeatures: {
location: string;
features: {
smoking: string;
roomSharingOption: string;
mateAge: string;
options: string;
};
};
participants: Array<{
memberId: string;
profileImageFileName: string;
}>;
roomImages: Array<{
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;
scrapCount: number;
viewCount: number;
createdAt: Date;
createdBy: string;
modifiedAt: Date;
modifiedBy: string;
}
16 changes: 13 additions & 3 deletions src/features/shared/shared.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import axios from 'axios';

import { type GetSharedPostDTO, type GetSharedPostsDTO } from './shared.dto';
import {
type GetDormitorySharedPostDTO,
type GetDormitorySharedPostsDTO,
type GetSharedPostDTO,
type GetSharedPostsDTO,
} from './shared.dto';
import {
type CreateSharedPostProps,
type GetSharedPostsFilter,
Expand Down Expand Up @@ -119,7 +124,7 @@ export const getDormitorySharedPosts = async ({
page,
}: GetSharedPostsProps) => {
const getURI = () => {
const baseURL = '/maru-api/shared/posts/studio';
const baseURL = '/maru-api/shared/posts/dormitory';
let query = '';

if (filter != null) {
Expand All @@ -135,5 +140,10 @@ export const getDormitorySharedPosts = async ({
return `${baseURL}?${encodeURI(query)}`;
};

return await axios.get<GetSharedPostsDTO>(getURI());
return await axios.get<GetDormitorySharedPostsDTO>(getURI());
};

export const getDormitorySharedPost = async (postId: number) =>
await axios.get<GetDormitorySharedPostDTO>(
`/maru-api/shared/posts/dormitory/${postId}`,
);
5 changes: 5 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 DormitorySharedPost,
type DormitorySharedPostListItem,
type SharedPost,
type SharedPostListItem,
Expand Down Expand Up @@ -70,3 +71,7 @@ export interface GetDormitorySharedPostsDTO extends SuccessBaseDTO {
empty: boolean;
};
}

export interface GetDormitorySharedPostDTO extends SuccessBaseDTO {
data: DormitorySharedPost;
}
17 changes: 16 additions & 1 deletion 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,
getDormitorySharedPost,
getDormitorySharedPosts,
getSharedPost,
getSharedPosts,
Expand Down Expand Up @@ -395,11 +396,25 @@ export const useDormitorySharedPosts = ({
enabled,
}: GetSharedPostsProps & { enabled: boolean }) =>
useQuery({
queryKey: ['/api/shared/posts/studio', { filter, search, page }],
queryKey: ['/api/shared/posts/dormitory', { filter, search, page }],
queryFn: async () =>
await getDormitorySharedPosts({ filter, search, page }).then(
response => response.data,
),
staleTime: 60000,
enabled,
});

export const useDormitorySharedPost = ({
postId,
enabled,
}: {
postId: number;
enabled: boolean;
}) =>
useQuery({
queryKey: [`/api/shared/posts/dormitory/${postId}`],
queryFn: async () =>
await getDormitorySharedPost(postId).then(response => response.data),
enabled,
});

0 comments on commit 9dd1431

Please sign in to comment.