From 31dee5435fcd36ef4c90df2b3cbed95c511f55b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B5=AC=ED=99=98=EC=A4=80/=EB=AA=A8=EA=B1=B4?= Date: Sun, 16 Jun 2024 11:31:55 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Feat:=20Branch=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/branch/business/BranchService.java | 39 ++++++++++++++ .../implementation/BranchCommandAdapter.java | 14 +++++ .../implementation/BranchQueryAdapter.java | 22 ++++++++ .../branch/persistence/BranchRepository.java | 11 ++++ .../api/branch/presentation/BranchApi.java | 32 +++++++++++ .../presentation/dto/BranchResponseDTO.java | 53 +++++++++++++++++++ .../server/global/entity/branch/Branch.java | 31 +++++++++++ 7 files changed, 202 insertions(+) create mode 100644 src/main/java/treehouse/server/api/branch/business/BranchService.java create mode 100644 src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java create mode 100644 src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java create mode 100644 src/main/java/treehouse/server/api/branch/persistence/BranchRepository.java create mode 100644 src/main/java/treehouse/server/api/branch/presentation/BranchApi.java create mode 100644 src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java create mode 100644 src/main/java/treehouse/server/global/entity/branch/Branch.java diff --git a/src/main/java/treehouse/server/api/branch/business/BranchService.java b/src/main/java/treehouse/server/api/branch/business/BranchService.java new file mode 100644 index 0000000..4b91ec7 --- /dev/null +++ b/src/main/java/treehouse/server/api/branch/business/BranchService.java @@ -0,0 +1,39 @@ +package treehouse.server.api.branch.business; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import treehouse.server.api.branch.implementation.BranchCommandAdapter; +import treehouse.server.api.branch.implementation.BranchQueryAdapter; +import treehouse.server.api.branch.presentation.dto.BranchResponseDTO; +import treehouse.server.api.member.implementation.MemberQueryAdapter; +import treehouse.server.api.treehouse.implementation.TreehouseQueryAdapter; +import treehouse.server.global.entity.User.User; +import treehouse.server.global.entity.branch.Branch; +import treehouse.server.global.entity.member.Member; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +import java.util.List; + +@Service +@AllArgsConstructor +@Slf4j +public class BranchService { + + private final BranchCommandAdapter branchCommandAdapter; + private final BranchQueryAdapter branchQueryAdapter; + private final TreehouseQueryAdapter treehouseQueryAdapter; + private final MemberQueryAdapter memberQueryAdapter; + + + public BranchResponseDTO.getMemberBranchView getMemberBranchView(User user, Long treehouseId, Long targetMemberId) { + + TreeHouse treeHouse = treehouseQueryAdapter.getTreehouseById(treehouseId); + List branches = branchQueryAdapter.findAllByTreehouse(treeHouse); // 트리하우스 내 모든 브랜치 조회 + Member member = memberQueryAdapter.findByUserAndTreehouse(user, treeHouse); // 현재 로그인한 트리하우스 멤버 + Long rootId = member.getId(); // 현재 로그인한 트리하우스 멤버의 ID + + + + } +} diff --git a/src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java b/src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java new file mode 100644 index 0000000..5ec1df0 --- /dev/null +++ b/src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java @@ -0,0 +1,14 @@ +package treehouse.server.api.branch.implementation; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import treehouse.server.api.branch.persistence.BranchRepository; +import treehouse.server.global.annotations.Adapter; + +@Adapter +@RequiredArgsConstructor +@Slf4j +public class BranchCommandAdapter { + + private final BranchRepository branchRepository; +} diff --git a/src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java b/src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java new file mode 100644 index 0000000..c8856d8 --- /dev/null +++ b/src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java @@ -0,0 +1,22 @@ +package treehouse.server.api.branch.implementation; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import treehouse.server.api.branch.persistence.BranchRepository; +import treehouse.server.global.annotations.Adapter; +import treehouse.server.global.entity.branch.Branch; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +import java.util.List; + +@Adapter +@RequiredArgsConstructor +@Slf4j +public class BranchQueryAdapter { + + private final BranchRepository branchRepository; + + public List findAllByTreehouse(TreeHouse treeHouse) { + return branchRepository.findAllByTreeHouse(treeHouse); + } +} diff --git a/src/main/java/treehouse/server/api/branch/persistence/BranchRepository.java b/src/main/java/treehouse/server/api/branch/persistence/BranchRepository.java new file mode 100644 index 0000000..c75c87d --- /dev/null +++ b/src/main/java/treehouse/server/api/branch/persistence/BranchRepository.java @@ -0,0 +1,11 @@ +package treehouse.server.api.branch.persistence; + +import org.springframework.data.jpa.repository.JpaRepository; +import treehouse.server.global.entity.branch.Branch; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +import java.util.List; + +public interface BranchRepository extends JpaRepository{ + List findAllByTreeHouse(TreeHouse treeHouse); +} diff --git a/src/main/java/treehouse/server/api/branch/presentation/BranchApi.java b/src/main/java/treehouse/server/api/branch/presentation/BranchApi.java new file mode 100644 index 0000000..2365fb2 --- /dev/null +++ b/src/main/java/treehouse/server/api/branch/presentation/BranchApi.java @@ -0,0 +1,32 @@ +package treehouse.server.api.branch.presentation; + +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; +import treehouse.server.api.branch.business.BranchService; +import treehouse.server.api.branch.presentation.dto.BranchResponseDTO; +import treehouse.server.global.common.CommonResponse; +import treehouse.server.global.entity.User.User; +import treehouse.server.global.security.handler.annotation.AuthMember; + +@RequiredArgsConstructor +@RestController +@Slf4j +@Tag(name = "🔗 Branch API", description = "트리하우스 브랜치 관련 API 입니다.") +@RequestMapping("/treehouses/{treehouseId}/branches") +public class BranchApi { + + private final BranchService branchService; + + @GetMapping + public CommonResponse getMemberBranchView( + @PathVariable(name = "treehouseId") Long treehouseId, + @RequestParam(name = "targetMemberId") Long targetMemberId, + @AuthMember @Parameter(hidden = true) User user + ) + { + return CommonResponse.onSuccess(branchService.getMemberBranchView(user, treehouseId, targetMemberId)); + } +} diff --git a/src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java b/src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java new file mode 100644 index 0000000..ba7edc7 --- /dev/null +++ b/src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java @@ -0,0 +1,53 @@ +package treehouse.server.api.branch.presentation.dto; + +import lombok.*; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BranchResponseDTO { + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class ShortestPathResult{ + private int distance; + private List path; + } + + // Node 정보를 담을 클래스 + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class NodeDTO { + private Long id; + private String profileImageUrl; + private String memberName; + + } + + // Link 정보를 담을 클래스 + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class LinkDTO { + private Long sourceId; + private Long targetId; + + } + + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class getMemberBranchView { + private List nodes; + private List links; + private Long startId; // 시작 노드의 memberId + private Long endId; // 끝 노드의 memberId + } +} diff --git a/src/main/java/treehouse/server/global/entity/branch/Branch.java b/src/main/java/treehouse/server/global/entity/branch/Branch.java new file mode 100644 index 0000000..358d847 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/branch/Branch.java @@ -0,0 +1,31 @@ +package treehouse.server.global.entity.branch; + +import jakarta.persistence.*; +import lombok.*; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.member.Member; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Branch extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private Integer branchDegree; + + @JoinColumn(name = "rootId") + @ManyToOne(fetch = FetchType.LAZY) + private Member root; + @JoinColumn(name = "leafId") + @ManyToOne(fetch = FetchType.LAZY) + private Member leaf; + + @JoinColumn(name = "treehouseId") + @ManyToOne(fetch = FetchType.LAZY) + private TreeHouse treeHouse; +} From 9726441e82bcf89fe65df3518544c7200d885a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B5=AC=ED=99=98=EC=A4=80/=EB=AA=A8=EA=B1=B4?= Date: Tue, 25 Jun 2024 20:12:24 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Feat:=20Branch=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=A0=88=EA=B1=B0=EC=8B=9C=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/branch/business/BranchMapper.java | 58 ++++++++ .../api/branch/business/BranchService.java | 128 +++++++++++++++++- .../implementation/BranchCommandAdapter.java | 5 + .../implementation/BranchQueryAdapter.java | 2 +- .../api/branch/presentation/BranchApi.java | 12 ++ .../presentation/dto/BranchResponseDTO.java | 9 ++ .../implementation/MemberQueryAdapter.java | 6 +- .../global/exception/GlobalErrorCode.java | 4 +- 8 files changed, 218 insertions(+), 6 deletions(-) create mode 100644 src/main/java/treehouse/server/api/branch/business/BranchMapper.java diff --git a/src/main/java/treehouse/server/api/branch/business/BranchMapper.java b/src/main/java/treehouse/server/api/branch/business/BranchMapper.java new file mode 100644 index 0000000..be2c0a7 --- /dev/null +++ b/src/main/java/treehouse/server/api/branch/business/BranchMapper.java @@ -0,0 +1,58 @@ +package treehouse.server.api.branch.business; + +import treehouse.server.api.branch.presentation.dto.BranchResponseDTO; +import treehouse.server.global.entity.branch.Branch; +import treehouse.server.global.entity.member.Member; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +import java.util.List; + +public class BranchMapper { + + public static Branch toBranch(TreeHouse treeHouse, Member inviter, Member invitee) { + return Branch.builder() + .treeHouse(treeHouse) + .root(inviter) + .leaf(invitee) + .branchDegree(1) + .build(); + } + + public static BranchResponseDTO.ShortestPathResult toShortestPathResult(int distance, List path) { + return BranchResponseDTO.ShortestPathResult.builder() + .distance(distance) + .path(path) + .build(); + } + + public static BranchResponseDTO.NodeDTO toNodeDTO(Member member) { + return BranchResponseDTO.NodeDTO.builder() + .id(member.getId()) + .profileImageUrl(member.getProfileImageUrl()) + .memberName(member.getName()) + .build(); + } + + public static BranchResponseDTO.LinkDTO toLinkDTO(Long sourceId, Long leafId) { + return BranchResponseDTO.LinkDTO.builder() + .sourceId(sourceId) + .targetId(leafId) + .build(); + } + + public static BranchResponseDTO.getMemberBranchView toBranchView(List nodes, List links, Long rootId, Long leafId) { + return BranchResponseDTO.getMemberBranchView.builder() + .nodes(nodes) + .links(links) + .startId(rootId) + .endId(leafId) + .build(); + } + + public static BranchResponseDTO.getCompleteBranchView toCompleteBranchView(List nodes, List links) { + return BranchResponseDTO.getCompleteBranchView.builder() + .nodes(nodes) + .links(links) + .build(); + } +} diff --git a/src/main/java/treehouse/server/api/branch/business/BranchService.java b/src/main/java/treehouse/server/api/branch/business/BranchService.java index 4b91ec7..42443ed 100644 --- a/src/main/java/treehouse/server/api/branch/business/BranchService.java +++ b/src/main/java/treehouse/server/api/branch/business/BranchService.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import treehouse.server.api.branch.implementation.BranchCommandAdapter; import treehouse.server.api.branch.implementation.BranchQueryAdapter; import treehouse.server.api.branch.presentation.dto.BranchResponseDTO; @@ -13,7 +14,8 @@ import treehouse.server.global.entity.member.Member; import treehouse.server.global.entity.treeHouse.TreeHouse; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; @Service @AllArgsConstructor @@ -25,15 +27,137 @@ public class BranchService { private final TreehouseQueryAdapter treehouseQueryAdapter; private final MemberQueryAdapter memberQueryAdapter; + @Transactional + public void createBranch(TreeHouse treeHouse, Member inviter, Member invitee) { + Branch branch = BranchMapper.toBranch(treeHouse, inviter, invitee); + branchCommandAdapter.createBranch(branch); + } + /** + * 트리하우스 내 두 멤버 사이의 가장 짧은 거리를 계산하여 브랜치 뷰를 반환합니다. + * @param user + * @param treehouseId + * @param targetMemberId + * @return BranchResponseDTO.getMemberBranchView + */ + @Transactional(readOnly = true) public BranchResponseDTO.getMemberBranchView getMemberBranchView(User user, Long treehouseId, Long targetMemberId) { TreeHouse treeHouse = treehouseQueryAdapter.getTreehouseById(treehouseId); - List branches = branchQueryAdapter.findAllByTreehouse(treeHouse); // 트리하우스 내 모든 브랜치 조회 + List branches = branchQueryAdapter.findAllByTreeHouse(treeHouse); // 트리하우스 내 모든 브랜치 조회 Member member = memberQueryAdapter.findByUserAndTreehouse(user, treeHouse); // 현재 로그인한 트리하우스 멤버 Long rootId = member.getId(); // 현재 로그인한 트리하우스 멤버의 ID + BranchResponseDTO.ShortestPathResult shortestPathResult = findShortestDistance(branches, rootId, targetMemberId); // 최단 거리 계산 + + // 최단 거리 결과를 이용해 브랜치 뷰 생성 + // Node 정보 생성 + List nodes = shortestPathResult.getPath().stream() + .map(memberId -> memberQueryAdapter.findById(memberId)) + .map(BranchMapper::toNodeDTO) + .collect(Collectors.toList()); + + // Link 정보 생성 + List links = new ArrayList<>(); + for (int i = 0; i < shortestPathResult.getPath().size() - 1; i++) { + links.add(BranchMapper.toLinkDTO(shortestPathResult.getPath().get(i), shortestPathResult.getPath().get(i + 1))); + } + + // 브랜치 뷰 생성 + return BranchMapper.toBranchView(nodes, links, rootId, targetMemberId); + + } + + @Transactional(readOnly = true) + public BranchResponseDTO.getCompleteBranchView getCompleteBranchView(User user, Long treehouseId) { + TreeHouse treeHouse = treehouseQueryAdapter.getTreehouseById(treehouseId); + List branches = branchQueryAdapter.findAllByTreeHouse(treeHouse); // 트리하우스 내 모든 브랜치 조회 + Set memberIds = new HashSet<>(); + List nodes = new ArrayList<>(); + List links = new ArrayList<>(); + + // 모든 멤버 ID를 수집 + for (Branch branch : branches) { + memberIds.add(branch.getRoot().getId()); + memberIds.add(branch.getLeaf().getId()); + links.add(BranchMapper.toLinkDTO(branch.getRoot().getId(), branch.getLeaf().getId())); + } + + // 모든 멤버 정보를 조회 + for (Long memberId : memberIds) { + Member member = memberQueryAdapter.findById(memberId); + nodes.add(BranchMapper.toNodeDTO(member)); + } + + // 브랜치 뷰 생성 + return BranchMapper.toCompleteBranchView(nodes, links); + } + + /** + * 두 멤버 사이의 가장 짧은 거리를 계산하여 정수값으로 니다. + * @param treeHouse + * @param rootId // 시작 멤버 ID + * @param leafId // 끝(대상) 멤버 ID + * @return 두 멤버 사이의 가장 짧은 거리 + */ + + public Integer calculateBranchDegree(TreeHouse treeHouse, Long rootId, Long leafId) { + // 두 멤버 사이의 모든 Branch 엔티티를 찾습니다. + List branches = branchQueryAdapter.findAllByTreeHouse(treeHouse); + + // Branch 목록을 사용하여 최단 거리를 계산합니다. + int shortestDistance = findShortestDistance(branches, rootId, leafId).getDistance(); + + return shortestDistance; + } + + /** + * BFS 알고리즘을 이용해 두 멤버 사이의 가장 짧은 거리를 계산합니다. + * @param branches + * @param startMemberId + * @param endMemberId + * @return 두 멤버 사이의 가장 짧은 거리 + */ + + public BranchResponseDTO.ShortestPathResult findShortestDistance(List branches, Long startMemberId, Long endMemberId) { + Map> adjacencyList = new HashMap<>(); + Map prev = new HashMap<>(); + Set visited = new HashSet<>(); + Queue queue = new LinkedList<>(); + + // 각 멤버 ID를 기준으로 연결된 Branch를 매핑 + for (Branch branch : branches) { + adjacencyList.computeIfAbsent(branch.getRoot().getId(), k -> new ArrayList<>()).add(branch.getLeaf().getId()); + adjacencyList.computeIfAbsent(branch.getLeaf().getId(), k -> new ArrayList<>()).add(branch.getRoot().getId()); + } + + queue.add(startMemberId); + visited.add(startMemberId); + prev.put(startMemberId, null); // 시작 노드의 선행자는 없음 + while (!queue.isEmpty()) { + Long current = queue.poll(); + if (current.equals(endMemberId)) { + break; // 목표 노드에 도달 + } + for (Long neighbor : adjacencyList.getOrDefault(current, Collections.emptyList())) { + if (!visited.contains(neighbor)) { + visited.add(neighbor); + queue.add(neighbor); + prev.put(neighbor, current); + } + } + } + // 경로 복원 및 결과 생성 + List path = new ArrayList<>(); + Long current = endMemberId; + while (current != null) { + path.add(current); + current = prev.get(current); + } + Collections.reverse(path); // 경로를 역순으로 뒤집어 정상 순서로 만듦 + int distance = path.size() - 1; // 거리는 경로의 길이에서 1을 뺀 값 + return BranchMapper.toShortestPathResult(distance, path); } } diff --git a/src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java b/src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java index 5ec1df0..3969e34 100644 --- a/src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java +++ b/src/main/java/treehouse/server/api/branch/implementation/BranchCommandAdapter.java @@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; import treehouse.server.api.branch.persistence.BranchRepository; import treehouse.server.global.annotations.Adapter; +import treehouse.server.global.entity.branch.Branch; @Adapter @RequiredArgsConstructor @@ -11,4 +12,8 @@ public class BranchCommandAdapter { private final BranchRepository branchRepository; + + public void createBranch(Branch branch) { + branchRepository.save(branch); + } } diff --git a/src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java b/src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java index c8856d8..8baba8e 100644 --- a/src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java +++ b/src/main/java/treehouse/server/api/branch/implementation/BranchQueryAdapter.java @@ -16,7 +16,7 @@ public class BranchQueryAdapter { private final BranchRepository branchRepository; - public List findAllByTreehouse(TreeHouse treeHouse) { + public List findAllByTreeHouse(TreeHouse treeHouse) { return branchRepository.findAllByTreeHouse(treeHouse); } } diff --git a/src/main/java/treehouse/server/api/branch/presentation/BranchApi.java b/src/main/java/treehouse/server/api/branch/presentation/BranchApi.java index 2365fb2..4c81463 100644 --- a/src/main/java/treehouse/server/api/branch/presentation/BranchApi.java +++ b/src/main/java/treehouse/server/api/branch/presentation/BranchApi.java @@ -1,5 +1,6 @@ package treehouse.server.api.branch.presentation; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -20,6 +21,7 @@ public class BranchApi { private final BranchService branchService; + @Operation(summary = "두 멤버 간 브랜치 뷰 API 🔑", description = "트리하우스 내 두 멤버 사이의 브랜치 뷰를 반환합니다.") @GetMapping public CommonResponse getMemberBranchView( @PathVariable(name = "treehouseId") Long treehouseId, @@ -29,4 +31,14 @@ public CommonResponse getMemberBranchView { return CommonResponse.onSuccess(branchService.getMemberBranchView(user, treehouseId, targetMemberId)); } + + @Operation(summary = "트리하우스 전체 브랜치 뷰 API 🔑", description = "트리하우스 내 모든 멤버 사이의 브랜치 뷰를 반환합니다.") + @GetMapping("/complete") + public CommonResponse getCompleteBranchView( + @PathVariable(name = "treehouseId") Long treehouseId, + @AuthMember @Parameter(hidden = true) User user + ) + { + return CommonResponse.onSuccess(branchService.getCompleteBranchView(user, treehouseId)); + } } diff --git a/src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java b/src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java index ba7edc7..ab33cfa 100644 --- a/src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java +++ b/src/main/java/treehouse/server/api/branch/presentation/dto/BranchResponseDTO.java @@ -50,4 +50,13 @@ public static class getMemberBranchView { private Long startId; // 시작 노드의 memberId private Long endId; // 끝 노드의 memberId } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class getCompleteBranchView { + private List nodes; + private List links; + } } diff --git a/src/main/java/treehouse/server/api/member/implementation/MemberQueryAdapter.java b/src/main/java/treehouse/server/api/member/implementation/MemberQueryAdapter.java index de2a41e..a041b47 100644 --- a/src/main/java/treehouse/server/api/member/implementation/MemberQueryAdapter.java +++ b/src/main/java/treehouse/server/api/member/implementation/MemberQueryAdapter.java @@ -20,6 +20,10 @@ public Member getMember(User user){ } public Member findByUserAndTreehouse(User user, TreeHouse treehouse) { - return memberRepository.findByUserAndTreeHouse(user, treehouse).orElseThrow(() -> new MemberException(GlobalErrorCode.USER_NOT_FOUND)); + return memberRepository.findByUserAndTreeHouse(user, treehouse).orElseThrow(() -> new MemberException(GlobalErrorCode.MEMBER_NOT_FOUND)); + } + + public Member findById(Long memberId) { + return memberRepository.findById(memberId).orElseThrow(() -> new MemberException(GlobalErrorCode.MEMBER_NOT_FOUND)); } } diff --git a/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java b/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java index 2896713..80fa6b7 100644 --- a/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java +++ b/src/main/java/treehouse/server/global/exception/GlobalErrorCode.java @@ -47,8 +47,8 @@ public enum GlobalErrorCode implements BaseErrorCode{ DUPLICATE_PHONE_NUMBER(CONFLICT, "USER409_1", "중복된 전화번호가 존재합니다."), // MEMBER + 404 Not Found - 찾을 수 없음 - PROFILE_NOT_FOUND(NOT_FOUND, "MEMBER404_1", "존재하지 않는 프로필입니다."), - AVAILABLE_PROFILE_NOT_FOUND(NOT_FOUND, "MEMBER404_2", "현재 선택된 프로필이 없습니다."), + MEMBER_NOT_FOUND(NOT_FOUND, "MEMBER404_1", "존재하지 않는 멤버입니다."), + AVAILABLE_PROFILE_NOT_FOUND(NOT_FOUND, "MEMBER404_2", "현재 선택된 멤버 정보가 없습니다."), // TREEHOUSE + 404 Not Found - 찾을 수 없음 TREEHOUSE_NOT_FOUND(NOT_FOUND, "TREEHOUSE404_1", "존재하지 않는 트리입니다."),