Skip to content

Commit

Permalink
Fix: 참여 현황 관련 로직 및 API 기능 수정 (#17)
Browse files Browse the repository at this point in the history
- 참여 현황 업데이트 로직 오류 수정
- 참여 현황 데이터를 처리하는 API 기능 개선
- 서버 응답 데이터 구조에 맞춘 로직 변경
  • Loading branch information
sunglitter committed Nov 27, 2024
1 parent 510c27c commit 3448cf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/components/pages/community/PostDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ const PostDetailPage = () => {
window.confirm('참여를 확정하시겠습니까? 이후에는 수정이 불가능합니다.')
) {
try {
// await joinPost(postId!, currentUserId, quantity);
const updatedQuantity = post.currentQuantity + quantity;
// await joinPost(postId!, currentUserId, quantity, updatedQuantity);
alert('참여가 완료되었습니다.');
setPost((prev) => {
if (!prev) return prev;
return {
...prev,
currentQuantity: prev.currentQuantity + quantity,
currentQuantity: updatedQuantity,
participants: [
...prev.participants,
{ userId: currentUserId, quantity, isCancelled: false },
Expand All @@ -164,13 +165,14 @@ const PostDetailPage = () => {
window.confirm('취소 후 다시 참여할 수 없습니다. 정말 취소하시겠습니까?')
) {
try {
// await cancelJoinPost(postId!, currentUserId);
const updatedQuantity = post.currentQuantity - quantity;
// await cancelJoinPost(postId!, currentUserId, updatedQuantity);
alert('참여가 취소되었습니다.');
setPost((prev) => {
if (!prev) return prev;
return {
...prev,
currentQuantity: prev.currentQuantity - quantity,
currentQuantity: updatedQuantity,
participants: prev.participants.map((p) =>
p.userId === currentUserId ? { ...p, isCancelled: true } : p
),
Expand Down
8 changes: 6 additions & 2 deletions src/components/pages/community/api/postApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ export const deletePostById = async (postId: string): Promise<void> => {
export const joinPost = async (
postId: string,
userId: string,
quantity: number
quantity: number,
updatedQuantity: number
): Promise<void> => {
try {
await axiosInstance.put(`/api/posts/${postId}/join`, {
userId,
quantity,
currentQuantity: updatedQuantity,
isCancelled: false, // 참여 상태
});
} catch (error) {
Expand All @@ -141,11 +143,13 @@ export const joinPost = async (
// 공구 진행 취소하기 API
export const cancelJoinPost = async (
postId: string,
userId: string
userId: string,
updatedQuantity: number
): Promise<void> => {
try {
await axiosInstance.put(`/api/posts/${postId}/cancel`, {
userId,
currentQuantity: updatedQuantity,
isCancelled: true, // 취소 상태
});
} catch (error) {
Expand Down

0 comments on commit 3448cf1

Please sign in to comment.