From 4c038862d23ace9d1b62b70157470a33586b276f Mon Sep 17 00:00:00 2001 From: orijoon98 Date: Sat, 2 Mar 2024 22:00:05 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9A=A1=EF=B8=8F:=20fix=20CI/CD=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/plu-api/switch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/plu-api/switch.sh b/scripts/plu-api/switch.sh index a015995..2b234f9 100644 --- a/scripts/plu-api/switch.sh +++ b/scripts/plu-api/switch.sh @@ -14,7 +14,7 @@ else exit 1 fi -echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" | sudo tee /etc/nginx/conf.d/service-url.inc +echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" >> /home/ubuntu/plu-api/deploy.log | sudo tee /etc/nginx/conf.d/service-url.inc echo "[$NOW_TIME] Now Nginx proxies to ${TARGET_PORT}." >> /home/ubuntu/plu-api/deploy.log sudo service nginx reload From e64debd77e6cf4a0d0a97cee4292904854d1c389 Mon Sep 17 00:00:00 2001 From: sookyung kang Date: Sun, 3 Mar 2024 06:37:05 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8:=20feat=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=A4=91=EB=B3=B5=EC=B2=B4=ED=81=AC=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/member/MemberController.kt | 26 ++++++++++++++ .../dto/request/CheckNicknameRequestDto.kt | 5 +++ .../dto/response/CheckNickNameResponseDto.kt | 5 +++ .../plu/api/service/member/MemberService.kt | 8 ++++- .../plu/api/service/member/MemberValidator.kt | 6 ++++ .../th/plu/common/exception/code/ErrorCode.kt | 1 + .../repository/MemberRepositoryCustom.kt | 2 ++ .../member/repository/MemberRepositoryImpl.kt | 34 ++++++++++++------- 8 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/CheckNicknameRequestDto.kt create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt new file mode 100644 index 0000000..c07d93e --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt @@ -0,0 +1,26 @@ +package com.th.plu.api.controller.member + +import com.th.plu.api.controller.member.dto.request.CheckNicknameRequestDto +import com.th.plu.api.controller.member.dto.response.CheckNicknameResponse +import com.th.plu.api.service.member.MemberService +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.tags.Tag +import com.th.plu.common.dto.response.ApiResponse +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController + +@Tag(name = "Member") +@RestController +class MemberController( + private val memberService: MemberService, +) { + + @Operation(summary = "닉네임 중복 체크") + @PostMapping("/api/v1/member/nickname/dupl") + fun checkNicknameDupl(@RequestBody request: CheckNicknameRequestDto): ApiResponse { + val isAvailable = memberService.isNicknameAvailable(request.nickname) + val response = CheckNicknameResponse(isAvailable) + return ApiResponse.success(response) + } +} \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/CheckNicknameRequestDto.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/CheckNicknameRequestDto.kt new file mode 100644 index 0000000..9a8fd0b --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/CheckNicknameRequestDto.kt @@ -0,0 +1,5 @@ +package com.th.plu.api.controller.member.dto.request + +data class CheckNicknameRequestDto( + val nickname: String +) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt new file mode 100644 index 0000000..e250b4b --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt @@ -0,0 +1,5 @@ +package com.th.plu.api.controller.member.dto.response + +data class CheckNicknameResponse( + val isAvailable: Boolean +) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt index 342be36..e840f94 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt @@ -1,6 +1,7 @@ package com.th.plu.api.service.member import com.th.plu.api.controller.member.dto.request.CreateUserRequestDto +import com.th.plu.common.exception.model.NotFoundException import com.th.plu.domain.domain.member.Member import com.th.plu.domain.domain.member.Onboarding import com.th.plu.domain.domain.member.Setting @@ -21,7 +22,8 @@ class MemberService( @Transactional fun registerUser(request: CreateUserRequestDto): Long { memberValidator.validateNotExistsMember(request.socialId, request.socialType) - // TODO: 닉네임 중복 체크 추가해야합니다. + memberValidator.validateDuplicatedNickname(request.nickname) + val member = memberRepository.save( Member.newInstance( socialId = request.socialId, @@ -40,4 +42,8 @@ class MemberService( return member.id!! } + fun isNicknameAvailable(nickname: String): Boolean { + return !memberRepository.existsByNickname(nickname) + } + } \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt index c47541a..ba47380 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt @@ -15,4 +15,10 @@ class MemberValidator( throw ConflictException(ErrorCode.CONFLICT_MEMBER_EXCEPTION, "이미 존재하는 유저 $socialId - $socialType 입니다") } } + + fun validateDuplicatedNickname(nickname: String) { + if (memberRepository.existsByNickname(nickname)) { + throw ConflictException(ErrorCode.CONFLICT_NICKNAME_EXCEPTION, "이미 사용 중인 닉네임입니다.") + } + } } \ No newline at end of file diff --git a/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt b/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt index dd62104..1993628 100644 --- a/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt +++ b/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt @@ -31,6 +31,7 @@ enum class ErrorCode(val code: String, val message: String) { CONFLICT_EXCEPTION("C001", "이미 존재합니다."), CONFLICT_MEMBER_EXCEPTION("C002", "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), CONFLICT_BOOKMARK_EXCEPTION("C003", "요청과 동일한 북마크 상태 입니다."), + CONFLICT_NICKNAME_EXCEPTION("C004","이미 사용 중인 닉네임 입니다."), // Internal Server Exception INTERNAL_SERVER_EXCEPTION("I001", "서버 내부에서 에러가 발생하였습니다."), diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryCustom.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryCustom.kt index 897a389..c12ede7 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryCustom.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryCustom.kt @@ -8,4 +8,6 @@ interface MemberRepositoryCustom { fun findMemberById(id: Long): Member? fun findMemberBySocialIdAndSocialType(socialId: String, socialType: MemberSocialType): Member? fun existBySocialIdAndSocialType(socialId: String, socialType: MemberSocialType): Boolean + fun existsByNickname(nickname: String): Boolean + } diff --git a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryImpl.kt b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryImpl.kt index 5c20ea1..335b7f5 100644 --- a/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryImpl.kt +++ b/plu-domain/src/main/kotlin/com/th/plu/domain/domain/member/repository/MemberRepositoryImpl.kt @@ -4,32 +4,40 @@ import com.querydsl.jpa.impl.JPAQueryFactory import com.th.plu.domain.domain.member.Member import com.th.plu.domain.domain.member.MemberSocialType import com.th.plu.domain.domain.member.QMember.member +import com.th.plu.domain.domain.member.QOnboarding.onboarding import org.springframework.stereotype.Repository @Repository class MemberRepositoryImpl(private val queryFactory: JPAQueryFactory) : MemberRepositoryCustom { override fun findMemberById(id: Long): Member? { return queryFactory - .selectFrom(member) - .where(member.id.eq(id)) - .fetchOne() + .selectFrom(member) + .where(member.id.eq(id)) + .fetchOne() } override fun findMemberBySocialIdAndSocialType(socialId: String, socialType: MemberSocialType): Member? { return queryFactory - .selectFrom(member) - .where( - member.socialId.eq(socialId), - member.socialType.eq(socialType) - ).fetchOne() + .selectFrom(member) + .where( + member.socialId.eq(socialId), + member.socialType.eq(socialType) + ).fetchOne() } override fun existBySocialIdAndSocialType(socialId: String, socialType: MemberSocialType): Boolean { return queryFactory - .selectFrom(member) - .where( - member.socialId.eq(socialId), - member.socialType.eq(socialType) - ).fetchOne() != null + .selectFrom(member) + .where( + member.socialId.eq(socialId), + member.socialType.eq(socialType) + ).fetchOne() != null + } + + override fun existsByNickname(nickname: String): Boolean { + return queryFactory + .selectFrom(onboarding) + .where(onboarding.nickname.eq(nickname)) + .fetchOne() != null } } From 10402f51888e4ed5671a987fb0475467e41e24b1 Mon Sep 17 00:00:00 2001 From: sookyung kang Date: Sun, 3 Mar 2024 09:05:33 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=A8:=20feat=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=ED=83=88=ED=87=B4,=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20API=20=EC=B6=94=EA=B0=80=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/member/MemberController.kt | 29 +++++++++-- .../dto/request/UpdateNicknameRequest.kt | 5 ++ .../plu/api/service/member/MemberService.kt | 52 ++++++++++++++----- 3 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt index c07d93e..45c1ce7 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt @@ -1,21 +1,22 @@ package com.th.plu.api.controller.member +import com.th.plu.api.config.interceptor.Auth +import com.th.plu.api.config.resolver.MemberId import com.th.plu.api.controller.member.dto.request.CheckNicknameRequestDto +import com.th.plu.api.controller.member.dto.request.UpdateNicknameRequest import com.th.plu.api.controller.member.dto.response.CheckNicknameResponse +import com.th.plu.api.controller.member.dto.response.MyPageResponse import com.th.plu.api.service.member.MemberService import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import com.th.plu.common.dto.response.ApiResponse -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* @Tag(name = "Member") @RestController class MemberController( private val memberService: MemberService, ) { - @Operation(summary = "닉네임 중복 체크") @PostMapping("/api/v1/member/nickname/dupl") fun checkNicknameDupl(@RequestBody request: CheckNicknameRequestDto): ApiResponse { @@ -23,4 +24,24 @@ class MemberController( val response = CheckNicknameResponse(isAvailable) return ApiResponse.success(response) } + + @Auth + @Operation(summary = "[인증] 닉네임 수정") + @PutMapping("/api/v1/member/{memberId}/nickname") + fun updateNickname( + @PathVariable memberId: Long, + @RequestBody request: UpdateNicknameRequest + ): ApiResponse { + memberService.updateNickname(memberId, request.newNickname) + return ApiResponse.success() + } + + @Auth + @Operation(summary = "[인증] 회원 탈퇴") + @DeleteMapping("/api/v1/member") + fun deleteMember(@MemberId memberId: Long): ApiResponse { + memberService.deleteMember(memberId) + return ApiResponse.success() + } + } \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt new file mode 100644 index 0000000..c6c9d46 --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt @@ -0,0 +1,5 @@ +package com.th.plu.api.controller.member.dto.request + +data class UpdateNicknameRequest( + val newNickname: String +) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt index e840f94..6f485c1 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt @@ -1,10 +1,13 @@ package com.th.plu.api.service.member import com.th.plu.api.controller.member.dto.request.CreateUserRequestDto +import com.th.plu.api.controller.member.dto.response.MyPageResponse +import com.th.plu.common.exception.code.ErrorCode import com.th.plu.common.exception.model.NotFoundException import com.th.plu.domain.domain.member.Member import com.th.plu.domain.domain.member.Onboarding import com.th.plu.domain.domain.member.Setting +import com.th.plu.domain.domain.member.explorer.MemberExplorer import com.th.plu.domain.domain.member.repository.MemberRepository import com.th.plu.domain.domain.member.repository.OnboardingRepository import com.th.plu.domain.domain.member.repository.SettingRepository @@ -13,10 +16,11 @@ import org.springframework.transaction.annotation.Transactional @Service class MemberService( - private val memberValidator: MemberValidator, - private val memberRepository: MemberRepository, - private val onboardingRepository: OnboardingRepository, - private val settingRepository: SettingRepository + private val memberValidator: MemberValidator, + private val memberRepository: MemberRepository, + private val onboardingRepository: OnboardingRepository, + private val settingRepository: SettingRepository, + private val memberExplorer: MemberExplorer ) { @Transactional @@ -25,25 +29,45 @@ class MemberService( memberValidator.validateDuplicatedNickname(request.nickname) val member = memberRepository.save( - Member.newInstance( - socialId = request.socialId, - socialType = request.socialType, - fcmToken = request.fcmToken, - setting = settingRepository.save(Setting.newInstance()) - ) + Member.newInstance( + socialId = request.socialId, + socialType = request.socialType, + fcmToken = request.fcmToken, + setting = settingRepository.save(Setting.newInstance()) + ) ) val onboarding = onboardingRepository.save( - Onboarding.newInstance( - member = member, - nickname = request.nickname - ) + Onboarding.newInstance( + member = member, + nickname = request.nickname + ) ) member.initOnboarding(onboarding) return member.id!! } + @Transactional(readOnly = true) fun isNicknameAvailable(nickname: String): Boolean { return !memberRepository.existsByNickname(nickname) } + @Transactional + fun updateNickname(memberId: Long, newNickname: String) { + val member = memberExplorer.findMemberById(memberId) + + memberValidator.validateDuplicatedNickname(newNickname) + + //onboarding 객체가 null이라면 예외 발생 + member.onboarding?.let { + it.nickname = newNickname + onboardingRepository.save(it) + } ?: throw NotFoundException(ErrorCode.NOT_FOUND_MEMBER_EXCEPTION, "Onboarding 정보가 없는 유저 $memberId 입니다") + } + + @Transactional + fun deleteMember(memberId: Long) { + val member = memberExplorer.findMemberById(memberId) + memberRepository.delete(member) + } + } \ No newline at end of file From 015460d03bc4252223b9ab65d3da34a6fa6e2837 Mon Sep 17 00:00:00 2001 From: sookyung kang Date: Sun, 3 Mar 2024 09:05:44 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E2=9C=A8:=20feat=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/th/plu/api/controller/member/MemberController.kt | 9 ++++++++- .../api/controller/member/dto/response/MyPageResponse.kt | 6 ++++++ .../com/th/plu/api/service/member/MemberService.kt | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt index 45c1ce7..22fcad9 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt @@ -43,5 +43,12 @@ class MemberController( memberService.deleteMember(memberId) return ApiResponse.success() } - + + @Auth + @Operation(summary = "[인증] 마이페이지 조회") + @GetMapping("/api/v1/mypage") + fun getMyPageInfo(@MemberId memberId: Long): ApiResponse { + val myPageInfo = memberService.getMyPageInfo(memberId) + return ApiResponse.success(data = myPageInfo) + } } \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt new file mode 100644 index 0000000..5dd6a3f --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt @@ -0,0 +1,6 @@ +package com.th.plu.api.controller.member.dto.response + +data class MyPageResponse( + val nickname: String, + val notificationStatus: Boolean +) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt index 6f485c1..1f69c55 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt @@ -70,4 +70,13 @@ class MemberService( memberRepository.delete(member) } + @Transactional(readOnly = true) + fun getMyPageInfo(memberId: Long): MyPageResponse { + val member = memberExplorer.findMemberById(memberId) + return MyPageResponse( + nickname = member.onboarding?.nickname ?: "", + notificationStatus = member.setting.notificationStatus + ) + } + } \ No newline at end of file From b25bc9260c492372040de9dcec068f017ee8104a Mon Sep 17 00:00:00 2001 From: sookyung kang Date: Thu, 7 Mar 2024 02:24:12 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9A=A1=EF=B8=8F:=20fix=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=ED=8F=AC=EB=A7=B7=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20Dto=20=ED=8C=8C=EC=9D=BC=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/member/dto/request/UpdateNicknameRequest.kt | 5 ----- .../member/dto/request/UpdateNicknameRequestDto.kt | 5 +++++ .../member/dto/response/CheckNickNameResponseDto.kt | 2 +- .../api/controller/member/dto/response/MyPageResponse.kt | 6 ------ .../api/controller/member/dto/response/MyPageResponseDto.kt | 6 ++++++ 5 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequestDto.kt delete mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponseDto.kt diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt deleted file mode 100644 index c6c9d46..0000000 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequest.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.th.plu.api.controller.member.dto.request - -data class UpdateNicknameRequest( - val newNickname: String -) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequestDto.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequestDto.kt new file mode 100644 index 0000000..4b088b1 --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/request/UpdateNicknameRequestDto.kt @@ -0,0 +1,5 @@ +package com.th.plu.api.controller.member.dto.request + +data class UpdateNicknameRequestDto( + val newNickname: String +) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt index e250b4b..b5136de 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/CheckNickNameResponseDto.kt @@ -1,5 +1,5 @@ package com.th.plu.api.controller.member.dto.response data class CheckNicknameResponse( - val isAvailable: Boolean + val isAvailable: Boolean ) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt deleted file mode 100644 index 5dd6a3f..0000000 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponse.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.th.plu.api.controller.member.dto.response - -data class MyPageResponse( - val nickname: String, - val notificationStatus: Boolean -) \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponseDto.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponseDto.kt new file mode 100644 index 0000000..40d9cb5 --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/dto/response/MyPageResponseDto.kt @@ -0,0 +1,6 @@ +package com.th.plu.api.controller.member.dto.response + +data class MyPageResponseDto( + val nickname: String, + val notificationStatus: Boolean +) \ No newline at end of file From 8fafe34a3b4a5fc94c3a461ab84f76b2b4418f13 Mon Sep 17 00:00:00 2001 From: sookyung kang Date: Thu, 7 Mar 2024 02:25:12 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E2=9A=A1=EF=B8=8F:=20fix=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/member/MemberController.kt | 19 +++--- .../plu/api/service/member/MemberService.kt | 60 ++++++++++--------- .../plu/api/service/member/MemberValidator.kt | 16 +++++ .../th/plu/common/exception/code/ErrorCode.kt | 6 +- 4 files changed, 61 insertions(+), 40 deletions(-) diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt index 22fcad9..807765c 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/member/MemberController.kt @@ -3,25 +3,24 @@ package com.th.plu.api.controller.member import com.th.plu.api.config.interceptor.Auth import com.th.plu.api.config.resolver.MemberId import com.th.plu.api.controller.member.dto.request.CheckNicknameRequestDto -import com.th.plu.api.controller.member.dto.request.UpdateNicknameRequest +import com.th.plu.api.controller.member.dto.request.UpdateNicknameRequestDto import com.th.plu.api.controller.member.dto.response.CheckNicknameResponse -import com.th.plu.api.controller.member.dto.response.MyPageResponse +import com.th.plu.api.controller.member.dto.response.MyPageResponseDto import com.th.plu.api.service.member.MemberService +import com.th.plu.common.dto.response.ApiResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag -import com.th.plu.common.dto.response.ApiResponse import org.springframework.web.bind.annotation.* @Tag(name = "Member") @RestController class MemberController( - private val memberService: MemberService, + private val memberService: MemberService, ) { @Operation(summary = "닉네임 중복 체크") @PostMapping("/api/v1/member/nickname/dupl") - fun checkNicknameDupl(@RequestBody request: CheckNicknameRequestDto): ApiResponse { - val isAvailable = memberService.isNicknameAvailable(request.nickname) - val response = CheckNicknameResponse(isAvailable) + fun checkNicknameDuplication(@RequestBody request: CheckNicknameRequestDto): ApiResponse { + val response = memberService.checkNicknameDuplication(request) return ApiResponse.success(response) } @@ -29,8 +28,8 @@ class MemberController( @Operation(summary = "[인증] 닉네임 수정") @PutMapping("/api/v1/member/{memberId}/nickname") fun updateNickname( - @PathVariable memberId: Long, - @RequestBody request: UpdateNicknameRequest + @PathVariable memberId: Long, + @RequestBody request: UpdateNicknameRequestDto ): ApiResponse { memberService.updateNickname(memberId, request.newNickname) return ApiResponse.success() @@ -47,7 +46,7 @@ class MemberController( @Auth @Operation(summary = "[인증] 마이페이지 조회") @GetMapping("/api/v1/mypage") - fun getMyPageInfo(@MemberId memberId: Long): ApiResponse { + fun getMyPageInfo(@MemberId memberId: Long): ApiResponse { val myPageInfo = memberService.getMyPageInfo(memberId) return ApiResponse.success(data = myPageInfo) } diff --git a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt index 1f69c55..4cbfa07 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberService.kt @@ -1,9 +1,9 @@ package com.th.plu.api.service.member +import com.th.plu.api.controller.member.dto.request.CheckNicknameRequestDto import com.th.plu.api.controller.member.dto.request.CreateUserRequestDto -import com.th.plu.api.controller.member.dto.response.MyPageResponse -import com.th.plu.common.exception.code.ErrorCode -import com.th.plu.common.exception.model.NotFoundException +import com.th.plu.api.controller.member.dto.response.CheckNicknameResponse +import com.th.plu.api.controller.member.dto.response.MyPageResponseDto import com.th.plu.domain.domain.member.Member import com.th.plu.domain.domain.member.Onboarding import com.th.plu.domain.domain.member.Setting @@ -16,11 +16,11 @@ import org.springframework.transaction.annotation.Transactional @Service class MemberService( - private val memberValidator: MemberValidator, - private val memberRepository: MemberRepository, - private val onboardingRepository: OnboardingRepository, - private val settingRepository: SettingRepository, - private val memberExplorer: MemberExplorer + private val memberValidator: MemberValidator, + private val memberRepository: MemberRepository, + private val onboardingRepository: OnboardingRepository, + private val settingRepository: SettingRepository, + private val memberExplorer: MemberExplorer ) { @Transactional @@ -29,26 +29,28 @@ class MemberService( memberValidator.validateDuplicatedNickname(request.nickname) val member = memberRepository.save( - Member.newInstance( - socialId = request.socialId, - socialType = request.socialType, - fcmToken = request.fcmToken, - setting = settingRepository.save(Setting.newInstance()) - ) + Member.newInstance( + socialId = request.socialId, + socialType = request.socialType, + fcmToken = request.fcmToken, + setting = settingRepository.save(Setting.newInstance()) + ) ) val onboarding = onboardingRepository.save( - Onboarding.newInstance( - member = member, - nickname = request.nickname - ) + Onboarding.newInstance( + member = member, + nickname = request.nickname + ) ) + member.initOnboarding(onboarding) return member.id!! } @Transactional(readOnly = true) - fun isNicknameAvailable(nickname: String): Boolean { - return !memberRepository.existsByNickname(nickname) + fun checkNicknameDuplication(request: CheckNicknameRequestDto): CheckNicknameResponse { + val isAvailable = !memberRepository.existsByNickname(request.nickname) + return CheckNicknameResponse(isAvailable) } @Transactional @@ -56,12 +58,10 @@ class MemberService( val member = memberExplorer.findMemberById(memberId) memberValidator.validateDuplicatedNickname(newNickname) + memberValidator.validateOnboardingExists(member) + + member.onboarding!!.nickname = newNickname - //onboarding 객체가 null이라면 예외 발생 - member.onboarding?.let { - it.nickname = newNickname - onboardingRepository.save(it) - } ?: throw NotFoundException(ErrorCode.NOT_FOUND_MEMBER_EXCEPTION, "Onboarding 정보가 없는 유저 $memberId 입니다") } @Transactional @@ -71,11 +71,13 @@ class MemberService( } @Transactional(readOnly = true) - fun getMyPageInfo(memberId: Long): MyPageResponse { + fun getMyPageInfo(memberId: Long): MyPageResponseDto { val member = memberExplorer.findMemberById(memberId) - return MyPageResponse( - nickname = member.onboarding?.nickname ?: "", - notificationStatus = member.setting.notificationStatus + val onboarding = memberValidator.validateOnboardingExists(member) + + return MyPageResponseDto( + nickname = onboarding.nickname, + notificationStatus = member.setting.notificationStatus ) } diff --git a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt index ba47380..0ec3e89 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/service/member/MemberValidator.kt @@ -2,7 +2,11 @@ package com.th.plu.api.service.member import com.th.plu.common.exception.code.ErrorCode import com.th.plu.common.exception.model.ConflictException +import com.th.plu.common.exception.model.IllegalArgumentException +import com.th.plu.common.exception.model.NotFoundException +import com.th.plu.domain.domain.member.Member import com.th.plu.domain.domain.member.MemberSocialType +import com.th.plu.domain.domain.member.Onboarding import com.th.plu.domain.domain.member.repository.MemberRepository import org.springframework.stereotype.Component @@ -21,4 +25,16 @@ class MemberValidator( throw ConflictException(ErrorCode.CONFLICT_NICKNAME_EXCEPTION, "이미 사용 중인 닉네임입니다.") } } + + fun validateNullorBlankNickname(nickname: String?) { + if (nickname.isNullOrBlank()) { + throw IllegalArgumentException(ErrorCode.Illegal_ARGUMENT_NICKNAME_EXCEPTION, "닉네임은 비어 있을 수 없습니다.") + } + } + + fun validateOnboardingExists(member: Member): Onboarding { + return member.onboarding + ?: throw NotFoundException(ErrorCode.NOT_FOUND_ONBOARDING_EXCEPTION, "Onboarding 정보가 없는 유저 입니다") + } + } \ No newline at end of file diff --git a/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt b/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt index 1993628..6280007 100644 --- a/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt +++ b/plu-common/src/main/kotlin/com/th/plu/common/exception/code/ErrorCode.kt @@ -26,16 +26,20 @@ enum class ErrorCode(val code: String, val message: String) { NOT_FOUND_ARTICLE_EXCEPTION("N005", "삭제되었거나 존재하지 않는 아티클입니다."), NOT_FOUND_ARTICLE_IN_WEEK_AND_DAY_EXCEPTION("N006", "해당 주차 일차에 해당하는 아티클이 존재하지 않습니다."), NOT_FOUND_ENDPOINT_EXCEPTION("N007", "존재하지 않는 엔드포인트입니다."), + NOT_FOUND_ONBOARDING_EXCEPTION("N007", "존재하지 않는 엔드포인트입니다."), // Conflict Exception CONFLICT_EXCEPTION("C001", "이미 존재합니다."), CONFLICT_MEMBER_EXCEPTION("C002", "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), CONFLICT_BOOKMARK_EXCEPTION("C003", "요청과 동일한 북마크 상태 입니다."), - CONFLICT_NICKNAME_EXCEPTION("C004","이미 사용 중인 닉네임 입니다."), + CONFLICT_NICKNAME_EXCEPTION("C004", "이미 사용 중인 닉네임 입니다."), // Internal Server Exception INTERNAL_SERVER_EXCEPTION("I001", "서버 내부에서 에러가 발생하였습니다."), // Bad Gateway Exception BAD_GATEWAY_EXCEPTION("B001", "외부 연동 중 에러가 발생하였습니다."), + + // Illegal Argument Exception + Illegal_ARGUMENT_NICKNAME_EXCEPTION("IA001", "잘못된 닉네임 형식입니다."), }