Skip to content
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

Hotfix | #81 | @YongsHub | v1.0.1 출시 위해 Query Transform 리팩토링 #88

Merged
merged 10 commits into from
Feb 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException
import java.sql.SQLException
import kotlin.RuntimeException

@RestControllerAdvice
class GlobalControllerAdvice {
Expand Down Expand Up @@ -59,4 +60,13 @@ class GlobalControllerAdvice {
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ApiResponse.error(ReturnCode.INTERNAL_SERVER_ERROR))
}

@ExceptionHandler(
value = [RuntimeException::class]
)
fun handleBusinessException(e: RuntimeException): ResponseEntity<ApiResponse<Unit>> {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ApiResponse.error(ReturnCode.INTERNAL_SERVER_ERROR))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.lovebird.api.dto.request.diary.DiaryListRequest
import com.lovebird.api.dto.request.diary.DiaryUpdateRequest
import com.lovebird.api.dto.response.diary.DiaryDetailResponse
import com.lovebird.api.dto.response.diary.DiaryListResponse
import com.lovebird.api.dto.response.diary.DiarySimpleListResponse
import com.lovebird.api.dto.response.diary.DiarySimpleResponse
import com.lovebird.api.service.diary.DiaryService
import com.lovebird.common.response.ApiResponse
import com.lovebird.domain.entity.User
Expand Down Expand Up @@ -39,14 +39,14 @@ class DiaryController(
fun findAllByMemoryDate(
@AuthorizedUser user: User,
@ModelAttribute request: DiaryListRequest.SearchByMemoryDateRequest
): ApiResponse<DiarySimpleListResponse> {
): ApiResponse<DiarySimpleResponse> {
return ApiResponse.success(diaryService.findAllByMemoryDate(request, user))
}

@GetMapping
fun findAll(
@AuthorizedUser user: User
): ApiResponse<DiarySimpleListResponse> {
): ApiResponse<DiarySimpleResponse> {
return ApiResponse.success(diaryService.findAll(user))
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lovebird.api.dto.response.diary

import com.lovebird.domain.dto.query.DiaryResponseParam

data class DiarySimpleResponse(
Copy link
Contributor

Choose a reason for hiding this comment

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

갑자기 네이밍을 바꾸신 특별한 이유가 있으실까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DiaryResponse와 DiarySimpleResponse의 return value들이 기존에 달랐던걸 인지하지 못하고 통합해버려서 원래대로 다시 분리했습니다!

val diaries: List<DiaryResponseParam>,
val totalCount: Int = diaries.size
) {
companion object {
fun of(diaries: List<DiaryResponseParam>): DiarySimpleResponse {
return DiarySimpleResponse(diaries)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.lovebird.api.dto.param.diary.DiaryUpdateParam
import com.lovebird.api.dto.request.diary.DiaryListRequest
import com.lovebird.api.dto.response.diary.DiaryDetailResponse
import com.lovebird.api.dto.response.diary.DiaryListResponse
import com.lovebird.api.dto.response.diary.DiarySimpleListResponse
import com.lovebird.api.dto.response.diary.DiarySimpleResponse
import com.lovebird.api.util.DiaryUtils.decryptDiaries
import com.lovebird.api.util.DiaryUtils.decryptDiariesOfSimple
import com.lovebird.api.util.DiaryUtils.decryptDiary
Expand All @@ -14,7 +14,6 @@ import com.lovebird.api.util.DiaryUtils.encryptDiaryUpdateParam
import com.lovebird.common.enums.DiarySearchType
import com.lovebird.domain.dto.query.DiaryListRequestParam
import com.lovebird.domain.dto.query.DiaryResponseParam
import com.lovebird.domain.dto.query.DiarySimpleResponseParam
import com.lovebird.domain.entity.CoupleEntry
import com.lovebird.domain.entity.Diary
import com.lovebird.domain.entity.User
Expand Down Expand Up @@ -78,25 +77,26 @@ class DiaryService(
}

@Transactional(readOnly = true)
fun findAll(user: User): DiarySimpleListResponse {
fun findAll(user: User): DiarySimpleResponse {
val coupleEntry: CoupleEntry? = coupleEntryReader.findByUser(user)
val partner: User? = coupleEntry?.partner
val diaries: List<DiarySimpleResponseParam> = diaryReader.findAll(user.id!!, partner?.id)

val diaries: List<DiaryResponseParam> = diaryReader.findAll(user.id!!, partner?.id)

decryptDiariesOfSimple(diaries)

return DiarySimpleListResponse.of(diaries)
return DiarySimpleResponse.of(diaries)
}

@Transactional(readOnly = true)
fun findAllByMemoryDate(request: DiaryListRequest.SearchByMemoryDateRequest, user: User): DiarySimpleListResponse {
fun findAllByMemoryDate(request: DiaryListRequest.SearchByMemoryDateRequest, user: User): DiarySimpleResponse {
val coupleEntry: CoupleEntry? = coupleEntryReader.findByUser(user)
val partner: User? = coupleEntry?.partner
val diaries: List<DiarySimpleResponseParam> = diaryReader.findAllByMemoryDate(request.toParam(user.id!!, partner?.id))
val diaries: List<DiaryResponseParam> = diaryReader.findAllByMemoryDate(request.toParam(user.id!!, partner?.id))

decryptDiariesOfSimple(diaries)

return DiarySimpleListResponse.of(diaries)
return DiarySimpleResponse.of(diaries)
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.lovebird.api.dto.param.diary.DiaryUpdateParam
import com.lovebird.api.provider.AesEncryptProvider.decryptString
import com.lovebird.api.provider.AesEncryptProvider.encryptString
import com.lovebird.domain.dto.query.DiaryResponseParam
import com.lovebird.domain.dto.query.DiarySimpleResponseParam
import com.lovebird.domain.entity.Diary

object DiaryUtils {
Expand All @@ -18,7 +17,7 @@ object DiaryUtils {
}
}

fun decryptDiariesOfSimple(diaries: List<DiarySimpleResponseParam>) {
fun decryptDiariesOfSimple(diaries: List<DiaryResponseParam>) {
diaries.forEach {
it.title = decryptString(it.title)
it.place = it.place?.let { place -> decryptString(place) }
Expand Down
Loading
Loading