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

release(매핑 스타일 리팩토링, DDD스러운 코드): 1.2.3 #285

Merged
merged 41 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
81d9532
chore: (#278) value 패키지 추가
khcho0125 Jan 4, 2023
13d1bab
refactor: (#278) 상수로 명시
khcho0125 Jan 4, 2023
7b987c1
style: (#278) Enum 코드 컨벤션 위반
khcho0125 Jan 4, 2023
8721dba
feat: (#278) spot name, location & team name unique 컬럼
khcho0125 Jan 4, 2023
35c5fcb
refactor: (#278) 메서드 참조 지향
khcho0125 Jan 4, 2023
ace522b
refactor: (#278) saveAll 반환 값 추가
khcho0125 Jan 4, 2023
8f5c8d3
refactor: (#287) Exception 교체
khcho0125 Jan 4, 2023
d0af305
docs: (#278) 누락된 Javadoc 추가
khcho0125 Jan 4, 2023
9a94952
add: (#278) mapNonNull 확장함수
khcho0125 Jan 4, 2023
4f0a9ff
refactor: (#278) mapNotNull → mapNonNull 변경
khcho0125 Jan 4, 2023
25d944c
chore: (#278) 패키지 이동
khcho0125 Jan 4, 2023
72f13d2
revert: (#278) 파트 이름 중복 허용
khcho0125 Jan 4, 2023
cb34d18
chore: (#278) Import 제거...
khcho0125 Jan 4, 2023
d4dd1a6
revert: (#278) 확장함수 제거
khcho0125 Jan 5, 2023
03d7354
feat: (#278) toDomainNotNull 메서드 추가
khcho0125 Jan 5, 2023
6e98d14
refactor: (#278) toDomainNotNull 적용
khcho0125 Jan 5, 2023
75c7b74
revert: (#278) saveAll 반환 값 제거
khcho0125 Jan 5, 2023
b0d77af
merge: (#278) 코드 스타일 리팩토링 (#279)
khcho0125 Jan 5, 2023
9d947b7
chore: (#280) value 패키지 이동
khcho0125 Jan 5, 2023
bb15885
add: (#280) 요청 값 객체 추가
khcho0125 Jan 5, 2023
6e6294b
refactor: (#280) 변경사항 적용
khcho0125 Jan 5, 2023
0cabbdd
revert: (#280) 정규표현식 유틸리티 제거
khcho0125 Jan 5, 2023
c2d36d5
refactor: (#280) 누락된 부분 추가
khcho0125 Jan 5, 2023
df3d716
refactor: (#280) 정규식 최소, 최대 길이 분리
khcho0125 Jan 6, 2023
528793c
style: (#280) 상수 명 변경
khcho0125 Jan 6, 2023
90d6f95
refactor: (#280) value 객체 Length & Range 유효성 검사
khcho0125 Jan 6, 2023
bcced18
chore: (#280) value 객체 패키지 이동
khcho0125 Jan 6, 2023
32da710
build: (#280) dev redis properties 환경변수 적용
khcho0125 Jan 6, 2023
e3ac774
feat: (#280) IllegalArgumentException 예외 메시지 처리
khcho0125 Jan 6, 2023
bde33d8
refactor: (#280) Closeable use 사용 - FileConverter
khcho0125 Jan 6, 2023
61d8c56
refactor: (#280) Closeable use 사용 - ExcelFileAdapter
khcho0125 Jan 6, 2023
80efb61
refactor: (#280) 정규식 안 상수
khcho0125 Jan 7, 2023
cedbbe7
revert: (#280) Length 제거
khcho0125 Jan 7, 2023
e8724c0
revert: (#280) 로그인 유효성 검사 되돌리기
khcho0125 Jan 7, 2023
3438da2
refactor: (#283) 불필요한 예외 핸들링 삭제
softpeanut Jan 7, 2023
96ce3df
fix: (#283) 넓은 범위의 예외 삭제
softpeanut Jan 7, 2023
7d45488
refactor: (#283) TypeMismatchException 예외 메시지 구체화
softpeanut Jan 7, 2023
5421ce6
chore: (#283) 버전 명시
softpeanut Jan 7, 2023
3e04f04
merge: (#280) 요청 값 객체 추가 (#282)
khcho0125 Jan 7, 2023
a5a7347
Merge branch 'develop' into feature/283-validate-localdate
softpeanut Jan 8, 2023
3163002
merge: (#283) LocalDateTime 예외 처리 (#284)
softpeanut Jan 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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