Skip to content
Open
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ dependencies {
runtimeOnly(Dependency.MYSQL)
implementation(Dependency.OPENFEIGN)
implementation(Dependency.JWT)
implementation(Dependency.HIBERNATE_SPATIAL)
testImplementation(Dependency.SPRING_TEST)

}

Expand Down
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/Dependency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ object Dependency {

// property
const val PROPERTIES_SCAN = "org.springframework.boot:spring-boot-configuration-processor"

// test
const val SPRING_TEST = "org.springframework.boot:spring-boot-starter-test:${PluginVersions.SPRING_BOOT_FRAMEWORK_VERSION}"

// hibernate
const val HIBERNATE_SPATIAL = "org.hibernate:hibernate-spatial:6.1.3.Final"

Copy link
Copy Markdown

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 "}"

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.cheajib.cheajibserver.infrastructure.aws.defaultImage.DefaultImage
import org.hibernate.annotations.ColumnDefault
import org.hibernate.annotations.DynamicInsert
import org.hibernate.validator.constraints.Length
import org.locationtech.jts.geom.Point
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Entity
Expand All @@ -27,10 +28,7 @@ class Restaurant(
val address: String,

@field: NotNull
val latitude: Double,

@field: NotNull
val longitude: Double,
val coordinates: Point,

@field: NotNull
val phoneNumber: String,
Expand Down
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
Expand Up @@ -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(
Expand All @@ -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) +

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline after "("

cos(radianLatitude) * sin(distanceRadius) * cos(radianAngle))

Copy link
Copy Markdown

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 indentation (16) (should be 12)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline before ")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline before ")"


var longitude: Double = radianLongitude + Math.atan2(sin(radianAngle) * sin(distanceRadius) *

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline after "("

cos(radianLatitude), cos(distanceRadius) - sin(radianLatitude) * sin(latitude))

Copy link
Copy Markdown

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 indentation (16) (should be 12)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline after ","

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline before ")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline before ")"


longitude = normalizeLongitude(longitude)

return Location(toDegree(latitude), toDegree(longitude))

Copy link
Copy Markdown

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 "}"

}

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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing spacing after ":"

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")
Expand All @@ -20,6 +25,7 @@ class RestaurantController(
private val queryRestaurantPreviewService: QueryRestaurantPreviewService,
private val queryRestaurantDetailsService: QueryRestaurantDetailsService,
private val queryRestaurantReviewService: QueryRestaurantReviewService,
private val queryRestaurantMapListService: QueryRestaurantMapListService

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Not a valid Kotlin file (28:77 expecting comma or ')') (cannot be auto-corrected)

private val queryRestaurantInfoService: QueryRestaurantInfoService
) {

Expand Down Expand Up @@ -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")
Expand Down
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
File must end with a newline (\n)


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.*

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Wildcard import (cannot be auto-corrected)

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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline after "("

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

bearing = Direction.NORTHEAST.bearing
)

val southWest: Location = restaurantFacade.getCoordinatesCalculate(x, y, distance = 12324.1,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Missing newline after "("

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Argument should be on a separate line (unless all arguments can fit a single line)

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 "

Copy link
Copy Markdown

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 indentation (20) (should be 16)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Line must not begin with "+"

+ "WHERE MBRContains(ST_LINESTRINGFROMTEXT(" + pointFormat + ", r.point)", Restaurant::class.java

Copy link
Copy Markdown

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 indentation (20) (should be 16)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] reported by reviewdog 🐢
Line must not begin with "+"

)
.setMaxResults(10)

val restaurants: QueryRestaurantMapListResponse = query.resultList
return restaurants
}


}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring:

jpa:
database: mysql
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
database-platform: org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect
hibernate:
ddl-auto: update
open-in-view: false
Expand Down
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")
}
}