From 6ebe16cc208203f65b5ea284d91e6651beb7735e Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 27 Jan 2025 18:59:22 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[UNI-64]=20chore:=20Building=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=AA=A9=EB=8D=B0=EC=9D=B4=ED=84=B0=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 --- uniro_backend/src/main/resources/data.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/uniro_backend/src/main/resources/data.sql b/uniro_backend/src/main/resources/data.sql index c05fdbf..1b6c233 100644 --- a/uniro_backend/src/main/resources/data.sql +++ b/uniro_backend/src/main/resources/data.sql @@ -18,3 +18,13 @@ VALUES (3, 15.2, ST_GeomFromText('LINESTRING(127.003 37.003, 127.004 37.004)', 4326), 3, 4, 1002, 1, NULL, NULL), (4, 25.7, ST_GeomFromText('LINESTRING(127.004 37.004, 127.005 37.005)', 4326), 4, 5, 1002, 1, '["CURB", "CRACK"]', NULL), (5, 30.0, ST_GeomFromText('LINESTRING(127.005 37.005, 127.006 37.006)', 4326), 5, 6, 1003, NULL, NULL, '["CURB"]'); + +INSERT INTO + building (id, phone_number, address, name, image_url, level, node_id, univ_id) +VALUES + (1, '010-1234-5678', '123 Main St', '공학관', 'http://example.com/image1.jpg', 5, 1, 1001), + (2, '010-2345-6789', '456 Maple Ave', '인문관', 'http://example.com/image2.jpg', 3, 2, 1001), + (3, '010-3456-7890', '789 Oak St', '소프트웨어융합관', 'http://example.com/image3.jpg', 7, 3, 1001), + (4, '010-4567-8901', '101 Pine St', '공대관', 'http://example.com/image4.jpg', 4, 4, 1002), + (5, '010-5678-9012', '202 Cedar Rd', '예술관', 'http://example.com/image5.jpg', 6, 5, 1002), + (6, '010-6789-0123', '303 Birch Ln', '강당', 'http://example.com/image6.jpg', 2, 6, 1003); From 73f74eca27d69c548553dc581e08b274876b2daf Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 27 Jan 2025 18:59:52 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[UNI-64]=20feat:=20univId=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniro_backend/node/entity/Building.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/entity/Building.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/entity/Building.java index 1758ae3..09afe5f 100644 --- a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/entity/Building.java +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/entity/Building.java @@ -5,6 +5,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -33,15 +34,12 @@ public class Building { private int level; + @Column(name = "node_id") + @NotNull private Long nodeId; - @Builder - private Building(String phoneNumber, String address, String name, String imageUrl, int level, Long nodeId) { - this.phoneNumber = phoneNumber; - this.address = address; - this.name = name; - this.imageUrl = imageUrl; - this.level = level; - this.nodeId = nodeId; - } + @Column(name = "univ_id") + @NotNull + private Long univId; + } From a30229e9f6ae1bcee80c0666785034a9604e01f1 Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 27 Jan 2025 19:00:17 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[UNI-64]=20feat:=20Building=20=EA=B3=BC=20N?= =?UTF-8?q?ode=20Join=ED=95=A0=20=EB=95=8C=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EB=8A=94=20DTO=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniro_backend/node/dto/BuildingNode.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/BuildingNode.java diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/BuildingNode.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/BuildingNode.java new file mode 100644 index 0000000..3b4d726 --- /dev/null +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/BuildingNode.java @@ -0,0 +1,17 @@ +package com.softeer5.uniro_backend.node.dto; + +import com.softeer5.uniro_backend.node.entity.Building; +import com.softeer5.uniro_backend.node.entity.Node; + +import lombok.Getter; + +@Getter +public class BuildingNode { + private final Building building; + private final Node node; + + public BuildingNode(Building building, Node node) { + this.building = building; + this.node = node; + } +} From 776f7e1ee810ee912faf7a44c5181e1b0adcb818 Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 27 Jan 2025 19:00:46 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[UNI-64]=20feat:=20DTO=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=ED=83=80=EC=9E=85=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../node/controller/NodeApi.java | 26 +++++++++++++ .../node/dto/GetBuildingResDTO.java | 37 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeApi.java create mode 100644 uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/GetBuildingResDTO.java 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 new file mode 100644 index 0000000..7a9f24b --- /dev/null +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeApi.java @@ -0,0 +1,26 @@ +package com.softeer5.uniro_backend.node.controller; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; + +import com.softeer5.uniro_backend.node.dto.GetBuildingResDTO; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; + +@Tag(name = "노드(코어노드, 서브노드, 건물노드) 관련 Api") +public interface NodeApi { + @Operation(summary = "건물 노드 조회") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "건물 노드 조회 성공"), + @ApiResponse(responseCode = "400", description = "EXCEPTION(임시)", content = @Content), + }) + ResponseEntity> getBuildings(@PathVariable("univId") Long univId, + @RequestParam(value = "level", required = false, defaultValue = "1") int level); +} diff --git a/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/GetBuildingResDTO.java b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/GetBuildingResDTO.java new file mode 100644 index 0000000..6f0b94e --- /dev/null +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/GetBuildingResDTO.java @@ -0,0 +1,37 @@ +package com.softeer5.uniro_backend.node.dto; + +import java.util.Map; + +import com.softeer5.uniro_backend.node.entity.Building; +import com.softeer5.uniro_backend.node.entity.Node; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Schema(name = "GetBuildingResDTO", description = "건물 노드 조회 DTO") +@Getter +@RequiredArgsConstructor +public class GetBuildingResDTO { + + @Schema(description = "노드 id", example = "4") + private final Long nodeId; + + @Schema(description = "건물 노드 좌표", example = "{\"lag\": 127.123456, \"lat\": 37.123456}") + private final Map node; + + private final String buildingName; + + private final String buildingImageUrl; + + private final String phoneNumber; + + private final String address; + + public static GetBuildingResDTO of(Building building, Node node) { + + return new GetBuildingResDTO(node.getId(), node.getXY(), building.getName(), building.getImageUrl(), + building.getPhoneNumber(), building.getAddress()); + } + +} From 44d8c996815b507dc1d9132adf2c6feb6ee937da Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 27 Jan 2025 19:01:35 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[UNI-64]=20feat:=20=EA=B1=B4=EB=AC=BC=20?= =?UTF-8?q?=EB=85=B8=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../node/controller/NodeController.java | 31 +++++++++++++++++++ .../node/repository/BuildingRepository.java | 21 +++++++++++++ .../node/service/NodeService.java | 28 +++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeController.java create mode 100644 uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java create mode 100644 uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java 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 new file mode 100644 index 0000000..48616b1 --- /dev/null +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeController.java @@ -0,0 +1,31 @@ +package com.softeer5.uniro_backend.node.controller; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.softeer5.uniro_backend.node.dto.GetBuildingResDTO; +import com.softeer5.uniro_backend.node.service.NodeService; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +public class NodeController implements NodeApi { + private final NodeService nodeService; + + @Override + @GetMapping("/{univId}/nodes/buildings") + public ResponseEntity> getBuildings( + @PathVariable("univId") Long univId, + @RequestParam(value = "level", required = false, defaultValue = "1") int level) { + + List buildingResDTOS = nodeService.getBuildings(univId, level); + return ResponseEntity.ok().body(buildingResDTOS); + } + +} 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 new file mode 100644 index 0000000..7668c85 --- /dev/null +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java @@ -0,0 +1,21 @@ +package com.softeer5.uniro_backend.node.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import com.softeer5.uniro_backend.node.dto.BuildingNode; +import com.softeer5.uniro_backend.node.entity.Building; + +public interface BuildingRepository extends JpaRepository { + + @Query(""" + SELECT new com.softeer5.uniro_backend.node.dto.BuildingNode(b, n) + FROM Building b + JOIN FETCH Node n ON b.nodeId = n.id + AND b.univId = :univId + AND b.level >= :level + """) + List findByUnivIdAndLevelWithNode(Long univId, int level); +} 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 new file mode 100644 index 0000000..203c408 --- /dev/null +++ b/uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java @@ -0,0 +1,28 @@ +package com.softeer5.uniro_backend.node.service; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.softeer5.uniro_backend.node.dto.BuildingNode; +import com.softeer5.uniro_backend.node.dto.GetBuildingResDTO; +import com.softeer5.uniro_backend.node.repository.BuildingRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class NodeService { + private final BuildingRepository buildingRepository; + + public List getBuildings(Long univId, int level){ + List buildingNodes = buildingRepository.findByUnivIdAndLevelWithNode(univId, level); + + return buildingNodes.stream() + .map(buildingNode -> GetBuildingResDTO.of(buildingNode.getBuilding(), buildingNode.getNode())) + .toList(); + } + +} From de2907408d7ac44759d677013d6b32b372a4aeeb Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 27 Jan 2025 21:18:32 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[UNI-64]=20fix:=20h2=EC=97=90=EC=84=9C=20ST?= =?UTF-8?q?=5FWithin=20=EC=97=B0=EC=82=B0=20=EC=A7=80=EC=9B=90=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=EC=9C=84=ED=95=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniro_backend/src/main/resources/application-local.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniro_backend/src/main/resources/application-local.yml b/uniro_backend/src/main/resources/application-local.yml index 57fec89..534c39b 100644 --- a/uniro_backend/src/main/resources/application-local.yml +++ b/uniro_backend/src/main/resources/application-local.yml @@ -1,6 +1,6 @@ spring: datasource: - url: jdbc:h2:mem:uniro-local-db;DATABASE_TO_UPPER=FALSE;mode=mysql + url: jdbc:h2:mem:uniro-local-db;mode=mysql driverClassName: org.h2.Driver username: sa password: From 4c967ca1a5839196914f9dd02053680d74cffe31 Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 27 Jan 2025 21:19:23 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[UNI-64]=20fix:=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EB=B0=94=EB=9D=BC=EB=B3=B4=EA=B3=A0=20=EC=9E=88=EB=8A=94=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=B2=94?= =?UTF-8?q?=EC=9C=84=20=EA=B2=80=EC=83=89=20=EA=B5=AC=ED=98=84=20(?= =?UTF-8?q?=EC=B6=94=ED=9B=84=EC=97=90=20=EA=B3=B5=EA=B0=84=20=EC=9D=B8?= =?UTF-8?q?=EB=8D=B1=EC=8A=A4=20=EC=A0=81=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uniro_backend/node/controller/NodeApi.java | 10 ++++++++-- .../node/controller/NodeController.java | 12 +++++++++--- .../node/repository/BuildingRepository.java | 4 +++- .../uniro_backend/node/service/NodeService.java | 8 ++++++-- uniro_backend/src/main/resources/data.sql | 4 ++-- 5 files changed, 28 insertions(+), 10 deletions(-) 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 7a9f24b..5fa22e1 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 @@ -21,6 +21,12 @@ public interface NodeApi { @ApiResponse(responseCode = "200", description = "건물 노드 조회 성공"), @ApiResponse(responseCode = "400", description = "EXCEPTION(임시)", content = @Content), }) - ResponseEntity> getBuildings(@PathVariable("univId") Long univId, - @RequestParam(value = "level", required = false, defaultValue = "1") int level); + ResponseEntity> getBuildings( + @PathVariable("univId") Long univId, + @RequestParam(value = "level", required = false, defaultValue = "1") int level, + @RequestParam(value = "left-up-lng") double leftUpLng, + @RequestParam(value = "left-up-lat") double leftUpLat, + @RequestParam(value = "right-down-lng") double rightDownLng, + @RequestParam(value = "right-down-lat") double rightDownLat + ); } 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 48616b1..46c1662 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 @@ -22,9 +22,15 @@ public class NodeController implements NodeApi { @GetMapping("/{univId}/nodes/buildings") public ResponseEntity> getBuildings( @PathVariable("univId") Long univId, - @RequestParam(value = "level", required = false, defaultValue = "1") int level) { - - List buildingResDTOS = nodeService.getBuildings(univId, level); + @RequestParam(value = "level", required = false, defaultValue = "1") int level, + @RequestParam(value = "left-up-lng") double leftUpLng, + @RequestParam(value = "left-up-lat") double leftUpLat, + @RequestParam(value = "right-down-lng") double rightDownLng, + @RequestParam(value = "right-down-lat") double rightDownLat + ) { + + List buildingResDTOS = nodeService.getBuildings(univId, level, leftUpLng, leftUpLat, + rightDownLng, rightDownLat); return ResponseEntity.ok().body(buildingResDTOS); } 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 7668c85..ef57c0e 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 @@ -10,12 +10,14 @@ public interface BuildingRepository extends JpaRepository { + // 추후에 인덱싱 작업 필요. @Query(""" SELECT new com.softeer5.uniro_backend.node.dto.BuildingNode(b, n) FROM Building b JOIN FETCH Node n ON b.nodeId = n.id AND b.univId = :univId AND b.level >= :level + AND ST_Within(n.coordinates, ST_MakeEnvelope(:lux, :luy, :rdx, :rdy, 4326)) """) - List findByUnivIdAndLevelWithNode(Long univId, int level); + List findByUnivIdAndLevelWithNode(Long univId, int level, double lux , double luy, double rdx , double rdy); } 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 203c408..2e47611 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 @@ -17,8 +17,12 @@ public class NodeService { private final BuildingRepository buildingRepository; - public List getBuildings(Long univId, int level){ - List buildingNodes = buildingRepository.findByUnivIdAndLevelWithNode(univId, level); + public List getBuildings( + Long univId, int level, + double leftUpLng, double leftUpLat, double rightDownLng , double rightDownLat) { + + List buildingNodes = buildingRepository.findByUnivIdAndLevelWithNode( + univId, level, leftUpLng, leftUpLat, rightDownLng, rightDownLat); return buildingNodes.stream() .map(buildingNode -> GetBuildingResDTO.of(buildingNode.getBuilding(), buildingNode.getNode())) diff --git a/uniro_backend/src/main/resources/data.sql b/uniro_backend/src/main/resources/data.sql index 1b6c233..fbfa9e7 100644 --- a/uniro_backend/src/main/resources/data.sql +++ b/uniro_backend/src/main/resources/data.sql @@ -24,7 +24,7 @@ INSERT INTO VALUES (1, '010-1234-5678', '123 Main St', '공학관', 'http://example.com/image1.jpg', 5, 1, 1001), (2, '010-2345-6789', '456 Maple Ave', '인문관', 'http://example.com/image2.jpg', 3, 2, 1001), - (3, '010-3456-7890', '789 Oak St', '소프트웨어융합관', 'http://example.com/image3.jpg', 7, 3, 1001), + (3, '010-3456-7890', '789 Oak St', '소프트웨어융합관', 'http://example.com/image3.jpg', 1, 3, 1001), (4, '010-4567-8901', '101 Pine St', '공대관', 'http://example.com/image4.jpg', 4, 4, 1002), - (5, '010-5678-9012', '202 Cedar Rd', '예술관', 'http://example.com/image5.jpg', 6, 5, 1002), + (5, '010-5678-9012', '202 Cedar Rd', '예술관', 'http://example.com/image5.jpg', 2, 5, 1002), (6, '010-6789-0123', '303 Birch Ln', '강당', 'http://example.com/image6.jpg', 2, 6, 1003);