Skip to content

Commit

Permalink
fix: entity serializing bug
Browse files Browse the repository at this point in the history
somehow entity was serialized instead of dto so lazy loading error was being occurred
  • Loading branch information
ShanePark committed Mar 8, 2025
1 parent cd434cb commit fdefb54
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class RestExceptionControllerAdvice {

@ResponseBody
@ExceptionHandler
fun notAuthorizedHandler(e: DutyparkAuthException): ResponseEntity<Any> {
fun notAuthorizedHandler(e: DutyparkAuthException): ResponseEntity<DutyParkErrorResponse> {
return ResponseEntity.status(e.errorCode)
.body(DutyParkErrorResponse.of(e))
}

@ExceptionHandler
fun noSuchElementHandler(e: NoSuchElementException): ResponseEntity<Any> {
fun noSuchElementHandler(e: NoSuchElementException): ResponseEntity<Void> {
log.warn("no such element: ${e.message}")
return ResponseEntity.status(404).build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class DutyParkErrorResponse(
val message: String,
) {
companion object {
fun of(e: DutyparkAuthException): Any? {
fun of(e: DutyparkAuthException): DutyParkErrorResponse {
return DutyParkErrorResponse(
errorCode = e.errorCode,
message = e.message ?: "Unknown Error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import net.gpedro.integrations.slack.SlackField
import net.gpedro.integrations.slack.SlackMessage
import org.apache.catalina.connector.ClientAbortException
import org.apache.coyote.CloseNowException
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.web.HttpRequestMethodNotSupportedException
import org.springframework.web.bind.annotation.ControllerAdvice
Expand All @@ -30,7 +28,7 @@ class ErrorDetectAdvisor(
fun handleMethodNotSupported(
req: HttpServletRequest,
e: HttpRequestMethodNotSupportedException
): ResponseEntity<Any> {
): ResponseEntity<Void> {
val requestURI = req.requestURI
if (!requestURI.equals("/")) {
log.info("MethodNotSupportedException ${e.message}, requestURI: $requestURI")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import com.tistory.shanepark.dutypark.member.domain.annotation.Login
import com.tistory.shanepark.dutypark.member.repository.MemberRepository
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import jakarta.validation.Valid
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
import org.springframework.data.domain.Pageable
import org.springframework.data.web.PageableDefault
Expand Down Expand Up @@ -82,18 +80,16 @@ class DepartmentAdminController(
fun changeManager(
@PathVariable id: Long,
@RequestParam memberId: Long?
): ResponseEntity<Any> {
) {
departmentService.changeManager(departmentId = id, memberId = memberId)
return ResponseEntity.ok().build()
}

@PatchMapping("/{id}/batch-template")
fun updateBatchTemplate(
@PathVariable id: Long,
@RequestParam(name = "templateName", required = false) dutyBatchTemplate: DutyBatchTemplate?
): ResponseEntity<Any> {
) {
departmentService.updateBatchTemplate(id, dutyBatchTemplate)
return ResponseEntity.ok().build()
}

@PostMapping("/{id}/duty")
Expand Down Expand Up @@ -127,27 +123,24 @@ class DepartmentAdminController(
@PathVariable id: Long,
@RequestParam color: String,
@RequestParam name: String,
): ResponseEntity<Any> {
) {
departmentService.updateDefaultDuty(id, name, color)
return ResponseEntity.ok().build()
}

@PostMapping("/{id}/members")
fun addMember(
@PathVariable id: Long,
@RequestParam memberId: Long
): ResponseEntity<Any> {
) {
departmentService.addMemberToDepartment(departmentId = id, memberId = memberId)
return ResponseEntity.ok().build()
}

@DeleteMapping("/{id}/members")
fun removeMember(
@PathVariable id: Long,
@RequestParam memberId: Long
): ResponseEntity<Any> {
) {
departmentService.removeMemberFromDepartment(id, memberId)
return ResponseEntity.ok().build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.tistory.shanepark.dutypark.duty.domain.dto.DutyTypeCreateDto
import com.tistory.shanepark.dutypark.duty.domain.dto.DutyTypeUpdateDto
import com.tistory.shanepark.dutypark.duty.service.DutyTypeService
import jakarta.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*

@RestController
Expand All @@ -15,27 +13,23 @@ class DutyTypeController(
) {

@PostMapping
fun addDutyType(@RequestBody @Valid dutyTypeCreateDto: DutyTypeCreateDto): ResponseEntity<Any> {
fun addDutyType(@RequestBody @Valid dutyTypeCreateDto: DutyTypeCreateDto) {
dutyTypeService.addDutyType(dutyTypeCreateDto)
return ResponseEntity.status(HttpStatus.CREATED).build()
}

@PatchMapping
fun updateDutyType(@RequestBody @Valid dutyTypeUpdateDto: DutyTypeUpdateDto): ResponseEntity<Any> {
fun updateDutyType(@RequestBody @Valid dutyTypeUpdateDto: DutyTypeUpdateDto) {
dutyTypeService.update(dutyTypeUpdateDto)
return ResponseEntity.status(HttpStatus.OK).build()
}

@PatchMapping("/swap-position")
fun swapDutyTypePosition(@RequestParam id1: Long, @RequestParam id2: Long): ResponseEntity<Any> {
fun swapDutyTypePosition(@RequestParam id1: Long, @RequestParam id2: Long) {
dutyTypeService.swapDutyTypePosition(id1, id2)
return ResponseEntity.ok().build()
}

@DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseEntity<Any> {
fun delete(@PathVariable id: Long) {
dutyTypeService.delete(id)
return ResponseEntity.status(HttpStatus.OK).build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tistory.shanepark.dutypark.member.controller

import com.tistory.shanepark.dutypark.common.slack.annotation.SlackNotification
import com.tistory.shanepark.dutypark.member.domain.annotation.Login
import com.tistory.shanepark.dutypark.member.domain.dto.DDayDto
import com.tistory.shanepark.dutypark.member.domain.dto.DDaySaveDto
import com.tistory.shanepark.dutypark.member.service.DDayService
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
Expand All @@ -21,55 +22,39 @@ class DDayController(
fun createDDay(
@Login member: LoginMember,
@Valid @RequestBody dDaySaveDto: DDaySaveDto
): ResponseEntity<Any> {
val createDDay = dDayService.createDDay(member, dDaySaveDto)

return ResponseEntity
.status(HttpStatus.CREATED)
.body(createDDay)
): DDayDto {
return dDayService.createDDay(member, dDaySaveDto)
}

@GetMapping
fun findDDays(@Login login: LoginMember): ResponseEntity<Any> {
val findDDays = dDayService.findDDays(login, login.id)

return ResponseEntity
.status(HttpStatus.OK)
.body(findDDays)
fun findDDays(@Login login: LoginMember): List<DDayDto> {
return dDayService.findDDays(login, login.id)
}

@GetMapping("/{id}")
fun findDDaysByMemberId(
@Login(required = false) member: LoginMember?,
@PathVariable id: Long
): ResponseEntity<Any> {
val findDDay = dDayService.findDDays(member, id)

return ResponseEntity
.status(HttpStatus.OK)
.body(findDDay)
): List<DDayDto> {
return dDayService.findDDays(member, id)
}


@DeleteMapping("/{id}")
fun deleteDDay(
@Login member: LoginMember,
@PathVariable id: Long
): ResponseEntity<Any> {
) {
dDayService.deleteDDay(member, id)

return ResponseEntity
.status(HttpStatus.NO_CONTENT)
.build()
}

@PutMapping("/{id}")
fun updateDDay(
@Login member: LoginMember,
@PathVariable id: Long,
@Valid @RequestBody dDaySaveDto: DDaySaveDto
): ResponseEntity<Any> {
val updateDDay = dDayService.updateDDay(
): ResponseEntity<Void> {
dDayService.updateDDay(
loginMember = member,
id = id,
title = dDaySaveDto.title,
Expand All @@ -78,7 +63,7 @@ class DDayController(
)
return ResponseEntity
.status(HttpStatus.OK)
.body(updateDDay)
.build()
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.tistory.shanepark.dutypark.member.service

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.exceptions.DutyparkAuthException
import com.tistory.shanepark.dutypark.member.domain.dto.DDayDto
import com.tistory.shanepark.dutypark.member.domain.dto.DDaySaveDto
import com.tistory.shanepark.dutypark.member.domain.entity.DDayEvent
import com.tistory.shanepark.dutypark.member.repository.DDayRepository
import com.tistory.shanepark.dutypark.member.repository.MemberRepository
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate
Expand All @@ -21,9 +18,7 @@ class DDayService(
private val dDayRepository: DDayRepository
) {

private val log = logger()

fun createDDay(loginMember: LoginMember, dDaySaveDto: DDaySaveDto): DDayEvent {
fun createDDay(loginMember: LoginMember, dDaySaveDto: DDaySaveDto): DDayDto {
val member = memberRepository.findById(loginMember.id).orElseThrow()

val dDayEvent = DDayEvent(
Expand All @@ -32,7 +27,8 @@ class DDayService(
date = dDaySaveDto.date,
isPrivate = dDaySaveDto.isPrivate,
)
return dDayRepository.save(dDayEvent)
dDayRepository.save(dDayEvent)
return DDayDto.of(dDayEvent)
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.tistory.shanepark.dutypark.schedule.service.ScheduleService
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import org.springframework.data.domain.Pageable
import org.springframework.data.web.PageableDefault
import org.springframework.http.ResponseEntity
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import java.time.YearMonth
Expand Down Expand Up @@ -51,10 +50,8 @@ class ScheduleController(
fun createSchedule(
@RequestBody @Validated scheduleUpdateDto: ScheduleUpdateDto,
@Login loginMember: LoginMember
): ResponseEntity<Any> {
) {
scheduleService.createSchedule(loginMember, scheduleUpdateDto)

return ResponseEntity.ok().build()
}

@PutMapping("/{id}")
Expand All @@ -63,19 +60,17 @@ class ScheduleController(
scheduleUpdateDto: ScheduleUpdateDto,
@Login loginMember: LoginMember,
@PathVariable id: UUID
): ResponseEntity<Any> {
) {
scheduleService.updateSchedule(loginMember, id, scheduleUpdateDto)
return ResponseEntity.ok().build()
}

@PatchMapping("/{id1}/position")
fun swapSchedulePosition(
@PathVariable id1: UUID,
@RequestParam id2: UUID,
@Login loginMember: LoginMember,
): ResponseEntity<Any> {
) {
scheduleService.swapSchedulePosition(loginMember, id1, id2)
return ResponseEntity.ok().build()
}

@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import com.tistory.shanepark.dutypark.security.domain.dto.PasswordChangeDto
import com.tistory.shanepark.dutypark.security.service.AuthService
import jakarta.servlet.http.HttpServletRequest
import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.*
Expand All @@ -27,7 +26,7 @@ class AuthController(
req: HttpServletRequest,
@RequestParam(name = "referer", required = false) urlReferer: String?,
@SessionAttribute(name = "referer", required = false) referer: String?
): ResponseEntity<Any> {
): ResponseEntity<String> {
var refererValue = urlReferer ?: referer ?: "/"
if (refererValue.contains("/login")) {
refererValue = "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class OAuthController(
@RequestParam(value = "state") stateString: String,
httpServletRequest: HttpServletRequest,
@Login(required = false) loginMember: LoginMember?
): ResponseEntity<Any> {
): ResponseEntity<Void> {
val state = objectMapper.readValue(stateString, Map::class.java)
val referer = (state["referer"] as String?) ?: "/"

Expand Down Expand Up @@ -61,7 +61,7 @@ class OAuthController(
@RequestParam(value = "username") username: String,
@RequestParam(value = "term_agree") termAgree: Boolean,
httpServletRequest: HttpServletRequest
): ResponseEntity<Any> {
): ResponseEntity<Void> {
if (!termAgree) {
return ResponseEntity.badRequest().build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import com.tistory.shanepark.dutypark.member.repository.MemberSsoRegisterReposit
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import com.tistory.shanepark.dutypark.security.service.AuthService
import jakarta.servlet.http.HttpServletRequest
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
Expand All @@ -29,7 +27,7 @@ class KakaoLoginService(
) {
private val log = logger()

fun login(req: HttpServletRequest, code: String, redirectUrl: String, referer: String): ResponseEntity<Any> {
fun login(req: HttpServletRequest, code: String, redirectUrl: String, referer: String): ResponseEntity<Void> {
val kakaoId = getKakaoId(redirectUrl, code)

val member = memberRepository.findMemberByKakaoId(kakaoId)
Expand Down

0 comments on commit fdefb54

Please sign in to comment.