From 433dc23fd5a3ae6359b89fb300e021643cf397c2 Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Thu, 17 Aug 2023 14:49:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#111=20refactor:=20user=20Domain=20isValid?= =?UTF-8?q?=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/psr/psr/user/dto/UserInterestDto.kt | 8 +++----- .../com/psr/psr/user/dto/assembler/UserAssembler.kt | 4 ++-- .../kotlin/com/psr/psr/user/dto/request/SignUpReq.kt | 4 ++++ src/main/kotlin/com/psr/psr/user/entity/Type.kt | 10 ++++------ .../kotlin/com/psr/psr/user/service/UserService.kt | 5 +++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/psr/psr/user/dto/UserInterestDto.kt b/src/main/kotlin/com/psr/psr/user/dto/UserInterestDto.kt index 17c252d..a49b03e 100644 --- a/src/main/kotlin/com/psr/psr/user/dto/UserInterestDto.kt +++ b/src/main/kotlin/com/psr/psr/user/dto/UserInterestDto.kt @@ -1,11 +1,9 @@ package com.psr.psr.user.dto +import com.psr.psr.global.resolver.EnumValid import com.psr.psr.user.entity.Category data class UserInterestDto ( + @EnumValid(enumClass = Category::class, message = "올바르지 않은 상품 카테고리입니다.") val category: String -){ - fun checkInterestCategory() : Category{ - return Category.getCategoryByName(category) - } -} \ No newline at end of file +) \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/user/dto/assembler/UserAssembler.kt b/src/main/kotlin/com/psr/psr/user/dto/assembler/UserAssembler.kt index fbf1b36..3e92672 100644 --- a/src/main/kotlin/com/psr/psr/user/dto/assembler/UserAssembler.kt +++ b/src/main/kotlin/com/psr/psr/user/dto/assembler/UserAssembler.kt @@ -30,7 +30,7 @@ class UserAssembler { fun toEntity(signUpReq: SignUpReq): User { return User(email = signUpReq.email, password = signUpReq.password, - type = Type.getTypeByName(signUpReq.type), + type = Type.getTypeByValue(signUpReq.type), phone = signUpReq.phone, imgUrl = signUpReq.imgUrl, provider = Provider.LOCAL, @@ -43,7 +43,7 @@ class UserAssembler { fun toInterestListEntity(user: User, signUpReq: SignUpReq): List { return signUpReq.interestList.stream() .map { i -> - UserInterest(category = Category.getCategoryByName(i.category), + UserInterest(category = Category.getCategoryByValue(i.category), user = user) }.collect(Collectors.toList()) } diff --git a/src/main/kotlin/com/psr/psr/user/dto/request/SignUpReq.kt b/src/main/kotlin/com/psr/psr/user/dto/request/SignUpReq.kt index d79c16d..508c234 100644 --- a/src/main/kotlin/com/psr/psr/user/dto/request/SignUpReq.kt +++ b/src/main/kotlin/com/psr/psr/user/dto/request/SignUpReq.kt @@ -1,6 +1,9 @@ package com.psr.psr.user.dto.request +import com.psr.psr.global.resolver.EnumValid import com.psr.psr.user.dto.UserInterestDto +import com.psr.psr.user.entity.Category +import com.psr.psr.user.entity.Type import jakarta.annotation.Nullable import jakarta.validation.constraints.Email import jakarta.validation.constraints.NotBlank @@ -20,6 +23,7 @@ data class SignUpReq ( ) var password: String, @field:NotBlank + @EnumValid(enumClass = Type::class, message = "올바르지 않은 사용자 역할니다.") val type: String, @field:Pattern( regexp = "^01([0|1|6|7|8|9])-?([0-9]{3,4})-?([0-9]{4})\$", diff --git a/src/main/kotlin/com/psr/psr/user/entity/Type.kt b/src/main/kotlin/com/psr/psr/user/entity/Type.kt index 56052d3..96d1df8 100644 --- a/src/main/kotlin/com/psr/psr/user/entity/Type.kt +++ b/src/main/kotlin/com/psr/psr/user/entity/Type.kt @@ -1,19 +1,17 @@ package com.psr.psr.user.entity -import com.psr.psr.global.exception.BaseException -import com.psr.psr.global.exception.BaseResponseCode +import com.psr.psr.global.resolver.EnumType -enum class Type(val value: String) { +enum class Type(override val value: String) : EnumType { GENERAL("일반"), ENTREPRENEUR("사업자"), SHOW_HOST("쇼호스트"), MANAGER("관리자"); companion object { - fun getTypeByName(name: String): Type { - return enumValues().find { it.value == name } - ?: throw BaseException(BaseResponseCode.INVALID_USER_TYPE_NAME) + fun getTypeByValue(value: String): Type { + return enumValues().find { it.value == value }!! } } } \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/user/service/UserService.kt b/src/main/kotlin/com/psr/psr/user/service/UserService.kt index b0f7ad9..9ea09a4 100644 --- a/src/main/kotlin/com/psr/psr/user/service/UserService.kt +++ b/src/main/kotlin/com/psr/psr/user/service/UserService.kt @@ -80,7 +80,8 @@ class UserService( // 회원가입 @Transactional fun signUp(signUpReq: SignUpReq): TokenDto { - val categoryCheck = signUpReq.interestList.stream().map { i -> i.checkInterestCategory() }.collect(Collectors.toList()).groupingBy { it }.eachCount().any { it.value > 1 } + // 중복 값 확인 + val categoryCheck = signUpReq.interestList.groupingBy { it }.eachCount().any { it.value > 1 } if(categoryCheck) throw BaseException(INVALID_USER_INTEREST_COUNT) // category 의 사이즈 확인 val listSize = signUpReq.interestList.size @@ -242,7 +243,7 @@ class UserService( // 관심 목록 변경 @Transactional fun patchWatchLists(user: User, userInterestListReq: UserInterestListDto) { - val reqLists = userInterestListReq.interestList!!.map { i -> Category.getCategoryByName(i.category) } + val reqLists = userInterestListReq.interestList!!.map { i -> Category.getCategoryByValue(i.category) } if(reqLists.isEmpty() || reqLists.size > 3) throw BaseException(INVALID_USER_INTEREST_COUNT) val userWatchLists = userInterestRepository.findByUserAndStatus(user, ACTIVE_STATUS) val categoryLists = userWatchLists.map { c -> c.category } From 7db61d7f344283f2fe7b73171a5e2f804b8ac859 Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Thu, 17 Aug 2023 14:50:45 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#111=20refactor:=20cs=20Domain=20response?= =?UTF-8?q?=20package=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/psr/psr/cs/controller/CsController.kt | 8 ++++---- .../com/psr/psr/cs/dto/assembler/CsAssembler.kt | 8 ++++---- .../com/psr/psr/cs/dto/{ => response}/FaqListRes.kt | 2 +- .../com/psr/psr/cs/dto/{ => response}/FaqRes.kt | 2 +- .../psr/psr/cs/dto/{ => response}/NoticeListRes.kt | 2 +- .../com/psr/psr/cs/dto/{ => response}/NoticeRes.kt | 2 +- src/main/kotlin/com/psr/psr/cs/service/CsService.kt | 12 ++++++------ 7 files changed, 18 insertions(+), 18 deletions(-) rename src/main/kotlin/com/psr/psr/cs/dto/{ => response}/FaqListRes.kt (61%) rename src/main/kotlin/com/psr/psr/cs/dto/{ => response}/FaqRes.kt (85%) rename src/main/kotlin/com/psr/psr/cs/dto/{ => response}/NoticeListRes.kt (65%) rename src/main/kotlin/com/psr/psr/cs/dto/{ => response}/NoticeRes.kt (93%) diff --git a/src/main/kotlin/com/psr/psr/cs/controller/CsController.kt b/src/main/kotlin/com/psr/psr/cs/controller/CsController.kt index ad0b322..0134b4e 100644 --- a/src/main/kotlin/com/psr/psr/cs/controller/CsController.kt +++ b/src/main/kotlin/com/psr/psr/cs/controller/CsController.kt @@ -1,9 +1,9 @@ package com.psr.psr.cs.controller -import com.psr.psr.cs.dto.FaqListRes -import com.psr.psr.cs.dto.FaqRes -import com.psr.psr.cs.dto.NoticeListRes -import com.psr.psr.cs.dto.NoticeRes +import com.psr.psr.cs.dto.response.FaqListRes +import com.psr.psr.cs.dto.response.FaqRes +import com.psr.psr.cs.dto.response.NoticeListRes +import com.psr.psr.cs.dto.response.NoticeRes import com.psr.psr.cs.service.CsService import com.psr.psr.global.dto.BaseResponse import org.springframework.web.bind.annotation.* diff --git a/src/main/kotlin/com/psr/psr/cs/dto/assembler/CsAssembler.kt b/src/main/kotlin/com/psr/psr/cs/dto/assembler/CsAssembler.kt index e948651..3153f1f 100644 --- a/src/main/kotlin/com/psr/psr/cs/dto/assembler/CsAssembler.kt +++ b/src/main/kotlin/com/psr/psr/cs/dto/assembler/CsAssembler.kt @@ -1,9 +1,9 @@ package com.psr.psr.cs.dto.assembler -import com.psr.psr.cs.dto.FaqListRes -import com.psr.psr.cs.dto.FaqRes -import com.psr.psr.cs.dto.NoticeListRes -import com.psr.psr.cs.dto.NoticeRes +import com.psr.psr.cs.dto.response.FaqListRes +import com.psr.psr.cs.dto.response.FaqRes +import com.psr.psr.cs.dto.response.NoticeListRes +import com.psr.psr.cs.dto.response.NoticeRes import com.psr.psr.cs.entity.Faq import com.psr.psr.cs.entity.Notice import org.springframework.stereotype.Component diff --git a/src/main/kotlin/com/psr/psr/cs/dto/FaqListRes.kt b/src/main/kotlin/com/psr/psr/cs/dto/response/FaqListRes.kt similarity index 61% rename from src/main/kotlin/com/psr/psr/cs/dto/FaqListRes.kt rename to src/main/kotlin/com/psr/psr/cs/dto/response/FaqListRes.kt index 1404a55..e3609bb 100644 --- a/src/main/kotlin/com/psr/psr/cs/dto/FaqListRes.kt +++ b/src/main/kotlin/com/psr/psr/cs/dto/response/FaqListRes.kt @@ -1,4 +1,4 @@ -package com.psr.psr.cs.dto +package com.psr.psr.cs.dto.response data class FaqListRes ( val faqLists: List? diff --git a/src/main/kotlin/com/psr/psr/cs/dto/FaqRes.kt b/src/main/kotlin/com/psr/psr/cs/dto/response/FaqRes.kt similarity index 85% rename from src/main/kotlin/com/psr/psr/cs/dto/FaqRes.kt rename to src/main/kotlin/com/psr/psr/cs/dto/response/FaqRes.kt index d77e52c..81e4703 100644 --- a/src/main/kotlin/com/psr/psr/cs/dto/FaqRes.kt +++ b/src/main/kotlin/com/psr/psr/cs/dto/response/FaqRes.kt @@ -1,4 +1,4 @@ -package com.psr.psr.cs.dto +package com.psr.psr.cs.dto.response import com.fasterxml.jackson.annotation.JsonInclude diff --git a/src/main/kotlin/com/psr/psr/cs/dto/NoticeListRes.kt b/src/main/kotlin/com/psr/psr/cs/dto/response/NoticeListRes.kt similarity index 65% rename from src/main/kotlin/com/psr/psr/cs/dto/NoticeListRes.kt rename to src/main/kotlin/com/psr/psr/cs/dto/response/NoticeListRes.kt index a0ca727..9d92900 100644 --- a/src/main/kotlin/com/psr/psr/cs/dto/NoticeListRes.kt +++ b/src/main/kotlin/com/psr/psr/cs/dto/response/NoticeListRes.kt @@ -1,4 +1,4 @@ -package com.psr.psr.cs.dto +package com.psr.psr.cs.dto.response data class NoticeListRes ( val noticeLists: List? diff --git a/src/main/kotlin/com/psr/psr/cs/dto/NoticeRes.kt b/src/main/kotlin/com/psr/psr/cs/dto/response/NoticeRes.kt similarity index 93% rename from src/main/kotlin/com/psr/psr/cs/dto/NoticeRes.kt rename to src/main/kotlin/com/psr/psr/cs/dto/response/NoticeRes.kt index a2e8607..fac8ab0 100644 --- a/src/main/kotlin/com/psr/psr/cs/dto/NoticeRes.kt +++ b/src/main/kotlin/com/psr/psr/cs/dto/response/NoticeRes.kt @@ -1,4 +1,4 @@ -package com.psr.psr.cs.dto +package com.psr.psr.cs.dto.response import com.fasterxml.jackson.annotation.JsonFormat import com.fasterxml.jackson.annotation.JsonInclude diff --git a/src/main/kotlin/com/psr/psr/cs/service/CsService.kt b/src/main/kotlin/com/psr/psr/cs/service/CsService.kt index 1a7e759..6d718a8 100644 --- a/src/main/kotlin/com/psr/psr/cs/service/CsService.kt +++ b/src/main/kotlin/com/psr/psr/cs/service/CsService.kt @@ -1,9 +1,9 @@ package com.psr.psr.cs.service -import com.psr.psr.cs.dto.FaqListRes -import com.psr.psr.cs.dto.FaqRes -import com.psr.psr.cs.dto.NoticeListRes -import com.psr.psr.cs.dto.NoticeRes +import com.psr.psr.cs.dto.response.FaqListRes +import com.psr.psr.cs.dto.response.FaqRes +import com.psr.psr.cs.dto.response.NoticeListRes +import com.psr.psr.cs.dto.response.NoticeRes import com.psr.psr.cs.dto.assembler.CsAssembler import com.psr.psr.cs.entity.FaqType import com.psr.psr.cs.repository.FaqRepository @@ -21,12 +21,12 @@ class CsService( ) { // 공지사항 메인 - fun getNotices() : NoticeListRes{ + fun getNotices() : NoticeListRes { return csAssembler.toNoticeListRes(noticeRepository.findByStatusOrderByCreatedAtDesc(ACTIVE_STATUS)) } // 공지사항 상세 - fun getNotice(noticeId: Long) : NoticeRes{ + fun getNotice(noticeId: Long) : NoticeRes { val notice = noticeRepository.findByIdAndStatus(noticeId, ACTIVE_STATUS) ?: throw BaseException(BaseResponseCode.NOT_FOUND_NOTICE) return csAssembler.toNoticeRes(notice) }