Skip to content

Commit 9dd1431

Browse files
committed
feat: GET /shared/posts/dormitory/{postId} API (kookmin-sw#75)
1 parent 5a5805d commit 9dd1431

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

src/entities/shared-post/shared-post.type.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface SharedPost {
5555
};
5656
};
5757
participants: Array<{ memberId: string; profileImage: string }>;
58-
roomImages: Set<{
58+
roomImages: Array<{
5959
fileName: string;
6060
isThumbnail: boolean;
6161
order: number;
@@ -137,3 +137,51 @@ export interface DormitorySharedPostListItem {
137137
modifiedAt: Date;
138138
modifiedBy: string;
139139
}
140+
141+
export interface DormitorySharedPost {
142+
id: number;
143+
title: string;
144+
content: string;
145+
roomMateFeatures: {
146+
location: string;
147+
features: {
148+
smoking: string;
149+
roomSharingOption: string;
150+
mateAge: string;
151+
options: string;
152+
};
153+
};
154+
participants: Array<{
155+
memberId: string;
156+
profileImageFileName: string;
157+
}>;
158+
roomImages: Array<{
159+
fileName: string;
160+
isThumbNail: boolean;
161+
order: number;
162+
}>;
163+
publisherAccount: {
164+
memberId: string;
165+
email: string;
166+
nickname: string;
167+
birthYear: string;
168+
gender: string;
169+
phoneNumber: string;
170+
profileImageFileName: string;
171+
createdAt: Date;
172+
createdBy: string;
173+
modifiedAt: Date;
174+
modifiedBy: string;
175+
};
176+
address: {
177+
oldAddress: string;
178+
roadAddress: string;
179+
};
180+
isScrapped: boolean;
181+
scrapCount: number;
182+
viewCount: number;
183+
createdAt: Date;
184+
createdBy: string;
185+
modifiedAt: Date;
186+
modifiedBy: string;
187+
}

src/features/shared/shared.api.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import axios from 'axios';
22

3-
import { type GetSharedPostDTO, type GetSharedPostsDTO } from './shared.dto';
3+
import {
4+
type GetDormitorySharedPostDTO,
5+
type GetDormitorySharedPostsDTO,
6+
type GetSharedPostDTO,
7+
type GetSharedPostsDTO,
8+
} from './shared.dto';
49
import {
510
type CreateSharedPostProps,
611
type GetSharedPostsFilter,
@@ -119,7 +124,7 @@ export const getDormitorySharedPosts = async ({
119124
page,
120125
}: GetSharedPostsProps) => {
121126
const getURI = () => {
122-
const baseURL = '/maru-api/shared/posts/studio';
127+
const baseURL = '/maru-api/shared/posts/dormitory';
123128
let query = '';
124129

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

138-
return await axios.get<GetSharedPostsDTO>(getURI());
143+
return await axios.get<GetDormitorySharedPostsDTO>(getURI());
139144
};
145+
146+
export const getDormitorySharedPost = async (postId: number) =>
147+
await axios.get<GetDormitorySharedPostDTO>(
148+
`/maru-api/shared/posts/dormitory/${postId}`,
149+
);

src/features/shared/shared.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type DormitorySharedPost,
23
type DormitorySharedPostListItem,
34
type SharedPost,
45
type SharedPostListItem,
@@ -70,3 +71,7 @@ export interface GetDormitorySharedPostsDTO extends SuccessBaseDTO {
7071
empty: boolean;
7172
};
7273
}
74+
75+
export interface GetDormitorySharedPostDTO extends SuccessBaseDTO {
76+
data: DormitorySharedPost;
77+
}

src/features/shared/shared.hook.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
55
import {
66
createSharedPost,
77
deleteSharedPost,
8+
getDormitorySharedPost,
89
getDormitorySharedPosts,
910
getSharedPost,
1011
getSharedPosts,
@@ -395,11 +396,25 @@ export const useDormitorySharedPosts = ({
395396
enabled,
396397
}: GetSharedPostsProps & { enabled: boolean }) =>
397398
useQuery({
398-
queryKey: ['/api/shared/posts/studio', { filter, search, page }],
399+
queryKey: ['/api/shared/posts/dormitory', { filter, search, page }],
399400
queryFn: async () =>
400401
await getDormitorySharedPosts({ filter, search, page }).then(
401402
response => response.data,
402403
),
403404
staleTime: 60000,
404405
enabled,
405406
});
407+
408+
export const useDormitorySharedPost = ({
409+
postId,
410+
enabled,
411+
}: {
412+
postId: number;
413+
enabled: boolean;
414+
}) =>
415+
useQuery({
416+
queryKey: [`/api/shared/posts/dormitory/${postId}`],
417+
queryFn: async () =>
418+
await getDormitorySharedPost(postId).then(response => response.data),
419+
enabled,
420+
});

0 commit comments

Comments
 (0)