-
Notifications
You must be signed in to change notification settings - Fork 0
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
π :: (#63) κ°κ² μ§λ λͺ©λ‘ 보기 API #79
base: main
Are you sure you want to change the base?
Changes from all commits
f326f77
a9a6002
1f25c4c
bcdf2ff
e1c2af5
42a0a8b
b730893
aae1c6d
b47017f
10af5b9
3c4d859
f3e605d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.cheajib.cheajibserver.domain.restaurant.domain.type | ||
|
||
enum class Direction( | ||
val bearing: Double | ||
) { | ||
NORTH(0.0), | ||
WEST(270.0), | ||
SOUTH(180.0), | ||
EAST(90.0), | ||
NORTHWEST(315.0), | ||
SOUTHWEST(225.0), | ||
SOUTHEAST(135.0), | ||
NORTHEAST(45.0) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ import com.cheajib.cheajibserver.domain.restaurant.domain.repository.RestaurantR | |
import com.cheajib.cheajibserver.domain.restaurant.exception.RestaurantNotFoundException | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Component | ||
import java.util.UUID | ||
import java.util.* | ||
import kotlin.math.cos | ||
import kotlin.math.sin | ||
|
||
@Component | ||
class RestaurantFacade( | ||
|
@@ -14,4 +16,38 @@ class RestaurantFacade( | |
fun getRestaurantById(id: UUID): Restaurant { | ||
return restaurantRepository.findByIdOrNull(id) ?: throw RestaurantNotFoundException.EXCEPTION | ||
} | ||
|
||
fun getCoordinatesCalculate(latitude: Double, longitude: Double, bearing: Double, distance: Double): Location { | ||
val radianLatitude: Double = toRadian(latitude) | ||
val radianLongitude: Double = toRadian(longitude) | ||
val radianAngle: Double = toRadian(bearing) | ||
val distanceRadius: Double = distance / 6371.01 | ||
|
||
val latitude: Double = Math.asin(sin(radianLatitude) * cos(distanceRadius) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
cos(radianLatitude) * sin(distanceRadius) * cos(radianAngle)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
|
||
var longitude: Double = radianLongitude + Math.atan2(sin(radianAngle) * sin(distanceRadius) * | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
cos(radianLatitude), cos(distanceRadius) - sin(radianLatitude) * sin(latitude)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
|
||
longitude = normalizeLongitude(longitude) | ||
|
||
return Location(toDegree(latitude), toDegree(longitude)) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
} | ||
|
||
private fun toRadian(coordinate: Double): Double { | ||
return coordinate * Math.PI / 180.0 | ||
} | ||
|
||
private fun toDegree(coordinate: Double): Double { | ||
return coordinate * 180.0 / Math.PI | ||
} | ||
private fun normalizeLongitude(longitude: Double): Double { | ||
return (longitude + 540) % 360 - 180 | ||
} | ||
|
||
data class Location( | ||
var longitude:Double, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
var latitude: Double | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
package com.cheajib.cheajibserver.domain.restaurant.presentation | ||
|
||
import com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response.MapRestaurantListResponse | ||
import com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response.QueryRestaurantMapListResponse | ||
import com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response.QueryRestaurantInfoResponse | ||
import com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response.QueryRestaurantResponse | ||
import com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response.QueryRestaurantReviewResponse | ||
import com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response.RestaurantDetailsResponse | ||
import com.cheajib.cheajibserver.domain.restaurant.service.QueryRestaurantDetailsService | ||
import com.cheajib.cheajibserver.domain.restaurant.service.QueryRestaurantMapListService | ||
import com.cheajib.cheajibserver.domain.restaurant.service.QueryRestaurantInfoService | ||
import com.cheajib.cheajibserver.domain.restaurant.service.QueryRestaurantPreviewService | ||
import com.cheajib.cheajibserver.domain.restaurant.service.QueryRestaurantReviewService | ||
import com.cheajib.cheajibserver.domain.user.domain.type.Level | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import java.util.UUID | ||
|
||
@RequestMapping("/restaurants") | ||
|
@@ -20,6 +25,7 @@ class RestaurantController( | |
private val queryRestaurantPreviewService: QueryRestaurantPreviewService, | ||
private val queryRestaurantDetailsService: QueryRestaurantDetailsService, | ||
private val queryRestaurantReviewService: QueryRestaurantReviewService, | ||
private val queryRestaurantMapListService: QueryRestaurantMapListService | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
private val queryRestaurantInfoService: QueryRestaurantInfoService | ||
) { | ||
|
||
|
@@ -47,6 +53,20 @@ class RestaurantController( | |
return queryRestaurantReviewService.execute(restaurantId) | ||
} | ||
|
||
@GetMapping("/lists") | ||
fun queryRestaurantMapList( | ||
@RequestParam(required = false) | ||
x: Double, | ||
@RequestParam(required = false) | ||
y: Double, | ||
@RequestParam(required = false) | ||
level: Level, | ||
@RequestParam(required = false) | ||
star: Int | ||
): QueryRestaurantMapListResponse { | ||
return queryRestaurantMapListService.execute(x, y, level, star) | ||
} | ||
|
||
@GetMapping("/info/{restaurant-id}") | ||
fun queryRestaurantInfo( | ||
@PathVariable("restaurant-id") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response | ||
|
||
import com.cheajib.cheajibserver.domain.user.domain.type.Level | ||
import java.util.UUID | ||
|
||
data class MapRestaurantListResponse( | ||
val id: UUID, | ||
val name: String, | ||
val level: Level | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response | ||
|
||
data class QueryRestaurantMapListResponse( | ||
val restaurantList: List<MapRestaurantListResponse> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.cheajib.cheajibserver.domain.restaurant.service | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
|
||
import com.cheajib.cheajibserver.domain.restaurant.domain.Restaurant | ||
import com.cheajib.cheajibserver.domain.restaurant.domain.type.Direction | ||
import com.cheajib.cheajibserver.domain.restaurant.facade.RestaurantFacade | ||
import com.cheajib.cheajibserver.domain.restaurant.facade.RestaurantFacade.* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
import com.cheajib.cheajibserver.domain.restaurant.presentation.dto.response.QueryRestaurantMapListResponse | ||
import com.cheajib.cheajibserver.domain.user.domain.type.Level | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.lang.String | ||
import javax.persistence.EntityManager | ||
|
||
@Service | ||
class QueryRestaurantMapListService( | ||
private val restaurantFacade: RestaurantFacade, | ||
private val em: EntityManager | ||
) { | ||
|
||
@Transactional(readOnly = true) | ||
fun execute(x: Double, y: Double, level: Level, star: Int): QueryRestaurantMapListResponse { | ||
val northEast: Location = restaurantFacade.getCoordinatesCalculate(x, y, distance = 123.1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
bearing = Direction.NORTHEAST.bearing | ||
) | ||
|
||
val southWest: Location = restaurantFacade.getCoordinatesCalculate(x, y, distance = 12324.1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
bearing = Direction.SOUTHWEST.bearing | ||
) | ||
|
||
val x1: Double = northEast.latitude | ||
val y1: Double = northEast.longitude | ||
val x2: Double = southWest.longitude | ||
val y2: Double = southWest.longitude | ||
|
||
val pointFormat = String.format("'LINESTRING(%f %f, %f %f)')", x1, y1, x2, y2) | ||
val query = em.createNativeQuery( | ||
"SELECT r.id, r.address, r.cordinates, r.mainImageUrl, r.imageUrl, r.isVerify" | ||
+ "FROM restaurant AS r " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
+ "WHERE MBRContains(ST_LINESTRINGFROMTEXT(" + pointFormat + ", r.point)", Restaurant::class.java | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π« [ktlint] reported by reviewdog πΆ |
||
) | ||
.setMaxResults(10) | ||
|
||
val restaurants: QueryRestaurantMapListResponse = query.resultList | ||
return restaurants | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.cheajib.cheajibserver | ||
|
||
import com.cheajib.cheajibserver.domain.restaurant.domain.Restaurant | ||
import com.cheajib.cheajibserver.domain.restaurant.domain.repository.RestaurantRepository | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.locationtech.jts.geom.Point | ||
import org.locationtech.jts.io.WKTReader | ||
import org.mockito.Mock | ||
import java.lang.String.format | ||
import java.util.* | ||
|
||
class QueryRestaurantMapList( | ||
@Mock | ||
private val restaurantRepository: RestaurantRepository | ||
) { | ||
|
||
@ParameterizedTest | ||
fun λ μ€ν λ_νλ_μ μ₯(name: String, url: String, address: String, uuid: UUID) { | ||
val latitude: Double = 37.51435 | ||
val longitude: Double = 127.1234 | ||
|
||
val pointWKT = format("POINT(%s %s)", longitude, latitude) | ||
|
||
val point = WKTReader().read(pointWKT) as Point | ||
|
||
val restaurant: Restaurant = Restaurant( | ||
id = uuid, | ||
name = name, | ||
address = address, | ||
coordinates = point, | ||
mainImageUrl = url, | ||
imageUrl = url, | ||
isVerify = true | ||
) | ||
|
||
val restaurantSave = restaurantRepository.save(restaurant) | ||
|
||
assertThat(restaurantSave.name).isEqualTo("restaurant") | ||
} | ||
} |
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.
π« [ktlint] reported by reviewdog πΆ
Unexpected blank line(s) before "}"