Skip to content

Commit

Permalink
chore: api
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongho1209 committed May 27, 2024
1 parent 029aad7 commit 605e5bd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
11 changes: 2 additions & 9 deletions src/main/kotlin/com/trip/safe/review/domain/ReviewRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,9 @@ interface ReviewRepository : CoroutineCrudRepository<Review, Long> {
FROM review AS r
INNER JOIN user AS u
ON r.user_id = u.id
WHERE r.travel_destination_id = :travelDestinationId AND r.user_id = :userId AND r.is_deleted = false
WHERE r.user_id = :userId AND r.is_deleted = false
ORDER BY created_date DESC
LIMIT :limit
OFFSET :offset
"""
)
suspend fun findAllByUserAndTravelDestinationId(
travelDestinationId: Long,
userId: Long,
limit: Int,
offset: Long,
): Flux<ReviewElement>
suspend fun findAllByUser(userId: Long): Flux<ReviewElement>
}
31 changes: 5 additions & 26 deletions src/main/kotlin/com/trip/safe/review/service/ReviewService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.trip.safe.review.service

import com.trip.safe.common.error.exception.BadRequestException
import com.trip.safe.common.error.exception.ForbiddenException
import com.trip.safe.common.security.SecurityFacade
import com.trip.safe.review.domain.Review
Expand All @@ -24,11 +23,6 @@ class ReviewService(
private val reviewRepository: ReviewRepository,
private val securityFacade: SecurityFacade,
) {
companion object {
private const val MY = "my"
private const val ALL = "all"
}

suspend fun createReview(request: CreateReviewRequest, travelDestinationId: Long) {
val user = securityFacade.getCurrentUser()
val travelDestination = travelDestinationRepository.findById(travelDestinationId)
Expand Down Expand Up @@ -88,26 +82,11 @@ class ReviewService(
pageable: Pageable,
): ReviewListResponse {
val user = securityFacade.getCurrentUser()
val reviewList = when (type) {
MY -> {
reviewRepository.findAllByTravelDestinationId(
travelDestinationId = travelDestinationId,
limit = pageable.pageSize,
offset = pageable.offset,
)
}

ALL -> {
reviewRepository.findAllByUserAndTravelDestinationId(
travelDestinationId = travelDestinationId,
userId = user.id,
limit = pageable.pageSize,
offset = pageable.offset,
)
}

else -> throw BadRequestException(BadRequestException.BAD_REQUEST)
}.collectList().awaitSingle()
val reviewList = reviewRepository.findAllByTravelDestinationId(
travelDestinationId = travelDestinationId,
limit = pageable.pageSize,
offset = pageable.offset,
).collectList().awaitSingle()

val travelDestination = travelDestinationRepository.findById(travelDestinationId)
?: throw TravelDestinationNotFoundException(TravelDestinationNotFoundException.TRAVEL_DESTINATION_NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.trip.safe.user.presentation.dto.response

import com.trip.safe.review.presentation.dto.response.ReviewElement

data class MyInfoResponse(
val accountId: String,
val age: Short
val age: Short,
val reviewList: List<ReviewElement>,
)
9 changes: 8 additions & 1 deletion src/main/kotlin/com/trip/safe/user/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.trip.safe.user.service

import com.trip.safe.common.security.SecurityFacade
import com.trip.safe.common.security.jwt.JwtTokenProvider
import com.trip.safe.review.domain.ReviewRepository
import com.trip.safe.user.domain.User
import com.trip.safe.user.domain.UserRepository
import com.trip.safe.user.exception.PasswordMisMatchException
Expand All @@ -11,6 +12,7 @@ import com.trip.safe.user.presentation.dto.request.UserSignInRequest
import com.trip.safe.user.presentation.dto.request.UserSignUpRequest
import com.trip.safe.user.presentation.dto.response.MyInfoResponse
import com.trip.safe.user.presentation.dto.response.TokenResponse
import kotlinx.coroutines.reactive.awaitSingle
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service

Expand All @@ -20,6 +22,7 @@ class UserService(
private val jwtTokenProvider: JwtTokenProvider,
private val passwordEncoder: PasswordEncoder,
private val securityFacade: SecurityFacade,
private val reviewRepository: ReviewRepository,
) {

suspend fun signUp(request: UserSignUpRequest): TokenResponse {
Expand Down Expand Up @@ -52,9 +55,13 @@ class UserService(
suspend fun getMyInfo(): MyInfoResponse {
val user = securityFacade.getCurrentUser()

val reviewList = reviewRepository.findAllByUser(user.id)
.collectList().awaitSingle()

return MyInfoResponse(
accountId = user.accountId,
age = user.age
age = user.age,
reviewList = reviewList
)
}
}

0 comments on commit 605e5bd

Please sign in to comment.