-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix : api 경로 수정 * feat : 현재 영역에서 쓰레기통 조회 * feat : 현재 위치로부터 사각 영역내 쓰레기통 조회 * feat : 카테고리별 조회 추가 * docs : 스웨거 정리 * docs : uri 수정
- Loading branch information
1 parent
a522999
commit dc9d0d3
Showing
16 changed files
with
173 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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 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 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
32 changes: 0 additions & 32 deletions
32
src/main/java/com/example/nzgeneration/domain/errorreport/ErrorReport.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/main/java/com/example/nzgeneration/domain/trashcan/TrashCategory.java
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.example.nzgeneration.domain.trashcan; | ||
|
||
public enum TrashCategory { | ||
PLASTIC, PAPER, GENERAL | ||
PLASTIC, PAPER, GENERAL, ALL | ||
} |
This file contains 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
61 changes: 60 additions & 1 deletion
61
src/main/java/com/example/nzgeneration/domain/trashcan/TrashcanController.java
This file contains 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 |
---|---|---|
@@ -1,21 +1,80 @@ | ||
package com.example.nzgeneration.domain.trashcan; | ||
|
||
import com.example.nzgeneration.domain.trashcan.dto.TrashcanRequestDto.GetTrashcansRequest; | ||
import com.example.nzgeneration.domain.trashcan.dto.TrashcanResponseDto.GetTrashcanResponse; | ||
import com.example.nzgeneration.domain.trashcan.dto.TrashcanResponseDto.GetTrashcanResponses; | ||
import com.example.nzgeneration.domain.user.User; | ||
import com.example.nzgeneration.domain.user.UserService; | ||
import com.example.nzgeneration.global.common.response.ApiResponse; | ||
import com.example.nzgeneration.global.common.response.code.status.ErrorStatus; | ||
import com.example.nzgeneration.global.common.response.exception.GeneralException; | ||
import com.example.nzgeneration.global.security.CurrentUser; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.GeometryFactory; | ||
import org.locationtech.jts.geom.Polygon; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Tag(name = "쓰레기통 조회", description = "쓰레기통 조회 API") | ||
public class TrashcanController { | ||
|
||
private final TrashcanService trashcanService; | ||
private final UserService userService; | ||
|
||
@GetMapping | ||
@GetMapping("api/trashcan/{id}") | ||
@Operation( | ||
summary = "쓰레기통 상세 조회" | ||
) | ||
public ApiResponse<GetTrashcanResponse> getTrashcan(@PathVariable Long id) { | ||
return ApiResponse.onSuccess(trashcanService.getTrashcan(id)); | ||
} | ||
|
||
@PostMapping("api/trashcans/") | ||
@Operation( | ||
summary = "영역 내 쓰레기통 조회", | ||
description = "영역의 네 좌표값으로 영역 내 거점을 조회.<br>영역의 좌표값은 위도와 경도 <br>카테고리는 all할 경우 전체 조회" | ||
) | ||
public ApiResponse<GetTrashcanResponses> getTrashcans( | ||
@RequestBody GetTrashcansRequest request, @RequestParam TrashCategory trashCategory) { | ||
|
||
//다각형 객체 초기화 | ||
Polygon polygon = null; | ||
|
||
try { | ||
GeometryFactory geometryFactory = new GeometryFactory(); | ||
//request 객체에서 좌표를 가져와 Coordinate객체 리스트를 생성 | ||
List<Coordinate> coordinatesPolygon = List.of( | ||
new Coordinate(request.getTopLeftPoint().getX(), request.getTopLeftPoint().getY()), | ||
new Coordinate(request.getBottomLeftPoint().getX(), request.getBottomLeftPoint().getY()), | ||
new Coordinate(request.getBottomRightPoint().getX(), request.getBottomRightPoint().getY()), | ||
new Coordinate(request.getTopRightPoint().getX(), request.getTopRightPoint().getY()), | ||
new Coordinate(request.getTopLeftPoint().getX(), request.getTopLeftPoint().getY()) | ||
); | ||
polygon = geometryFactory.createPolygon(coordinatesPolygon.toArray(new Coordinate[0])); | ||
} catch (NullPointerException e) { | ||
throw new GeneralException(ErrorStatus._TRASHCAN_COORDINATE_INVALID); | ||
} catch (IllegalArgumentException e) { | ||
throw new GeneralException(ErrorStatus._TRASHCAN_POLYGON_INVALID); | ||
} | ||
return ApiResponse.onSuccess(trashcanService.getTrashcans(polygon, trashCategory)); | ||
} | ||
|
||
@Operation( | ||
summary = "쓰레기통 스탬프 찍기" | ||
) | ||
@PostMapping("api/user/trashcan-stamp") | ||
public ApiResponse<String> addStamp(@CurrentUser User user) { | ||
userService.addStamp(user); | ||
return ApiResponse.onSuccess("스탬프 찍기 성공"); | ||
} | ||
} |
12 changes: 11 additions & 1 deletion
12
src/main/java/com/example/nzgeneration/domain/trashcan/TrashcanRepository.java
This file contains 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 |
---|---|---|
@@ -1,7 +1,17 @@ | ||
package com.example.nzgeneration.domain.trashcan; | ||
|
||
import java.util.List; | ||
import org.locationtech.jts.geom.Polygon; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface TrashcanRepository extends JpaRepository<Trashcan, Long> { | ||
|
||
} | ||
//polygon안에 trashcanPoint가 포함되는지 확인 | ||
@Query(value = "SELECT tc FROM Trashcan tc WHERE ST_CONTAINS(:polygon, tc.trashcanPoint) = true AND tc.trashCategory = :trashCategory") | ||
List<Trashcan> findTrashcansByPolygonAndTrashCategory(@Param("polygon") Polygon polygon, @Param("trashCategory") TrashCategory trashCategory); | ||
|
||
@Query(value = "SELECT tc FROM Trashcan tc WHERE ST_CONTAINS(:polygon, tc.trashcanPoint)") | ||
List<Trashcan> findTrashcansByPolygon(@Param("polygon") Polygon polygon); | ||
} |
This file contains 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
18 changes: 17 additions & 1 deletion
18
src/main/java/com/example/nzgeneration/domain/trashcan/dto/TrashcanRequestDto.java
This file contains 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 |
---|---|---|
@@ -1,6 +1,22 @@ | ||
package com.example.nzgeneration.domain.trashcan.dto; | ||
|
||
public class TrashcanRequestDto { | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.geo.Point; | ||
|
||
public class TrashcanRequestDto { | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class GetTrashcansRequest { | ||
private Point currentPoint; | ||
private Point topLeftPoint; | ||
private Point topRightPoint; | ||
private Point bottomRightPoint; | ||
private Point bottomLeftPoint; | ||
} | ||
} |
This file contains 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
9 changes: 7 additions & 2 deletions
9
...va/com/example/nzgeneration/domain/trashcanerrorreport/TrashcanErrorReportController.java
This file contains 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 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 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
Oops, something went wrong.