Skip to content

Commit

Permalink
release(매핑 스타일 리팩토링, DDD스러운 코드): 1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut authored Jan 8, 2023
2 parents 62c721b + 3163002 commit cc7031a
Show file tree
Hide file tree
Showing 56 changed files with 325 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import team.comit.simtong.domain.file.model.EmployeeCertificate
*
* @author Chokyunghyeon
* @date 2022/12/06
* @version 1.0.0
* @version 1.2.3
**/
interface CommandEmployeeCertificatePort {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import team.comit.simtong.domain.holiday.model.Holiday
* @author Chokyunghyeon
* @author kimbeomjin
* @date 2022/12/03
* @version 1.0.0
* @version 1.2.3
**/
interface CommandHolidayPort {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.time.LocalDate
*
* @author Chokyunghyeon
* @date 2022/12/22
* @version 1.0.0
* @version 1.2.3
**/
@ReadOnlyUseCase
class CheckHolidayPeriodUseCase(
Expand All @@ -28,7 +28,7 @@ class CheckHolidayPeriodUseCase(
?: throw UserExceptions.NotFound()

if (!queryHolidayPeriodPort.existsHolidayPeriodByWithinPeriodAndSpotId(LocalDate.now(), user.spotId)) {
throw HolidayExceptions.NotFound("휴무표 작성 기간이 아닙니다.")
throw HolidayExceptions.NotWritablePeriod()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import team.comit.simtong.domain.menu.model.Menu
*
* @author kimbeomjin
* @date 2022/12/10
* @version 1.0.0
* @version 1.2.3
**/
interface CommandMenuPort {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import team.comit.simtong.domain.notification.model.NotificationReceiver
*
* @author kimbeomjin
* @date 2022/12/30
* @version 1.1.0
* @version 1.2.3
**/
interface CommandNotificationPort {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CheckHolidayPeriodUseCaseTests {
.willReturn(false)

// when & then
assertThrows<HolidayExceptions.NotFound> {
assertThrows<HolidayExceptions.NotWritablePeriod> {
checkHolidayPeriodUseCase.execute()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestControllerAdvice
import team.comit.simtong.global.error.dto.ErrorResponse
import team.comit.simtong.global.exception.GlobalExceptions

/**
*
* 전체적으로 발생하는 예외를 핸들링하는 GlobalErrorHandler
*
* @author kimbeomjin
* @date 2022/08/22
* @version 1.0.0
* @version 1.2.3
**/
@RestControllerAdvice
class GlobalErrorHandler {
Expand All @@ -29,13 +28,4 @@ class GlobalErrorHandler {
): ErrorResponse? {
return ErrorResponse.of(exception)
}

/**
* 적합하지 않거나 적절하지 못한 인자를 메서드에 넘기면 발생
*/
@ExceptionHandler(IllegalArgumentException::class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
protected fun handleIllegalArgumentException(exception: IllegalArgumentException): ErrorResponse? {
return ErrorResponse.of(GlobalExceptions.BadRequest())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import javax.validation.ConstraintViolationException
* @author kimbeomjin
* @author Chokyunghyeon
* @date 2022/08/22
* @version 1.0.0
* @version 1.2.3
**/
@RestControllerAdvice
class WebErrorHandler {
Expand Down Expand Up @@ -72,15 +72,6 @@ class WebErrorHandler {
return ErrorResponse.of(exception)
}

/**
* 적합하지 않거나 적절하지 못한 인자를 메서드에 넘기면 발생
*/
@ExceptionHandler(IllegalArgumentException::class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
protected fun handleIllegalArgumentException(exception: IllegalArgumentException): ErrorResponse? {
return ErrorResponse.of(GlobalExceptions.BadRequest())
}

/**
* 지원하지 않은 HTTP method 호출할 경우 발생
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import javax.validation.ConstraintViolationException
* 예외가 발생했을 경우 response 형태를 일관되게 유지하기 위한 ErrorResponse
*
* @author kimbeomjin
* @author Chokyunghyeon
* @date 2022/08/22
* @version 1.0.0
* @version 1.2.3
**/
class ErrorResponse(
val status: Int,
Expand Down Expand Up @@ -57,7 +58,11 @@ class ErrorResponse(

fun of(exception: MethodArgumentTypeMismatchException): ErrorResponse {
val value = exception.value
val fieldErrors = CustomFieldError.of(exception.name, value.toString(), exception.errorCode)
val fieldErrors = CustomFieldError.of(
field = exception.parameter.parameterName ?: "",
value = value.toString(),
reason = "${exception.requiredType!!.name} 타입으로 변환할 수 없습니다."
)

return of(
exception = GlobalExceptions.BadRequest(),
Expand All @@ -66,7 +71,7 @@ class ErrorResponse(
}

fun of(exception: MissingServletRequestParameterException): ErrorResponse {
val fieldErrors = CustomFieldError.of(exception.parameterName, "", exception.message)
val fieldErrors = CustomFieldError.of(exception.parameterName, "", exception.message ?: "")

return of(
exception = GlobalExceptions.BadRequest(),
Expand All @@ -79,6 +84,11 @@ class ErrorResponse(
fieldErrors = CustomFieldError.of("", "", exception.message ?: "")
)

fun of(exception: IllegalArgumentException): ErrorResponse = of(
exception = GlobalExceptions.BadRequest(),
fieldErrors = CustomFieldError.of("", "", exception.message ?: "")
)

private fun of(exception: BusinessException, fieldErrors: List<CustomFieldError>) = ErrorResponse(
status = exception.status,
message = exception.message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package team.comit.simtong.global.exception

/**
*
* GlobalExceptions
* 애플리케이션에서 발생하는 예외를 관리하는 GlobalExceptions
*
* @author kimbeomjin
* @author Chokyunghyeon
* @date 2022/12/17
* @version 1.0.0
* @version 1.2.3
**/
sealed class GlobalExceptions(
override val status: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.comit.simtong.persistence
package team.comit.simtong.global.extension

import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.core.types.dsl.DatePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ package team.comit.simtong.persistence
*
* @author Chokyunghyeon
* @date 2022/09/04
* @version 1.0.0
* @version 1.2.3
**/
interface GenericMapper<E, D> {

fun toEntity(model: D): E

fun toDomain(entity: E?): D?

fun toDomainNotNull(entity: E): D
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import team.comit.simtong.persistence.auth.repository.AuthCodeLimitRepository
* @author Chokyunghyeon
* @author kimbeomjin
* @date 2022/09/09
* @version 1.0.0
* @version 1.2.3
**/
@Component
class AuthCodeLimitPersistenceAdapter(
Expand All @@ -30,7 +30,7 @@ class AuthCodeLimitPersistenceAdapter(
override fun save(authCodeLimit: AuthCodeLimit): AuthCodeLimit {
return authCodeLimitRepository.save(
authCodeLimitMapper.toEntity(authCodeLimit)
).let { authCodeLimitMapper.toDomain(it)!! }
).let(authCodeLimitMapper::toDomainNotNull)
}

override fun delete(authCodeLimit: AuthCodeLimit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import team.comit.simtong.persistence.auth.repository.AuthCodeRepository
*
* @author Chokyunghyeon
* @date 2022/09/25
* @version 1.0.0
* @version 1.2.3
**/
@Component
class AuthCodePersistenceAdapter(
Expand All @@ -29,7 +29,7 @@ class AuthCodePersistenceAdapter(
override fun save(authCode: AuthCode): AuthCode {
return authCodeRepository.save(
authCodeMapper.toEntity(authCode)
).let { authCodeMapper.toDomain(it)!! }
).let(authCodeMapper::toDomainNotNull)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import team.comit.simtong.persistence.file.mapper.EmployeeCertificateMapper
*
* @author Chokyunghyeon
* @date 2022/12/06
* @version 1.0.0
* @version 1.2.3
**/
@Component
class EmployeeCertificatePersistenceAdapter(
Expand All @@ -26,7 +26,9 @@ class EmployeeCertificatePersistenceAdapter(
return employeeCertificateJpaRepository.existsByNameAndEmployeeNumber(name, employeeNumber)
}

override fun saveAll(employeeCertificates: List<EmployeeCertificate>) {
override fun saveAll(
employeeCertificates: List<EmployeeCertificate>
) {
employeeCertificateJpaRepository.saveAll(
employeeCertificates.map(employeeCertificateMapper::toEntity)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.util.UUID
*
* @author Chokyunghyeon
* @date 2022/12/20
* @version 1.0.1
* @version 1.2.3
**/
@Component
class HolidayPeriodPersistenceAdapter(
Expand Down Expand Up @@ -50,7 +50,7 @@ class HolidayPeriodPersistenceAdapter(
override fun save(holidayPeriod: HolidayPeriod): HolidayPeriod {
return holidayPeriodJpaRepository.save(
holidayPeriodMapper.toEntity(holidayPeriod)
).let { holidayPeriodMapper.toDomain(it)!! }
).let(holidayPeriodMapper::toDomain)!!
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package team.comit.simtong.persistence.holiday

import team.comit.simtong.persistence.holiday.entity.QHolidayJpaEntity.holidayJpaEntity as holiday
import team.comit.simtong.persistence.user.entity.QUserJpaEntity.userJpaEntity as user
import team.comit.simtong.persistence.spot.entity.QSpotJpaEntity.spotJpaEntity as spot
import team.comit.simtong.persistence.team.entity.QTeamJpaEntity.teamJpaEntity as team
import team.comit.simtong.persistence.user.entity.QUserJpaEntity.userJpaEntity as user
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.data.repository.findByIdOrNull
Expand All @@ -13,8 +13,8 @@ import team.comit.simtong.domain.holiday.model.HolidayStatus
import team.comit.simtong.domain.holiday.model.HolidayType
import team.comit.simtong.domain.holiday.spi.HolidayPort
import team.comit.simtong.domain.holiday.spi.vo.EmployeeHoliday
import team.comit.simtong.persistence.QuerydslExtensionUtils.or
import team.comit.simtong.persistence.QuerydslExtensionUtils.sameWeekFilter
import team.comit.simtong.global.extension.QuerydslExtensionUtils.or
import team.comit.simtong.global.extension.QuerydslExtensionUtils.sameWeekFilter
import team.comit.simtong.persistence.holiday.entity.HolidayJpaEntity
import team.comit.simtong.persistence.holiday.mapper.HolidayMapper
import team.comit.simtong.persistence.holiday.repository.HolidayJpaRepository
Expand All @@ -29,7 +29,7 @@ import java.util.UUID
* @author Chokyunghyeon
* @author kimbeomjin
* @date 2022/12/02
* @version 1.0.0
* @version 1.2.3
**/
@Component
class HolidayPersistenceAdapter(
Expand Down Expand Up @@ -83,7 +83,7 @@ class HolidayPersistenceAdapter(
)
.orderBy(holiday.id.date.asc())
.fetch()
.map { holidayMapper.toDomain(it)!! }
.map(holidayMapper::toDomainNotNull)
}

override fun queryHolidaysByYearAndMonthAndTeamId(
Expand Down Expand Up @@ -134,7 +134,7 @@ class HolidayPersistenceAdapter(
holiday.status.eq(HolidayStatus.WRITTEN)
)
.fetch()
.map { holidayMapper.toDomain(it)!! }
.map(holidayMapper::toDomainNotNull)
}

override fun existsHolidayByDateAndUserIdAndType(date: LocalDate, userId: UUID, type: HolidayType): Boolean {
Expand All @@ -150,7 +150,7 @@ class HolidayPersistenceAdapter(
override fun save(holiday: Holiday): Holiday {
return holidayJpaRepository.save(
holidayMapper.toEntity(holiday)
).let { holidayMapper.toDomain(it)!! }
).let(holidayMapper::toDomainNotNull)
}

override fun saveAll(holidays: List<Holiday>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import team.comit.simtong.persistence.user.repository.UserJpaRepository
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
* @version 1.2.3
**/
@Mapper
abstract class HolidayMapper : GenericMapper<HolidayJpaEntity, Holiday> {
Expand All @@ -34,6 +34,13 @@ abstract class HolidayMapper : GenericMapper<HolidayJpaEntity, Holiday> {
)
abstract override fun toDomain(entity: HolidayJpaEntity?): Holiday?

@Mappings(
Mapping(target = "userId", expression = "java(entity.getId().getUserId())"),
Mapping(target = "spotId", expression = "java(entity.getSpot().getId())"),
Mapping(target = "date", expression = "java(entity.getId().getDate())")
)
abstract override fun toDomainNotNull(entity: HolidayJpaEntity): Holiday

@Mappings(
Mapping(target = "user", expression = "java(userJpaRepository.findById(model.getUserId()).orElse(null))"),
Mapping(target = "spot", expression = "java(spotJpaRepository.findById(model.getSpotId()).orElse(null))"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import team.comit.simtong.persistence.spot.SpotJpaRepository
*
* @author Chokyunghyeon
* @date 2022/12/20
* @version 1.0.0
* @version 1.2.3
**/
@Mapper
abstract class HolidayPeriodMapper : GenericMapper<HolidayPeriodJpaEntity, HolidayPeriod> {
Expand All @@ -30,6 +30,13 @@ abstract class HolidayPeriodMapper : GenericMapper<HolidayPeriodJpaEntity, Holid
)
abstract override fun toDomain(entity: HolidayPeriodJpaEntity?): HolidayPeriod?

@Mappings(
Mapping(target = "spotId", expression = "java(entity.getId().getSpotId())"),
Mapping(target = "year", expression = "java(entity.getId().getYear())"),
Mapping(target = "month", expression = "java(entity.getId().getMonth())")
)
abstract override fun toDomainNotNull(entity: HolidayPeriodJpaEntity): HolidayPeriod

@Mappings(
Mapping(target = "id", expression = "java(new HolidayPeriodJpaEntity.Id(model.getYear(), model.getMonth(), model.getSpotId()))"),
Mapping(target = "spot", expression = "java(spotJpaRepository.findById(model.getSpotId()).orElse(null))")
Expand Down
Loading

0 comments on commit cc7031a

Please sign in to comment.