Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 15, 2023
2 parents 6f3b454 + 576f651 commit 64499f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import com.example.onui.domain.diary.presentation.request.UpdateDiaryRequest
import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse
import com.example.onui.domain.diary.presentation.response.DiaryListResponse
import com.example.onui.domain.diary.service.DiaryService
import org.joda.time.LocalDate
import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import java.util.*
import javax.validation.Valid
import javax.validation.constraints.Max
import javax.validation.constraints.Min
Expand Down Expand Up @@ -38,9 +38,9 @@ class DiaryController(

@GetMapping("/detail")
fun getById(
@RequestParam("id", required = true)
id: UUID
): DiaryDetailResponse = diaryService.getDetailById(id)
@RequestParam("date", required = true)
date: String
): DiaryDetailResponse = diaryService.getDetailById(LocalDate.parse(date))

@PutMapping
fun updateDiary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import com.example.onui.domain.diary.presentation.request.CreateDiaryRequest
import com.example.onui.domain.diary.presentation.request.UpdateDiaryRequest
import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse
import com.example.onui.domain.diary.presentation.response.DiaryListResponse
import java.util.*
import org.joda.time.LocalDate

interface DiaryService {

fun createDiary(req: CreateDiaryRequest): DiaryDetailResponse

fun getDiaryByMonth(year: Int, month: Int): DiaryListResponse

fun getDetailById(id: UUID): DiaryDetailResponse
fun getDetailById(date: LocalDate): DiaryDetailResponse?

fun update(req: UpdateDiaryRequest): DiaryDetailResponse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import com.example.onui.domain.diary.repository.DiaryRepository
import com.example.onui.domain.diary.repository.QDiaryRepository
import com.example.onui.global.common.facade.UserFacade
import com.example.onui.global.config.error.exception.PermissionDeniedException
import org.joda.time.LocalDate
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime
import java.util.*

@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -50,13 +50,9 @@ class DiaryServiceImpl(
}?.toMutableList()
)

override fun getDetailById(id: UUID): DiaryDetailResponse {
val diary = diaryRepository.findByIdOrNull(id) ?: throw DiaryNotFoundException

if (diary.user != userFacade.getCurrentUser()) throw PermissionDeniedException

return diary.toDetailResponse()
}
override fun getDetailById(date: LocalDate): DiaryDetailResponse? = diaryRepository.findByUserAndYearAndMonthAndDay(
userFacade.getCurrentUser(), date.year, date.monthOfYear, date.dayOfMonth
)?.toDetailResponse()

@Transactional
override fun update(req: UpdateDiaryRequest): DiaryDetailResponse {
Expand Down

0 comments on commit 64499f2

Please sign in to comment.