-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #484 from woowacourse-teams/feat/451-map
지도 기능 main merge
- Loading branch information
Showing
22 changed files
with
729 additions
and
48 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
31 changes: 31 additions & 0 deletions
31
server/src/main/java/com/project/yozmcafe/controller/LocationController.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.project.yozmcafe.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; | ||
import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; | ||
import com.project.yozmcafe.service.LocationService; | ||
|
||
@RestController | ||
@RequestMapping("/cafes/location") | ||
public class LocationController { | ||
|
||
private final LocationService locationService; | ||
|
||
public LocationController(final LocationService locationService) { | ||
this.locationService = locationService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<CafeLocationResponse>> findCafesFromLocation( | ||
final CafeLocationRequest cafeLocationRequest) { | ||
final List<CafeLocationResponse> cafesFromLocations = locationService.findCafesFromLocations( | ||
cafeLocationRequest); | ||
return ResponseEntity.ok(cafesFromLocations); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.project.yozmcafe.controller.dto.cafe; | ||
|
||
import org.locationtech.jts.geom.Point; | ||
|
||
import com.project.yozmcafe.domain.cafe.Cafe; | ||
import com.project.yozmcafe.domain.cafe.GeometryGenerator; | ||
import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; | ||
|
||
public record CafeCoordinateRequest(double latitude, double longitude) { | ||
|
||
public CafeCoordinate toCafeCoordinateWithCafe(final Cafe cafe) { | ||
final Point point = GeometryGenerator.generatePointWithCoordinate(latitude, longitude); | ||
return new CafeCoordinate(point, cafe); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationRequest.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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.project.yozmcafe.controller.dto.cafe; | ||
|
||
public record CafeLocationRequest(double latitude, double longitude, double latitudeDelta, double longitudeDelta) { | ||
} |
16 changes: 16 additions & 0 deletions
16
server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.project.yozmcafe.controller.dto.cafe; | ||
|
||
import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; | ||
|
||
public record CafeLocationResponse(Long id, String name, String address, double latitude, double longitude) { | ||
|
||
public static CafeLocationResponse from(final CafePinDto cafePinDto) { | ||
return new CafeLocationResponse( | ||
cafePinDto.getId(), | ||
cafePinDto.getName(), | ||
cafePinDto.getAddress(), | ||
cafePinDto.getLatitude(), | ||
cafePinDto.getLongitude() | ||
); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.project.yozmcafe.domain.cafe; | ||
|
||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.GeometryFactory; | ||
import org.locationtech.jts.geom.Point; | ||
|
||
import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; | ||
|
||
public class GeometryGenerator { | ||
|
||
private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); | ||
/** | ||
* SRID(Spatial Reference Identifier)는 고유한 공간 좌표 식별자입니다. | ||
* <p> | ||
* 그 중, 4326은 WGS84 경위도 좌표계를 의미합니다. GPS 기술에서도 사용되는 좌표계로 범용적으로 가장 널리 사용되는 좌표계입니다. | ||
*/ | ||
private static final int SRID = 4326; | ||
private static final String STRING_POLYGON_FORMAT = "POLYGON((%s))"; | ||
private static final String STRING_GEOMETRY_DELIMITER = " "; | ||
private static final String POINT_DELIMITER = ", "; | ||
|
||
private GeometryGenerator() { | ||
} | ||
|
||
public static Point generatePointWithCoordinate(final double latitude, final double longitude) { | ||
final Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude)); | ||
point.setSRID(SRID); | ||
return point; | ||
} | ||
|
||
public static String generateStringPolygon(final CafeLocationRequest cafeLocationRequest) { | ||
final double latitude = cafeLocationRequest.latitude(); | ||
final double longitude = cafeLocationRequest.longitude(); | ||
final double latitudeDelta = cafeLocationRequest.latitudeDelta(); | ||
final double longitudeDelta = cafeLocationRequest.longitudeDelta(); | ||
|
||
final String minLatitude = String.valueOf(latitude - latitudeDelta); | ||
final String maxLatitude = String.valueOf(latitude + latitudeDelta); | ||
final String minLongitude = String.valueOf(longitude - longitudeDelta); | ||
final String maxLongitude = String.valueOf(longitude + longitudeDelta); | ||
|
||
final String firstVertex = String.join(STRING_GEOMETRY_DELIMITER, minLatitude, maxLongitude); | ||
final String secondVertex = String.join(STRING_GEOMETRY_DELIMITER, maxLatitude, maxLongitude); | ||
final String thirdVertex = String.join(STRING_GEOMETRY_DELIMITER, maxLatitude, minLongitude); | ||
final String fourthVertex = String.join(STRING_GEOMETRY_DELIMITER, minLatitude, minLongitude); | ||
|
||
final String vertexes = String.join(POINT_DELIMITER, firstVertex, secondVertex, thirdVertex, fourthVertex, | ||
firstVertex); | ||
return String.format(STRING_POLYGON_FORMAT, vertexes); | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
server/src/main/java/com/project/yozmcafe/domain/cafe/Images.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
59 changes: 59 additions & 0 deletions
59
server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.project.yozmcafe.domain.cafe.coordinate; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
import org.locationtech.jts.geom.Point; | ||
|
||
import com.project.yozmcafe.domain.cafe.Cafe; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToOne; | ||
|
||
@Entity | ||
public class CafeCoordinate { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
private Point coordinate; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
private Cafe cafe; | ||
|
||
protected CafeCoordinate() { | ||
} | ||
|
||
public CafeCoordinate(final Long id, final Point coordinate, final Cafe cafe) { | ||
this.id = id; | ||
this.coordinate = coordinate; | ||
this.cafe = cafe; | ||
} | ||
|
||
public CafeCoordinate(final Point coordinate, final Cafe cafe) { | ||
this(null, coordinate, cafe); | ||
} | ||
|
||
public double getLatitude() { | ||
return coordinate.getY(); | ||
} | ||
|
||
public double getLongitude() { | ||
return coordinate.getX(); | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Point getCoordinate() { | ||
return coordinate; | ||
} | ||
|
||
public Cafe getCafe() { | ||
return cafe; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...r/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.project.yozmcafe.domain.cafe.coordinate; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; | ||
|
||
public interface CafeCoordinateRepository extends JpaRepository<CafeCoordinate, Long> { | ||
|
||
@Query(nativeQuery = true, | ||
value = """ | ||
SELECT c.id, c.name, c.address, ST_X(co.coordinate) AS latitude, ST_Y(co.coordinate) AS longitude | ||
FROM cafe_coordinate co | ||
JOIN cafe AS c | ||
ON co.cafe_id = c.id | ||
WHERE ST_CONTAINS(ST_GeomFromText(:area, 4326), co.coordinate); | ||
""") | ||
List<CafePinDto> findCafePinsFromCoordinate(@Param("area") final String area); | ||
} |
13 changes: 13 additions & 0 deletions
13
server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/dto/CafePinDto.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.project.yozmcafe.domain.cafe.coordinate.dto; | ||
|
||
public interface CafePinDto { | ||
Long getId(); | ||
|
||
String getName(); | ||
|
||
String getAddress(); | ||
|
||
double getLatitude(); | ||
|
||
double getLongitude(); | ||
} |
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.