From baafb2d89209389f286128e31717089ed43eebed Mon Sep 17 00:00:00 2001 From: mikekks Date: Thu, 30 Jan 2025 14:12:48 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[UNI-13]=20feat:=20=EB=85=B8=EB=93=9C=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=20=EA=B1=B4=EB=AC=BC=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniro_backend/common/error/ErrorCode.java | 12 +++++++++--- .../custom/NotFoundBuildingException.java | 13 +++++++++++++ .../node/repository/BuildingRepository.java | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/NotFoundBuildingException.java diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorCode.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorCode.java index 3c8a2cb..d28b618 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorCode.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorCode.java @@ -1,5 +1,7 @@ package com.softeer5.uniro_backend.common.error; +import org.springframework.http.HttpStatus; + import lombok.AllArgsConstructor; import lombok.Getter; @@ -8,8 +10,12 @@ public enum ErrorCode { // 길찾기 FASTEST_ROUTE_NOT_FOUND(422, "경로가 없습니다."), - SAME_START_AND_END_POINT(400, "출발지와 도착지가 같습니다."); + SAME_START_AND_END_POINT(400, "출발지와 도착지가 같습니다."), + + // 건물 노드 + BUILDING_NOT_FOUND(404, "유효한 건물을 찾을 수 없습니다."), + ; - final private int httpStatus; - final private String message; + private final int httpStatus; + private final String message; } diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/NotFoundBuildingException.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/NotFoundBuildingException.java new file mode 100644 index 0000000..45246e3 --- /dev/null +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/NotFoundBuildingException.java @@ -0,0 +1,13 @@ +package com.softeer5.uniro_backend.common.exception.custom; + +import com.softeer5.uniro_backend.common.error.ErrorCode; +import com.softeer5.uniro_backend.common.exception.CustomException; + +import lombok.Getter; + +@Getter +public class NotFoundBuildingException extends CustomException { + public NotFoundBuildingException(String message, ErrorCode errorCode) { + super(message, errorCode); + } +} diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java index afb633e..ac5e27d 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java @@ -1,10 +1,13 @@ package com.softeer5.uniro_backend.node.repository; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import com.softeer5.uniro_backend.common.error.ErrorCode; +import com.softeer5.uniro_backend.common.exception.custom.NotFoundBuildingException; import com.softeer5.uniro_backend.node.dto.BuildingNode; import com.softeer5.uniro_backend.node.entity.Building; @@ -20,4 +23,17 @@ public interface BuildingRepository extends JpaRepository, Build AND ST_Within(n.coordinates, ST_MakeEnvelope(:lux, :luy, :rdx, :rdy, 4326)) """) List findByUnivIdAndLevelWithNode(Long univId, int level, double lux , double luy, double rdx , double rdy); + + @Query(""" + SELECT new com.softeer5.uniro_backend.node.dto.BuildingNode(b, n) + FROM Building b + JOIN FETCH Node n ON b.nodeId = n.id + WHERE b.nodeId = :nodeId + """) + Optional findByNodeIdWithNode(Long nodeId); + + default BuildingNode findByNodeIdWithNodeOrThrow(Long nodeId){ + return findByNodeIdWithNode(nodeId) + .orElseThrow(() -> new NotFoundBuildingException("Not Found Building", ErrorCode.BUILDING_NOT_FOUND)); + } } From 85fa2431e2202f76d9994b2371295478c2d8e94c Mon Sep 17 00:00:00 2001 From: mikekks Date: Thu, 30 Jan 2025 14:13:17 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[UNI-13]=20feat:=20=EB=85=B8=EB=93=9C=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=20=EA=B1=B4=EB=AC=BC=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniro_backend/node/controller/NodeApi.java | 10 ++++++++++ .../uniro_backend/node/controller/NodeController.java | 10 ++++++++++ .../uniro_backend/node/service/NodeService.java | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeApi.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeApi.java index 3f7b235..61e2874 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeApi.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeApi.java @@ -42,4 +42,14 @@ ResponseEntity searchBuildings( @RequestParam(value = "cursor-id", required = false) Long cursorId, @RequestParam(value = "page-size", required = false) Integer pageSize ); + + @Operation(summary = "상세 건물 노드 조회") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "상세 건물 노드 조회 성공"), + @ApiResponse(responseCode = "400", description = "EXCEPTION(임시)", content = @Content), + }) + ResponseEntity getBuilding( + @PathVariable("univId") Long univId, + @PathVariable("nodeId") Long nodeId + ); } diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeController.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeController.java index 7b3aef8..70400ca 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeController.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeController.java @@ -46,4 +46,14 @@ public ResponseEntity searchBuildings( return ResponseEntity.ok().body(searchBuildingResDTO); } + @Override + @GetMapping("{univId}/nodes/buildings/{nodeId}") + public ResponseEntity getBuilding( + @PathVariable("univId") Long univId, + @PathVariable("nodeId") Long nodeId) { + + GetBuildingResDTO buildingResDTO = nodeService.getBuilding(nodeId); + return ResponseEntity.ok().body(buildingResDTO); + } + } diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java index 27f4926..ed973fb 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java @@ -42,4 +42,9 @@ public SearchBuildingResDTO searchBuildings(Long univId, String name, Long curso return SearchBuildingResDTO.of(data, buildingNodes.getNextCursor(), buildingNodes.isHasNext()); } + public GetBuildingResDTO getBuilding(Long nodeId){ + BuildingNode buildingNode = buildingRepository.findByNodeIdWithNodeOrThrow(nodeId); + return GetBuildingResDTO.of(buildingNode.getBuilding(), buildingNode.getNode()); + } + } From 2afdd6019dfc2c30af3a0fc3375751e91c94a90d Mon Sep 17 00:00:00 2001 From: mikekks Date: Thu, 30 Jan 2025 15:09:50 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[UNI-13]=20fix:=20Error=20=EC=83=81?= =?UTF-8?q?=EC=86=8D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/softeer5/uniro_backend/common/error/ErrorResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorResponse.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorResponse.java index 8ba8afc..8d1557a 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorResponse.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/error/ErrorResponse.java @@ -5,7 +5,7 @@ @Getter @Setter -public class ErrorResponse extends Error { +public class ErrorResponse { private int status; private String message; From 7a8c7335297bf674c91fa29a1cf9cc70e4ead28c Mon Sep 17 00:00:00 2001 From: mikekks Date: Thu, 30 Jan 2025 15:16:00 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[UNI-13]=20chore:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9D=B4=EB=A6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...dBuildingException.java => BuildingNotFoundException.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/{NotFoundBuildingException.java => BuildingNotFoundException.java} (67%) diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/NotFoundBuildingException.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/BuildingNotFoundException.java similarity index 67% rename from uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/NotFoundBuildingException.java rename to uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/BuildingNotFoundException.java index 45246e3..1c6e74a 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/NotFoundBuildingException.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/common/exception/custom/BuildingNotFoundException.java @@ -6,8 +6,8 @@ import lombok.Getter; @Getter -public class NotFoundBuildingException extends CustomException { - public NotFoundBuildingException(String message, ErrorCode errorCode) { +public class BuildingNotFoundException extends CustomException { + public BuildingNotFoundException(String message, ErrorCode errorCode) { super(message, errorCode); } } From 274810d243bdc67f0de6f46d4ce7117004542ca6 Mon Sep 17 00:00:00 2001 From: mikekks Date: Thu, 30 Jan 2025 15:16:35 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[UNI-13]=20fix:=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../node/repository/BuildingRepository.java | 7 ------- .../uniro_backend/node/service/NodeService.java | 11 +++++++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java index ac5e27d..9049dc7 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java @@ -6,8 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import com.softeer5.uniro_backend.common.error.ErrorCode; -import com.softeer5.uniro_backend.common.exception.custom.NotFoundBuildingException; import com.softeer5.uniro_backend.node.dto.BuildingNode; import com.softeer5.uniro_backend.node.entity.Building; @@ -31,9 +29,4 @@ AND ST_Within(n.coordinates, ST_MakeEnvelope(:lux, :luy, :rdx, :rdy, 4326)) WHERE b.nodeId = :nodeId """) Optional findByNodeIdWithNode(Long nodeId); - - default BuildingNode findByNodeIdWithNodeOrThrow(Long nodeId){ - return findByNodeIdWithNode(nodeId) - .orElseThrow(() -> new NotFoundBuildingException("Not Found Building", ErrorCode.BUILDING_NOT_FOUND)); - } } diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java index ed973fb..0652e1a 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java @@ -1,11 +1,14 @@ package com.softeer5.uniro_backend.node.service; import java.util.List; +import java.util.Optional; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.softeer5.uniro_backend.common.CursorPage; +import com.softeer5.uniro_backend.common.error.ErrorCode; +import com.softeer5.uniro_backend.common.exception.custom.BuildingNotFoundException; import com.softeer5.uniro_backend.node.dto.BuildingNode; import com.softeer5.uniro_backend.node.dto.GetBuildingResDTO; import com.softeer5.uniro_backend.node.dto.SearchBuildingResDTO; @@ -43,8 +46,12 @@ public SearchBuildingResDTO searchBuildings(Long univId, String name, Long curso } public GetBuildingResDTO getBuilding(Long nodeId){ - BuildingNode buildingNode = buildingRepository.findByNodeIdWithNodeOrThrow(nodeId); - return GetBuildingResDTO.of(buildingNode.getBuilding(), buildingNode.getNode()); + Optional buildingNode = buildingRepository.findByNodeIdWithNode(nodeId); + if(buildingNode.isEmpty()){ + throw new BuildingNotFoundException("Building Not Found", ErrorCode.BUILDING_NOT_FOUND); + } + + return GetBuildingResDTO.of(buildingNode.get().getBuilding(), buildingNode.get().getNode()); } }