-
Notifications
You must be signed in to change notification settings - Fork 0
[UNI-64] 건물 노드 조회 API ([UNI-9] last PR) #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6ebe16c
[UNI-64] chore: Building 관련 목데이터 추가
mikekks 73f74ec
[UNI-64] feat: univId 컬럼 추가
mikekks a30229e
[UNI-64] feat: Building 과 Node Join할 때 사용하는 DTO 정의
mikekks 776f7e1
[UNI-64] feat: DTO 데이터 타입 정의
mikekks 44d8c99
[UNI-64] feat: 건물 노드 조회 기능 구현
mikekks de29074
[UNI-64] fix: h2에서 ST_Within 연산 지원하기 위한 수정
mikekks 4c967ca
[UNI-64] fix: 현재 바라보고 있는 화면에 따라 범위 검색 구현 (추후에 공간 인덱스 적용)
mikekks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 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<List<GetBuildingResDTO>> 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 | ||
| ); | ||
| } |
37 changes: 37 additions & 0 deletions
37
uniro_backend/src/main/java/com/softeer5/uniro_backend/node/controller/NodeController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 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<List<GetBuildingResDTO>> 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 | ||
| ) { | ||
|
|
||
| List<GetBuildingResDTO> buildingResDTOS = nodeService.getBuildings(univId, level, leftUpLng, leftUpLat, | ||
| rightDownLng, rightDownLat); | ||
| return ResponseEntity.ok().body(buildingResDTOS); | ||
| } | ||
|
|
||
| } |
17 changes: 17 additions & 0 deletions
17
uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/BuildingNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
uniro_backend/src/main/java/com/softeer5/uniro_backend/node/dto/GetBuildingResDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String, Double> 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()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
..._backend/src/main/java/com/softeer5/uniro_backend/node/repository/BuildingRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 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<Building, Long> { | ||
|
|
||
| // 추후에 인덱싱 작업 필요. | ||
| @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<BuildingNode> findByUnivIdAndLevelWithNode(Long univId, int level, double lux , double luy, double rdx , double rdy); | ||
| } |
32 changes: 32 additions & 0 deletions
32
uniro_backend/src/main/java/com/softeer5/uniro_backend/node/service/NodeService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 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<GetBuildingResDTO> getBuildings( | ||
| Long univId, int level, | ||
| double leftUpLng, double leftUpLat, double rightDownLng , double rightDownLat) { | ||
|
|
||
| List<BuildingNode> buildingNodes = buildingRepository.findByUnivIdAndLevelWithNode( | ||
| univId, level, leftUpLng, leftUpLat, rightDownLng, rightDownLat); | ||
|
|
||
| return buildingNodes.stream() | ||
| .map(buildingNode -> GetBuildingResDTO.of(buildingNode.getBuilding(), buildingNode.getNode())) | ||
| .toList(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DTO 생성 시 저는 주로 빌더패턴을 사용하고, 민규님은 팩토리메서드 패턴을 사용하시는것 같습니다. 이에 관해서 컨밴션을 어떻게 할지에 대해 이야기해보면 좋을것 같아요 ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네넵 좋습니다! 내일 스크럼때 얘기해봅시다!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
회의내용
https://github.com/softeer5th/Team2-Getit/wiki/%5BBE%5D-DTO-%EC%83%9D%EC%84%B1-%EB%94%94%EC%9E%90%EC%9D%B8%ED%8C%A8%ED%84%B4-%ED%9A%8C%EC%9D%98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오... 정리 감사합니다 !!!