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