Skip to content

Commit c52f941

Browse files
committed
feat: POST /shared/posts/dormitory API (kookmin-sw#75)
1 parent b6e4299 commit c52f941

File tree

6 files changed

+143
-109
lines changed

6 files changed

+143
-109
lines changed

src/app/pages/writing-post-page.tsx

Lines changed: 108 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { useAuthValue } from '@/features/auth';
2424
import { getImageURL, putImage } from '@/features/image';
2525
import {
26+
useCreateDormitorySharedPost,
2627
useCreateSharedPost,
2728
usePostMateCardInputSection,
2829
useSharedPostProps,
@@ -458,6 +459,7 @@ export function WritingPostPage() {
458459

459460
const { mutate: createSharedPost } = useCreateSharedPost();
460461
const { mutate: updateSharedPost } = useUpdateSharedPost();
462+
const { mutate: createDormitorySharedPost } = useCreateDormitorySharedPost();
461463

462464
const { createToast } = useToast();
463465

@@ -610,72 +612,10 @@ export function WritingPostPage() {
610612
});
611613
}, []);
612614

613-
if (postId == null) {
614-
createSharedPost(
615-
{
616-
imageFilesData: uploadedImages,
617-
postData: { title, content },
618-
transactionData: {
619-
rentalType: dealTypeValue,
620-
expectedPayment: expectedMonthlyFee,
621-
},
622-
roomDetailData: {
623-
roomType: roomTypeValue,
624-
floorType: floorTypeValue,
625-
size: houseSize,
626-
numberOfRoom,
627-
numberOfBathRoom,
628-
hasLivingRoom: selectedOptions.livingRoom === '유',
629-
recruitmentCapacity: mateLimit,
630-
extraOption: {
631-
canPark: selectedExtraOptions.canPark ?? false,
632-
hasAirConditioner:
633-
selectedExtraOptions.hasAirConditioner ?? false,
634-
hasRefrigerator:
635-
selectedExtraOptions.hasRefrigerator ?? false,
636-
hasWasher: selectedExtraOptions.hasWasher ?? false,
637-
hasTerrace: selectedExtraOptions.hasTerrace ?? false,
638-
},
639-
},
640-
locationData: {
641-
oldAddress: address?.jibunAddress,
642-
roadAddress: address?.roadAddress,
643-
},
644-
roomMateCardData: {
645-
location: address?.roadAddress,
646-
features: derivedFeatures,
647-
},
648-
participationData: {
649-
recruitmentCapacity: mateLimit,
650-
participationMemberIds:
651-
auth?.user != null ? [auth.user.memberId] : [],
652-
},
653-
},
654-
{
655-
onSuccess: () => {
656-
createToast({
657-
message: '게시글이 정상적으로 업로드되었습니다.',
658-
option: {
659-
duration: 3000,
660-
},
661-
});
662-
router.back();
663-
},
664-
onError: () => {
665-
createToast({
666-
message: '게시글 업로드에 실패했습니다.',
667-
option: {
668-
duration: 3000,
669-
},
670-
});
671-
},
672-
},
673-
);
674-
} else if (postId != null) {
675-
updateSharedPost(
676-
{
677-
postId,
678-
postData: {
615+
if (type === 'hasRoom') {
616+
if (postId == null) {
617+
createSharedPost(
618+
{
679619
imageFilesData: uploadedImages,
680620
postData: { title, content },
681621
transactionData: {
@@ -714,27 +654,111 @@ export function WritingPostPage() {
714654
auth?.user != null ? [auth.user.memberId] : [],
715655
},
716656
},
717-
},
718-
{
719-
onSuccess: () => {
720-
createToast({
721-
message: '게시글이 정상적으로 수정되었습니다.',
722-
option: {
723-
duration: 3000,
724-
},
725-
});
726-
router.back();
657+
{
658+
onSuccess: () => {
659+
createToast({
660+
message: '게시글이 정상적으로 업로드되었습니다.',
661+
option: {
662+
duration: 3000,
663+
},
664+
});
665+
router.back();
666+
},
667+
onError: () => {
668+
createToast({
669+
message: '게시글 업로드에 실패했습니다.',
670+
option: {
671+
duration: 3000,
672+
},
673+
});
674+
},
727675
},
728-
onError: () => {
729-
createToast({
730-
message: '게시글 수정에 실패했습니다.',
731-
option: {
732-
duration: 3000,
676+
);
677+
} else if (postId != null) {
678+
updateSharedPost(
679+
{
680+
postId,
681+
postData: {
682+
imageFilesData: uploadedImages,
683+
postData: { title, content },
684+
transactionData: {
685+
rentalType: dealTypeValue,
686+
expectedPayment: expectedMonthlyFee,
733687
},
734-
});
688+
roomDetailData: {
689+
roomType: roomTypeValue,
690+
floorType: floorTypeValue,
691+
size: houseSize,
692+
numberOfRoom,
693+
numberOfBathRoom,
694+
hasLivingRoom: selectedOptions.livingRoom === '유',
695+
recruitmentCapacity: mateLimit,
696+
extraOption: {
697+
canPark: selectedExtraOptions.canPark ?? false,
698+
hasAirConditioner:
699+
selectedExtraOptions.hasAirConditioner ?? false,
700+
hasRefrigerator:
701+
selectedExtraOptions.hasRefrigerator ?? false,
702+
hasWasher: selectedExtraOptions.hasWasher ?? false,
703+
hasTerrace: selectedExtraOptions.hasTerrace ?? false,
704+
},
705+
},
706+
locationData: {
707+
oldAddress: address?.jibunAddress,
708+
roadAddress: address?.roadAddress,
709+
},
710+
roomMateCardData: {
711+
location: address?.roadAddress,
712+
features: derivedFeatures,
713+
},
714+
participationData: {
715+
recruitmentCapacity: mateLimit,
716+
participationMemberIds:
717+
auth?.user != null ? [auth.user.memberId] : [],
718+
},
719+
},
735720
},
736-
},
737-
);
721+
{
722+
onSuccess: () => {
723+
createToast({
724+
message: '게시글이 정상적으로 수정되었습니다.',
725+
option: {
726+
duration: 3000,
727+
},
728+
});
729+
router.back();
730+
},
731+
onError: () => {
732+
createToast({
733+
message: '게시글 수정에 실패했습니다.',
734+
option: {
735+
duration: 3000,
736+
},
737+
});
738+
},
739+
},
740+
);
741+
}
742+
} else if (type === 'dormitory') {
743+
if (postId == null) {
744+
createDormitorySharedPost({
745+
imageFilesData: uploadedImages,
746+
postData: { title, content },
747+
locationData: {
748+
oldAddress: address?.jibunAddress,
749+
roadAddress: address?.roadAddress,
750+
},
751+
roomMateCardData: {
752+
location: address?.roadAddress,
753+
features: derivedFeatures,
754+
},
755+
participationData: {
756+
recruitmentCapacity: mateLimit,
757+
participationMemberIds:
758+
auth?.user != null ? [auth.user.memberId] : [],
759+
},
760+
});
761+
}
738762
}
739763
} catch (error) {
740764
createToast({

src/components/shared-posts/PostCard.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import styled from 'styled-components';
44

5-
import { HorizontalDivider } from '..';
6-
5+
import { HorizontalDivider } from '@/components';
76
import {
87
type DormitorySharedPostListItem,
98
type SharedPostListItem,

src/components/shared-posts/SharedPostsMenu.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import styled from 'styled-components';
44

55
import { type SharedPostsType } from '@/entities/shared-posts-filter';
6-
import { useAuthValue } from '@/features/auth';
76

87
const styles = {
98
container: styled.div`
@@ -56,7 +55,7 @@ export function SharedPostsMenu({
5655
handleSelect,
5756
className,
5857
}: Props & React.ComponentProps<'div'>) {
59-
const auth = useAuthValue();
58+
// const auth = useAuthValue();
6059

6160
return (
6261
<styles.container className={className}>
@@ -76,16 +75,16 @@ export function SharedPostsMenu({
7675
>
7776
방 없는 메이트
7877
</styles.item>
79-
{auth?.user?.univCertified === true ?? (
80-
<styles.item
81-
onClick={() => {
82-
handleSelect('dormitory');
83-
}}
84-
className={selected === 'dormitory' ? 'selected' : ''}
85-
>
86-
기숙사 메이트
87-
</styles.item>
88-
)}
78+
{/* {auth?.user?.univCertified === true ?? (
79+
)} */}
80+
<styles.item
81+
onClick={() => {
82+
handleSelect('dormitory');
83+
}}
84+
className={selected === 'dormitory' ? 'selected' : ''}
85+
>
86+
기숙사 메이트
87+
</styles.item>
8988
</styles.container>
9089
);
9190
}

src/features/shared/shared.api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ export const getDormitorySharedPosts = async ({
8282
return await axios.get<GetDormitorySharedPostsDTO>(getURI());
8383
};
8484

85+
export const createDormitorySharedPost = async (postData: SharedPostProps) =>
86+
await axios.post<SuccessBaseDTO>(
87+
`/maru-api/shared/posts/dormitory`,
88+
postData,
89+
);
90+
8591
export const getDormitorySharedPost = async (postId: number) =>
8692
await axios.get<GetDormitorySharedPostDTO>(
8793
`/maru-api/shared/posts/dormitory/${postId}`,

src/features/shared/shared.hook.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
44
import { useRecoilState, useResetRecoilState } from 'recoil';
55

66
import {
7+
createDormitorySharedPost,
78
createSharedPost,
89
deleteDormitorySharedPost,
910
deleteSharedPost,
@@ -276,15 +277,6 @@ export const useCreateSharedPost = () =>
276277
mutationFn: createSharedPost,
277278
});
278279

279-
export const useUpdateSharedPost = () =>
280-
useMutation<
281-
AxiosResponse<SuccessBaseDTO>,
282-
FailureDTO,
283-
{ postId: number; postData: SharedPostProps }
284-
>({
285-
mutationFn: updateSharedPost,
286-
});
287-
288280
export const useSharedPosts = ({
289281
filter,
290282
search,
@@ -318,6 +310,15 @@ export const useSharedPost = ({
318310
enabled,
319311
});
320312

313+
export const useUpdateSharedPost = () =>
314+
useMutation<
315+
AxiosResponse<SuccessBaseDTO>,
316+
FailureDTO,
317+
{ postId: number; postData: SharedPostProps }
318+
>({
319+
mutationFn: updateSharedPost,
320+
});
321+
321322
export const useDeleteSharedPost = () =>
322323
useMutation<AxiosResponse<SuccessBaseDTO>, FailureDTO, number>({
323324
mutationFn: deleteSharedPost,
@@ -328,6 +329,11 @@ export const useScrapSharedPost = () =>
328329
mutationFn: scrapPost,
329330
});
330331

332+
export const useCreateDormitorySharedPost = () =>
333+
useMutation<AxiosResponse<SuccessBaseDTO>, FailureDTO, SharedPostProps>({
334+
mutationFn: createDormitorySharedPost,
335+
});
336+
331337
export const useDormitorySharedPosts = ({
332338
filter,
333339
search,

src/features/shared/shared.type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export interface SharedPostProps {
5454
title: string;
5555
content: string;
5656
};
57-
transactionData: {
57+
transactionData?: {
5858
rentalType: number;
5959
expectedPayment: number;
6060
};
61-
roomDetailData: {
61+
roomDetailData?: {
6262
roomType: number;
6363
floorType: number;
6464
size: number;

0 commit comments

Comments
 (0)