diff --git a/src/main/kotlin/com/hh2/katj/history/component/KakaoApiManager.kt b/src/main/kotlin/com/hh2/katj/history/component/KakaoApiManager.kt index 3048a359..2186586c 100644 --- a/src/main/kotlin/com/hh2/katj/history/component/KakaoApiManager.kt +++ b/src/main/kotlin/com/hh2/katj/history/component/KakaoApiManager.kt @@ -1,6 +1,9 @@ package com.hh2.katj.history.component -import com.hh2.katj.user.model.dto.KakaoAddressSearchResponse +import com.hh2.katj.history.model.dto.KakaoAddressSearchResponse +import com.hh2.katj.history.model.dto.KakaoRouteSearchResponse +import com.hh2.katj.trip.model.DepartureRoadAddress +import com.hh2.katj.trip.model.DestinationRoadAddress import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -30,11 +33,10 @@ class KakaoApiManager( return response } - fun requestCarDirectionSearch(origin: String?, destination: String?): KakaoAddressSearchResponse? { - // TODO 형식 검사 - // ${X좌표},${Y좌표},name=${출발지명} 또는 ${X좌표},${Y좌표} - checkNotNull(origin) - checkNotNull(destination) + fun requestCarDirectionSearch(departureRoadAddress: DepartureRoadAddress, + destinationRoadAddress: DestinationRoadAddress): KakaoRouteSearchResponse? { + val origin = "${departureRoadAddress.departureLongitude},${departureRoadAddress.departureLatitude}" + val destination = "${destinationRoadAddress.destinationLongitude},${destinationRoadAddress.destinationLatitude}" val uri = kakaoUriBuilder.buildUriByCarDirectionSearch(origin, destination) val headers = HttpHeaders() @@ -42,7 +44,7 @@ class KakaoApiManager( val httpEntity = HttpEntity(headers) - return restTemplate.exchange(uri, HttpMethod.GET, httpEntity, KakaoAddressSearchResponse::class.java).body + return restTemplate.exchange(uri, HttpMethod.GET, httpEntity, KakaoRouteSearchResponse::class.java).body } } diff --git a/src/main/kotlin/com/hh2/katj/history/component/RouteHistoryManager.kt b/src/main/kotlin/com/hh2/katj/history/component/RouteHistoryManager.kt new file mode 100644 index 00000000..b4f2f7a2 --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/history/component/RouteHistoryManager.kt @@ -0,0 +1,18 @@ +package com.hh2.katj.history.component + +import com.hh2.katj.history.model.entity.SearchRouteHistory +import com.hh2.katj.history.repository.RouteHistoryRepository +import org.springframework.stereotype.Component +import org.springframework.transaction.annotation.Transactional + +@Component +class RouteHistoryManager( + private val routeHistoryRepository: RouteHistoryRepository, +) { + + @Transactional + fun addRouteHistory(routeHistory: SearchRouteHistory): SearchRouteHistory { + val history = routeHistoryRepository.save(routeHistory) + return history + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hh2/katj/history/controller/LocationHistoryController.kt b/src/main/kotlin/com/hh2/katj/history/controller/LocationHistoryController.kt index 2fb1dd50..652fc600 100644 --- a/src/main/kotlin/com/hh2/katj/history/controller/LocationHistoryController.kt +++ b/src/main/kotlin/com/hh2/katj/history/controller/LocationHistoryController.kt @@ -17,8 +17,11 @@ class LocationHistoryController( private val userService: UserService, ) { + /** + * 검색어로 위치정보(RoadAddress) 검색 및 이력 저장 + */ @PostMapping - fun saveLocation(@RequestBody request: RequestLocationHistory): ResponseEntity { + fun addLocationHistory(@RequestBody request: RequestLocationHistory): ResponseEntity { val user = userService.findByUserId(userId = request.userId) val response = locationHistoryService.saveLocationHistory(user, request.keyword) return ResponseEntity.ok(response) diff --git a/src/main/kotlin/com/hh2/katj/history/controller/RouteHistoryController.kt b/src/main/kotlin/com/hh2/katj/history/controller/RouteHistoryController.kt new file mode 100644 index 00000000..5d0a5b18 --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/history/controller/RouteHistoryController.kt @@ -0,0 +1,36 @@ +package com.hh2.katj.history.controller + +import com.hh2.katj.history.model.dto.RequestRouteHistory +import com.hh2.katj.history.model.dto.Summary +import com.hh2.katj.history.service.RouteHistoryService +import com.hh2.katj.user.service.UserService +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RequestMapping("/route") +@RestController +class RouteHistoryController( + private val routeHistoryService: RouteHistoryService, + private val userService: UserService, +) { + + /** + * 출/도착 정보로 택시 요금 조회 및 이력 저장 + */ + @PostMapping + fun addRouteHistory( + @RequestBody requestRouteHistory: RequestRouteHistory, + ): ResponseEntity { + val findUser = userService.findByUserId(requestRouteHistory.userId) + val summary = + routeHistoryService.addRouteHistory( + findUser.id, + requestRouteHistory.toEntity(findUser) + ) + return ResponseEntity.ok(summary) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hh2/katj/user/model/dto/KakaoAddressSearchResponse.kt b/src/main/kotlin/com/hh2/katj/history/model/dto/KakaoAddressSearchResponse.kt similarity index 98% rename from src/main/kotlin/com/hh2/katj/user/model/dto/KakaoAddressSearchResponse.kt rename to src/main/kotlin/com/hh2/katj/history/model/dto/KakaoAddressSearchResponse.kt index 8b8c41e9..a9d61340 100644 --- a/src/main/kotlin/com/hh2/katj/user/model/dto/KakaoAddressSearchResponse.kt +++ b/src/main/kotlin/com/hh2/katj/history/model/dto/KakaoAddressSearchResponse.kt @@ -1,4 +1,4 @@ -package com.hh2.katj.user.model.dto +package com.hh2.katj.history.model.dto import com.fasterxml.jackson.annotation.JsonProperty import com.hh2.katj.util.model.RoadAddress diff --git a/src/main/kotlin/com/hh2/katj/history/model/dto/KakaoRouteSearchResponse.kt b/src/main/kotlin/com/hh2/katj/history/model/dto/KakaoRouteSearchResponse.kt new file mode 100644 index 00000000..0923d50e --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/history/model/dto/KakaoRouteSearchResponse.kt @@ -0,0 +1,35 @@ +package com.hh2.katj.history.model.dto + +import com.fasterxml.jackson.annotation.JsonProperty + +data class KakaoRouteSearchResponse( + @JsonProperty("trans_id") + val transId: String, + @JsonProperty("routes") + val routes: List, +) + +data class Routes( + @JsonProperty("result_code") + val resultCode: Int, + @JsonProperty("result_msg") + val resultMsg: String, + @JsonProperty("summary") + val summary: Summary, +) + +data class Summary( + @JsonProperty("fare") + val fare: Fare, + @JsonProperty("distance") + val distance: Int, + @JsonProperty("duration") + val duration: Int, +) + +data class Fare( + @JsonProperty("taxi") + val taxiFare: Int, + @JsonProperty("toll") + val tollFare: Int, +) diff --git a/src/main/kotlin/com/hh2/katj/history/model/dto/RequestRouteHistory.kt b/src/main/kotlin/com/hh2/katj/history/model/dto/RequestRouteHistory.kt new file mode 100644 index 00000000..40c2bb8a --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/history/model/dto/RequestRouteHistory.kt @@ -0,0 +1,20 @@ +package com.hh2.katj.history.model.dto + +import com.hh2.katj.history.model.entity.SearchRouteHistory +import com.hh2.katj.trip.model.DepartureRoadAddress +import com.hh2.katj.trip.model.DestinationRoadAddress +import com.hh2.katj.user.model.entity.User + +data class RequestRouteHistory( + val userId: Long, + val departureRoadAddress: DepartureRoadAddress, + val destinationRoadAddress: DestinationRoadAddress, +) { + fun toEntity(user: User): SearchRouteHistory { + return SearchRouteHistory( + user = user, + departureRoadAddress = departureRoadAddress, + destinationRoadAddress = destinationRoadAddress, + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hh2/katj/history/model/entity/SearchRouteHistory.kt b/src/main/kotlin/com/hh2/katj/history/model/entity/SearchRouteHistory.kt new file mode 100644 index 00000000..087a4df8 --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/history/model/entity/SearchRouteHistory.kt @@ -0,0 +1,33 @@ +package com.hh2.katj.history.model.entity + +import com.hh2.katj.trip.model.DepartureRoadAddress +import com.hh2.katj.trip.model.DestinationRoadAddress +import com.hh2.katj.user.model.entity.User +import com.hh2.katj.util.model.BaseEntity +import jakarta.persistence.* + +@Entity +@Table(name = "search_route_history") +class SearchRouteHistory( + user: User, + departureRoadAddress: DepartureRoadAddress, + destinationRoadAddress: DestinationRoadAddress, +) : BaseEntity() { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false, + foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT) + ) + var user = user + protected set + + @Embedded + @Column(nullable = false) + var departureRoadAddress = departureRoadAddress + protected set + + @Embedded + @Column(nullable = false) + var destinationRoadAddress = destinationRoadAddress + protected set +} \ No newline at end of file diff --git a/src/main/kotlin/com/hh2/katj/history/repository/RouteHistoryRepository.kt b/src/main/kotlin/com/hh2/katj/history/repository/RouteHistoryRepository.kt new file mode 100644 index 00000000..8ebad66b --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/history/repository/RouteHistoryRepository.kt @@ -0,0 +1,7 @@ +package com.hh2.katj.history.repository + +import com.hh2.katj.history.model.entity.SearchRouteHistory +import org.springframework.data.jpa.repository.JpaRepository + +interface RouteHistoryRepository : JpaRepository { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hh2/katj/history/service/LocationHistoryService.kt b/src/main/kotlin/com/hh2/katj/history/service/LocationHistoryService.kt index 404a05b7..3add6c48 100644 --- a/src/main/kotlin/com/hh2/katj/history/service/LocationHistoryService.kt +++ b/src/main/kotlin/com/hh2/katj/history/service/LocationHistoryService.kt @@ -20,7 +20,7 @@ class LocationHistoryService( // TODO 예외 메시지 checkNotNull(response) { "api 호출 오류" } check(response.documents.isNotEmpty()) { - failWithMessage(ExceptionMessage.NO_SEARCH_LOCATION_RESULT.name) + failWithMessage(ExceptionMessage.NO_SEARCH_RESULT.name) } val roadAddress = response.documents[0].roadAddress diff --git a/src/main/kotlin/com/hh2/katj/history/service/RouteHistoryService.kt b/src/main/kotlin/com/hh2/katj/history/service/RouteHistoryService.kt new file mode 100644 index 00000000..af614914 --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/history/service/RouteHistoryService.kt @@ -0,0 +1,39 @@ +package com.hh2.katj.history.service + +import com.hh2.katj.history.component.KakaoApiManager +import com.hh2.katj.history.component.RouteHistoryManager +import com.hh2.katj.history.model.dto.KakaoRouteSearchResponse +import com.hh2.katj.history.model.dto.Summary +import com.hh2.katj.history.model.entity.SearchRouteHistory +import com.hh2.katj.user.service.UserService +import com.hh2.katj.util.exception.ExceptionMessage +import com.hh2.katj.util.exception.failWithMessage +import org.springframework.stereotype.Service + +@Service +class RouteHistoryService( + private val kakaoApiManager: KakaoApiManager, + private val routeHistoryManager: RouteHistoryManager, + private val userService: UserService, +) { + + fun addRouteHistory(userId: Long, routeHistory: SearchRouteHistory): Summary { + val validatedUser = userService.userValidationCheck(userId) + userService.userStatusActiveCheck(validatedUser) + + val response = kakaoApiManager.requestCarDirectionSearch( + routeHistory.departureRoadAddress, + routeHistory.destinationRoadAddress + ) + + checkNotNull(response) { "api 호출 오류" } + check(response.routes.isNotEmpty()) { + failWithMessage(ExceptionMessage.NO_SEARCH_RESULT.name) + } + + routeHistoryManager.addRouteHistory(routeHistory) + + return response.routes[0].summary + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hh2/katj/util/exception/ExceptionMessage.kt b/src/main/kotlin/com/hh2/katj/util/exception/ExceptionMessage.kt index 80cfe03c..8de6c42c 100644 --- a/src/main/kotlin/com/hh2/katj/util/exception/ExceptionMessage.kt +++ b/src/main/kotlin/com/hh2/katj/util/exception/ExceptionMessage.kt @@ -6,7 +6,7 @@ enum class ExceptionMessage(message: String, status: Int) { USER_DOES_NOT_EXIST("user does not exist", 400), INTERNAL_SERVER_ERROR_FROM_DATABASE("internal server error from database", 500), INCORRECT_STATUS_VALUE("incorrect status value", 500), - NO_SEARCH_LOCATION_RESULT("no search results", 400), + NO_SEARCH_RESULT("no search results", 400), NO_SUCH_VALUE_EXISTS("no such value exists", 400), INVALID_PAYMENT_METHOD("invalid payment method", 500), } \ No newline at end of file diff --git a/src/test/kotlin/com/hh2/katj/favorite/service/FavoriteServiceTest.kt b/src/test/kotlin/com/hh2/katj/favorite/service/FavoriteServiceTest.kt index 4c8b988c..9fcea202 100644 --- a/src/test/kotlin/com/hh2/katj/favorite/service/FavoriteServiceTest.kt +++ b/src/test/kotlin/com/hh2/katj/favorite/service/FavoriteServiceTest.kt @@ -39,7 +39,7 @@ class FavoriteServiceTest ( @Test fun `사용자가 경로를 즐겨찾기에 추가한다`() { // given - val roadAddress: RoadAddress = RoadAddress( + val roadAddress = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -54,7 +54,7 @@ class FavoriteServiceTest ( latitude = "y.321", ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -63,7 +63,7 @@ class FavoriteServiceTest ( roadAddress = roadAddress ) - val favorite: Favorite = Favorite( + val favorite = Favorite( user = user, roadAddress = roadAddress, title = "favorite_title", @@ -72,7 +72,7 @@ class FavoriteServiceTest ( // when val saveUser = userRepository.save(user) - val requestAddFavorite: RequestAddFavorite = RequestAddFavorite( + val requestAddFavorite = RequestAddFavorite( roadAddress = roadAddress, title = favorite.title, description = favorite.description, @@ -92,7 +92,7 @@ class FavoriteServiceTest ( fun `사용자가 같은 타이틀의 즐겨찾기를 추가하려고 하면 오류가 발생한다`() { // given - val roadAddress: RoadAddress = RoadAddress( + val roadAddress = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -107,7 +107,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -116,7 +116,7 @@ class FavoriteServiceTest ( roadAddress = roadAddress ) - val favorite: Favorite = Favorite( + val favorite = Favorite( user = user, roadAddress = roadAddress, title = "favorite_title", @@ -124,7 +124,7 @@ class FavoriteServiceTest ( ) val saveUser = userRepository.save(user) - val requestAddFavorite: RequestAddFavorite = RequestAddFavorite( + val requestAddFavorite = RequestAddFavorite( roadAddress = roadAddress, title = favorite.title, description = favorite.description, @@ -134,13 +134,13 @@ class FavoriteServiceTest ( favoriteService.addFavorite(requestAddFavorite.toEntity(saveUser)) // when - val duplicatedFavorite: Favorite = Favorite( + val duplicatedFavorite = Favorite( user = user, roadAddress = roadAddress, title = "favorite_title", description = "favorite_duplicated_description" ) - val requestDuplicatedFavorite: RequestAddFavorite = RequestAddFavorite( + val requestDuplicatedFavorite = RequestAddFavorite( roadAddress = roadAddress, title = duplicatedFavorite.title, description = duplicatedFavorite.description, @@ -158,7 +158,7 @@ class FavoriteServiceTest ( @Test fun `사용자가 등록한 즐겨찾기 중 하나만 선택하여 조회한다`() { // given - val roadAddressA: RoadAddress = RoadAddress( + val roadAddressA = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -173,7 +173,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -183,7 +183,7 @@ class FavoriteServiceTest ( ) - val roadAddressB: RoadAddress = RoadAddress( + val roadAddressB = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -198,14 +198,14 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val favoriteA: Favorite = Favorite( + val favoriteA = Favorite( user = user, roadAddress = roadAddressA, title = "favorite_titleA", description = "favorite_descriptionA" ) - val favoriteB: Favorite = Favorite( + val favoriteB = Favorite( user = user, roadAddress = roadAddressB, title = "favorite_titleB", @@ -215,13 +215,13 @@ class FavoriteServiceTest ( // when val saveUser = userRepository.save(user) - val requestAddFavoriteA: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteA = RequestAddFavorite( roadAddress = roadAddressA, title = favoriteA.title, description = favoriteA.description, id = null, ) - val requestAddFavoriteB: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteB = RequestAddFavorite( roadAddress = roadAddressB, title = favoriteB.title, description = favoriteB.description, @@ -246,7 +246,7 @@ class FavoriteServiceTest ( @Test fun `사용자가 즐겨찾기를 전부 조회한다`() { // given - val roadAddressA: RoadAddress = RoadAddress( + val roadAddressA = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -261,7 +261,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -271,7 +271,7 @@ class FavoriteServiceTest ( ) - val roadAddressB: RoadAddress = RoadAddress( + val roadAddressB = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -286,14 +286,14 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val favoriteA: Favorite = Favorite( + val favoriteA = Favorite( user = user, roadAddress = roadAddressA, title = "favorite_titleA", description = "favorite_descriptionA" ) - val favoriteB: Favorite = Favorite( + val favoriteB = Favorite( user = user, roadAddress = roadAddressB, title = "favorite_titleB", @@ -303,13 +303,13 @@ class FavoriteServiceTest ( // when val saveUser = userRepository.save(user) - val requestAddFavoriteA: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteA = RequestAddFavorite( roadAddress = roadAddressA, title = favoriteA.title, description = favoriteA.description, id = null, ) - val requestAddFavoriteB: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteB = RequestAddFavorite( roadAddress = roadAddressB, title = favoriteB.title, description = favoriteB.description, @@ -340,7 +340,7 @@ class FavoriteServiceTest ( @Test fun `사용자가 즐겨찾기 정보를 수정한다`() { // given - val roadAddress: RoadAddress = RoadAddress( + val roadAddress = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -355,7 +355,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -364,7 +364,7 @@ class FavoriteServiceTest ( roadAddress = roadAddress ) - val favorite: Favorite = Favorite( + val favorite = Favorite( user = user, roadAddress = roadAddress, title = "favorite_title", @@ -372,7 +372,7 @@ class FavoriteServiceTest ( ) val saveUser = userRepository.save(user) - val requestAddFavorite: RequestAddFavorite = RequestAddFavorite( + val requestAddFavorite = RequestAddFavorite( roadAddress = roadAddress, title = favorite.title, description = favorite.description, @@ -383,7 +383,7 @@ class FavoriteServiceTest ( val savedFavorite = favoriteRepository.findByTitle(requestAddFavorite.title) ?: failWithMessage(ID_DOES_NOT_EXIST.name) // when - val newRoadAddress: RoadAddress = RoadAddress( + val newRoadAddress = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -417,7 +417,7 @@ class FavoriteServiceTest ( @Test fun `사용자가 즐겨찾기 하나를 삭제한다`() { // given - val roadAddressA: RoadAddress = RoadAddress( + val roadAddressA = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -432,7 +432,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -442,7 +442,7 @@ class FavoriteServiceTest ( ) - val roadAddressB: RoadAddress = RoadAddress( + val roadAddressB = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -457,14 +457,14 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val favoriteA: Favorite = Favorite( + val favoriteA = Favorite( user = user, roadAddress = roadAddressA, title = "favorite_titleA", description = "favorite_descriptionA" ) - val favoriteB: Favorite = Favorite( + val favoriteB = Favorite( user = user, roadAddress = roadAddressB, title = "favorite_titleB", @@ -474,13 +474,13 @@ class FavoriteServiceTest ( // when val saveUser = userRepository.save(user) - val requestAddFavoriteA: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteA = RequestAddFavorite( roadAddress = roadAddressA, title = favoriteA.title, description = favoriteA.description, id = null, ) - val requestAddFavoriteB: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteB = RequestAddFavorite( roadAddress = roadAddressB, title = favoriteB.title, description = favoriteB.description, @@ -513,7 +513,7 @@ class FavoriteServiceTest ( @Test fun `사용자가 즐겨찾기를 전부 삭제한다`() { // given - val roadAddressA: RoadAddress = RoadAddress( + val roadAddressA = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -528,7 +528,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -538,7 +538,7 @@ class FavoriteServiceTest ( ) - val roadAddressB: RoadAddress = RoadAddress( + val roadAddressB = RoadAddress( addressName = "address_name", region1depthName = "r_1", region2depthName = "r_2", @@ -553,14 +553,14 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val favoriteA: Favorite = Favorite( + val favoriteA = Favorite( user = user, roadAddress = roadAddressA, title = "favorite_titleA", description = "favorite_descriptionA" ) - val favoriteB: Favorite = Favorite( + val favoriteB = Favorite( user = user, roadAddress = roadAddressB, title = "favorite_titleB", @@ -570,13 +570,13 @@ class FavoriteServiceTest ( // when val saveUser = userRepository.save(user) - val requestAddFavoriteA: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteA = RequestAddFavorite( roadAddress = roadAddressA, title = favoriteA.title, description = favoriteA.description, id = null, ) - val requestAddFavoriteB: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteB = RequestAddFavorite( roadAddress = roadAddressB, title = favoriteB.title, description = favoriteB.description, @@ -603,7 +603,7 @@ class FavoriteServiceTest ( @Test fun `사용자가 선택한 여러개의 즐겨찾기를 삭제한다`() { // given - val roadAddressA: RoadAddress = RoadAddress( + val roadAddressA = RoadAddress( addressName = "address_nameA", region1depthName = "r_1", region2depthName = "r_2", @@ -618,7 +618,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val user: User = User( + val user = User( name = "newUser", phoneNumber = "123-456-789", email = "user@gmail.com", @@ -628,7 +628,7 @@ class FavoriteServiceTest ( ) - val roadAddressB: RoadAddress = RoadAddress( + val roadAddressB = RoadAddress( addressName = "address_nameB", region1depthName = "r_1", region2depthName = "r_2", @@ -643,7 +643,7 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val roadAddressC: RoadAddress = RoadAddress( + val roadAddressC = RoadAddress( addressName = "address_nameC", region1depthName = "r_1", region2depthName = "r_2", @@ -658,21 +658,21 @@ class FavoriteServiceTest ( latitude = "y.321" ) - val favoriteA: Favorite = Favorite( + val favoriteA = Favorite( user = user, roadAddress = roadAddressA, title = "favorite_titleA", description = "favorite_descriptionA" ) - val favoriteB: Favorite = Favorite( + val favoriteB = Favorite( user = user, roadAddress = roadAddressB, title = "favorite_titleB", description = "favorite_descriptionB" ) - val favoriteC: Favorite = Favorite( + val favoriteC = Favorite( user = user, roadAddress = roadAddressC, title = "favorite_titleC", @@ -682,19 +682,19 @@ class FavoriteServiceTest ( // when val saveUser = userRepository.save(user) - val requestAddFavoriteA: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteA = RequestAddFavorite( roadAddress = roadAddressA, title = favoriteA.title, description = favoriteA.description, id = null, ) - val requestAddFavoriteB: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteB = RequestAddFavorite( roadAddress = roadAddressB, title = favoriteB. title, description = favoriteB.description, id = null, ) - val requestAddFavoriteC: RequestAddFavorite = RequestAddFavorite( + val requestAddFavoriteC = RequestAddFavorite( roadAddress = roadAddressC, title = favoriteC.title, description = favoriteC.description, @@ -720,7 +720,4 @@ class FavoriteServiceTest ( assertThat(afterDeleteFavorites).hasSize(1) assertThat(deleteResult).isTrue() } - - - } \ No newline at end of file diff --git a/src/test/kotlin/com/hh2/katj/history/service/LocationHistoryServiceTest.kt b/src/test/kotlin/com/hh2/katj/history/service/LocationHistoryServiceTest.kt index 6e6bd345..e4344402 100644 --- a/src/test/kotlin/com/hh2/katj/history/service/LocationHistoryServiceTest.kt +++ b/src/test/kotlin/com/hh2/katj/history/service/LocationHistoryServiceTest.kt @@ -1,13 +1,13 @@ package com.hh2.katj.history.service import com.hh2.katj.history.repository.LocationHistoryRepository -import com.hh2.katj.util.model.Gender import com.hh2.katj.user.model.entity.User import com.hh2.katj.user.model.entity.UserStatus import com.hh2.katj.user.repository.UserRepository import com.hh2.katj.util.annotation.KATJTestContainerE2E import com.hh2.katj.util.exception.ExceptionMessage import com.hh2.katj.util.model.BaseTestEnitity +import com.hh2.katj.util.model.Gender import com.hh2.katj.util.model.RoadAddress import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach @@ -52,7 +52,7 @@ class LocationHistoryServiceTest( assertThrows { locationHistoryService.saveLocationHistory(saveUser, keyword = "법원단지5가길 76555") }.apply { - assertThat(message).isEqualTo(ExceptionMessage.NO_SEARCH_LOCATION_RESULT.name) + assertThat(message).isEqualTo(ExceptionMessage.NO_SEARCH_RESULT.name) } } diff --git a/src/test/kotlin/com/hh2/katj/history/service/RouteHistoryServiceTest.kt b/src/test/kotlin/com/hh2/katj/history/service/RouteHistoryServiceTest.kt new file mode 100644 index 00000000..eaaf73a4 --- /dev/null +++ b/src/test/kotlin/com/hh2/katj/history/service/RouteHistoryServiceTest.kt @@ -0,0 +1,102 @@ +package com.hh2.katj.history.service + +import com.hh2.katj.history.model.entity.SearchRouteHistory +import com.hh2.katj.trip.model.DepartureRoadAddress +import com.hh2.katj.trip.model.DestinationRoadAddress +import com.hh2.katj.user.model.entity.User +import com.hh2.katj.user.model.entity.UserStatus +import com.hh2.katj.user.repository.UserRepository +import com.hh2.katj.util.annotation.KATJTestContainerE2E +import com.hh2.katj.util.model.BaseTestEnitity +import com.hh2.katj.util.model.Gender +import com.hh2.katj.util.model.RoadAddress +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +@KATJTestContainerE2E +class RouteHistoryServiceTest( + private val routeHistoryService: RouteHistoryService, + private val userRepository: UserRepository, +) : BaseTestEnitity() { + + @Test + fun `출도착 정보로 택시 요금 조회`() { + // given + val roadAddress = RoadAddress( + addressName = "서울 관악구 법원단지5가길 76", + region1depthName = "서울", + region2depthName = "관악구", + region3depthName = "신림동", + roadName = "법원단지5가길", + undergroundYn = "N", + mainBuildingNo = "76", + subBuildingNo = "", + buildingName = "대명아트빌", + zoneNo = "08852", + longitude = "126.923157313768", + latitude = "37.4764786774284", + ) + + val departureRoadAddress = DepartureRoadAddress( + departureAddressName = "서울 관악구 법원단지5가길 76", + departureRegion1depthName = "서울", + departureRegion2depthName = "관악구", + departureRegion3depthName = "신림동", + departureRoadName = "법원단지5가길", + departureUndergroundYn = "N", + departureMainBuildingNo = "76", + departureSubBuildingNo = "", + departureBuildingName = "대명아트빌", + departureZoneNo = "08852", + departureLongitude = "126.923157313768", + departureLatitude = "37.4764786774284", + ) + + val destinationRoadAddress = DestinationRoadAddress( + destinationAddressName = "서울 중구 세종대로 110", + destinationRegion1depthName = "서울", + destinationRegion2depthName = "중구", + destinationRegion3depthName = "태평로1가", + destinationRoadName = "세종대로", + destinationUndergroundYn = "N", + destinationMainBuildingNo = "76", + destinationSubBuildingNo = "", + destinationBuildingName = "서울특별시청", + destinationZoneNo = "04524", + destinationLongitude = "126.977829174031", + destinationLatitude = "37.5663174209601", + ) + + val user = User( + name = "탁지성", + phoneNumber = "010-3253-5576", + email = "user@gmail.com", + gender = Gender.MALE, + status = UserStatus.ACTIVE, + roadAddress = roadAddress, + ) + + val routeHistory = SearchRouteHistory( + user = user, + departureRoadAddress = departureRoadAddress, + destinationRoadAddress = destinationRoadAddress, + ) + + // when + val saveUser = userRepository.save(user) + val summary = routeHistoryService.addRouteHistory(saveUser.id, routeHistory) + + // then + assertThat(summary.fare.taxiFare).isGreaterThan(0) + } + + @Test + fun `API 호출 실패시 예외 반환`() { + // given + + // when + + // then + + } +} \ No newline at end of file