From 88a77ae2d032805a885477dc12460fa9a0f3c450 Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:22:12 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[chore]=20#19=20member=20info=20404=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/harang/server/dto/type/ErrorMessage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/harang/server/dto/type/ErrorMessage.java b/src/main/java/org/harang/server/dto/type/ErrorMessage.java index a3b2f7a..61ad981 100644 --- a/src/main/java/org/harang/server/dto/type/ErrorMessage.java +++ b/src/main/java/org/harang/server/dto/type/ErrorMessage.java @@ -36,6 +36,7 @@ public enum ErrorMessage { MEMBER_NOT_FOUND("40402", HttpStatus.NOT_FOUND, "사용자가 존재하지 않습니다."), POST_NOT_FOUND("40403", HttpStatus.NOT_FOUND, "게시글이 존재하지 않습니다."), MATCHING_NOT_FOUND("40404", HttpStatus.NOT_FOUND, "매칭이 존재하지 않습니다."), + MEMBER_INFO_NOT_FOUND("40405", HttpStatus.NOT_FOUND, "사용자의 정보가 존재하지 않습니다."), // method not allowed - 409 From e421bc9dabb794167052a3e6327ecfacb7bd8301 Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:22:54 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[feat]=20#19=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=8C=80=EA=B8=B0=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MatchingController.java | 6 ++++++ .../harang/server/service/MatchingService.java | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/org/harang/server/controller/MatchingController.java b/src/main/java/org/harang/server/controller/MatchingController.java index 9f2edc3..687fd33 100644 --- a/src/main/java/org/harang/server/controller/MatchingController.java +++ b/src/main/java/org/harang/server/controller/MatchingController.java @@ -8,6 +8,7 @@ import org.harang.server.dto.request.MatchingRequest; import org.harang.server.dto.type.SuccessMessage; import org.harang.server.service.MatchingService; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -38,4 +39,9 @@ public ApiResponse finishMatching(final @NotNull @PathVariable("postId") Long matchingService.finishMatching(postId); return ApiResponse.success(SuccessMessage.OK); } + + @GetMapping("/{postId}/waitings") + public ApiResponse getWaitinglist(final @NotNull @PathVariable("postId") Long postId) { + return ApiResponse.success(matchingService.getWaitingList(postId)); + } } diff --git a/src/main/java/org/harang/server/service/MatchingService.java b/src/main/java/org/harang/server/service/MatchingService.java index 98b6779..5090e17 100644 --- a/src/main/java/org/harang/server/service/MatchingService.java +++ b/src/main/java/org/harang/server/service/MatchingService.java @@ -1,17 +1,22 @@ package org.harang.server.service; +import java.util.List; import lombok.RequiredArgsConstructor; import org.harang.server.domain.Matching; import org.harang.server.domain.Member; import org.harang.server.domain.Post; +import org.harang.server.domain.Waiting; import org.harang.server.domain.enums.Status; import org.harang.server.domain.enums.Type; import org.harang.server.dto.request.MatchingRequest; +import org.harang.server.dto.response.WaitingResponse; import org.harang.server.dto.type.ErrorMessage; import org.harang.server.exception.CustomException; import org.harang.server.repository.MatchingRepository; +import org.harang.server.repository.MemberInfoRepository; import org.harang.server.repository.MemberRepository; import org.harang.server.repository.PostRepository; +import org.harang.server.repository.WaitingRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,6 +26,8 @@ public class MatchingService { private final MatchingRepository matchingRepository; private final MemberRepository memberRepository; private final PostRepository postRepository; + private final WaitingRepository waitingRepository; + private final MemberInfoRepository memberInfoRepository; @Transactional public void createMatching(Long memberId, MatchingRequest matchingRequest) { @@ -76,4 +83,15 @@ public void finishMatching(Long postId) { postRepository.save(post); matchingRepository.save(matching); } + + public List getWaitingList(Long postId) { + List waitingList = waitingRepository.findAllByPostId(postId); + + List waitingListResponse = waitingList.stream() + .map(w -> WaitingResponse.builder() + .memberId(w.getMember().getId()) + .nickname(memberInfoRepository.findByMemberIdOrThrow(w.getMember().getId()).getNickname()) + .build()).toList(); + return waitingListResponse; + } } From ea3dfa944e282fc20650c8f241ea98ef31434dd6 Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:23:27 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[fix]=20#19=20=EB=8C=80=EA=B8=B0=EC=9E=90?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/harang/server/domain/Member.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/harang/server/domain/Member.java b/src/main/java/org/harang/server/domain/Member.java index 7935225..b80a087 100644 --- a/src/main/java/org/harang/server/domain/Member.java +++ b/src/main/java/org/harang/server/domain/Member.java @@ -28,6 +28,7 @@ public class Member { @Column(name = "age", nullable = false) private Long age; + /* Relation Parent Mapping */ @OneToMany(mappedBy = "member") private List matchingList = new ArrayList<>(); @@ -35,6 +36,9 @@ public class Member { @OneToMany(mappedBy = "member") private List postList = new ArrayList<>(); + @OneToMany(mappedBy = "member") + private List waitingList = new ArrayList<>(); + @Builder public Member(Type type, Gender gender, Long age) { this.type = type; From ba9ae8a938488ca0b88df8fb3abdff81b1f54a80 Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:23:51 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[fix]=20#19=20=EB=8C=80=EA=B8=B0=EC=9E=90?= =?UTF-8?q?=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/harang/server/domain/Post.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/harang/server/domain/Post.java b/src/main/java/org/harang/server/domain/Post.java index 6d749b9..381f609 100644 --- a/src/main/java/org/harang/server/domain/Post.java +++ b/src/main/java/org/harang/server/domain/Post.java @@ -61,6 +61,9 @@ public class Post { @OneToMany(mappedBy = "post") private List postCategoryList = new ArrayList<>(); + @OneToMany(mappedBy = "post") + private List waitingList = new ArrayList<>(); + @Builder public Post(Member member, LocalDateTime createdAt, String title, String content, String chatLink, Gender preferredGender, int preferredAge, LocalDate preferredStartAt, LocalDate preferredEndAt, Status status) { this.member = member; From 96a9cb6bc47e2e66a67ee318f2424945ad20e4ab Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:24:15 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[feat]=20#19=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/harang/server/domain/Waiting.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/org/harang/server/domain/Waiting.java diff --git a/src/main/java/org/harang/server/domain/Waiting.java b/src/main/java/org/harang/server/domain/Waiting.java new file mode 100644 index 0000000..f718143 --- /dev/null +++ b/src/main/java/org/harang/server/domain/Waiting.java @@ -0,0 +1,37 @@ +package org.harang.server.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Waiting { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id", nullable = false) + private Post post; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @Builder + public Waiting(Post post, Member member) { + this.post = post; + this.member = member; + } +} From 2804d8e2550a8c726aea954ba5dae5d06572208d Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:25:20 +0900 Subject: [PATCH 6/8] [feat] #19 member info, waiting repository --- .../server/repository/MemberInfoRepository.java | 17 +++++++++++++++++ .../server/repository/WaitingRepository.java | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/java/org/harang/server/repository/MemberInfoRepository.java create mode 100644 src/main/java/org/harang/server/repository/WaitingRepository.java diff --git a/src/main/java/org/harang/server/repository/MemberInfoRepository.java b/src/main/java/org/harang/server/repository/MemberInfoRepository.java new file mode 100644 index 0000000..d916c47 --- /dev/null +++ b/src/main/java/org/harang/server/repository/MemberInfoRepository.java @@ -0,0 +1,17 @@ +성package org.harang.server.repository; + +import java.util.Optional; +import org.harang.server.domain.MemberInfo; +import org.harang.server.dto.type.ErrorMessage; +import org.harang.server.exception.CustomException; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MemberInfoRepository extends JpaRepository { + default MemberInfo findByMemberIdOrThrow(Long memberId) { + return findByMemberId(memberId).orElseThrow(() -> new CustomException(ErrorMessage.MEMBER_INFO_NOT_FOUND)); + } + + Optional findByMemberId(Long memberId); +} diff --git a/src/main/java/org/harang/server/repository/WaitingRepository.java b/src/main/java/org/harang/server/repository/WaitingRepository.java new file mode 100644 index 0000000..36f55b2 --- /dev/null +++ b/src/main/java/org/harang/server/repository/WaitingRepository.java @@ -0,0 +1,12 @@ +package org.harang.server.repository; + +import java.util.List; +import org.harang.server.domain.Member; +import org.harang.server.domain.Waiting; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface WaitingRepository extends JpaRepository { + List findAllByPostId(Long postId); +} From 35a40d306ac7c0b564bdc4bffa800a23703dae71 Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:25:48 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[feat]=20#19=20=EB=8C=80=EA=B8=B0=EC=9E=90?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=ED=98=95=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/dto/response/WaitingResponse.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/org/harang/server/dto/response/WaitingResponse.java diff --git a/src/main/java/org/harang/server/dto/response/WaitingResponse.java b/src/main/java/org/harang/server/dto/response/WaitingResponse.java new file mode 100644 index 0000000..8503539 --- /dev/null +++ b/src/main/java/org/harang/server/dto/response/WaitingResponse.java @@ -0,0 +1,16 @@ +package org.harang.server.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class WaitingResponse { + private Long memberId; + private String nickname; + + @Builder + public WaitingResponse(Long memberId, String nickname) { + this.memberId = memberId; + this.nickname = nickname; + } +} From 3853de8d803a33c313b1ef277640610d0fa1031b Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Tue, 13 Feb 2024 15:27:22 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[fix]=20#19=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/harang/server/repository/MemberInfoRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/harang/server/repository/MemberInfoRepository.java b/src/main/java/org/harang/server/repository/MemberInfoRepository.java index d916c47..81dd863 100644 --- a/src/main/java/org/harang/server/repository/MemberInfoRepository.java +++ b/src/main/java/org/harang/server/repository/MemberInfoRepository.java @@ -1,4 +1,4 @@ -성package org.harang.server.repository; +package org.harang.server.repository; import java.util.Optional; import org.harang.server.domain.MemberInfo;