Skip to content

Commit

Permalink
Hotfix | #81 | @YongsHub | v1.0.1 출시 위해 Query Transform 리팩토링
Browse files Browse the repository at this point in the history
* fix: QueryDSL Config 수정

* refactor: Diary 쿼리 transform 변경 및 DTO 생성 방법 리팩토링

* refactor: 쿼리 변경으로 인한 로직 리팩토링

* test: DTO 변경으로 인한 테스트 코드 수정

* refactor: ktlint 적용

* refactor: DiarySimpleResponse로 리팩토링

* test: 유저의 다이어리 전체 조회 및 날짜별 조회 리팩토링

* refactor: ktlint 적용

* feat: Business Exception 추가

* refactor: ktlint 적용
  • Loading branch information
YongsHub authored Feb 29, 2024
1 parent 1c268a1 commit d0cac56
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 194 deletions.
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(
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

0 comments on commit d0cac56

Please sign in to comment.