diff --git a/user-service/src/main/java/kr/mafoo/user/api/MeApi.java b/user-service/src/main/java/kr/mafoo/user/api/MeApi.java index 1a79f47..ab19ed5 100644 --- a/user-service/src/main/java/kr/mafoo/user/api/MeApi.java +++ b/user-service/src/main/java/kr/mafoo/user/api/MeApi.java @@ -4,11 +4,10 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import kr.mafoo.user.annotation.RequestMemberId; +import kr.mafoo.user.controller.dto.request.ChangeNameRequest; import kr.mafoo.user.controller.dto.response.MemberResponse; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Mono; @Tag(name = "로그인 사용자 정보 API", description = "현재 토큰 주인의 정보를 다루는 API") @@ -26,4 +25,11 @@ Mono getMemberWhoRequested( Mono deleteMemberWhoRequested( @RequestMemberId @Parameter(hidden = true) String memberId ); + + @Operation(summary = "이름 변경", description = "현재 토큰 주인의 이름을 변경합니다.") + @PostMapping("/name") + Mono changeName( + @RequestMemberId @Parameter(hidden = true) String memberId, + @RequestBody ChangeNameRequest name + ); } diff --git a/user-service/src/main/java/kr/mafoo/user/controller/MeController.java b/user-service/src/main/java/kr/mafoo/user/controller/MeController.java index 2cfb6dd..122ce45 100644 --- a/user-service/src/main/java/kr/mafoo/user/controller/MeController.java +++ b/user-service/src/main/java/kr/mafoo/user/controller/MeController.java @@ -1,6 +1,7 @@ package kr.mafoo.user.controller; import kr.mafoo.user.api.MeApi; +import kr.mafoo.user.controller.dto.request.ChangeNameRequest; import kr.mafoo.user.controller.dto.response.MemberResponse; import kr.mafoo.user.service.MemberService; import lombok.RequiredArgsConstructor; @@ -24,4 +25,11 @@ public Mono deleteMemberWhoRequested(String memberId) { return memberService .quitMemberByMemberId(memberId); } + + @Override + public Mono changeName(String memberId, ChangeNameRequest name) { + return memberService + .changeName(memberId, name.name()) + .map(MemberResponse::fromEntity); + } } diff --git a/user-service/src/main/java/kr/mafoo/user/controller/dto/request/ChangeNameRequest.java b/user-service/src/main/java/kr/mafoo/user/controller/dto/request/ChangeNameRequest.java new file mode 100644 index 0000000..8c57a22 --- /dev/null +++ b/user-service/src/main/java/kr/mafoo/user/controller/dto/request/ChangeNameRequest.java @@ -0,0 +1,10 @@ +package kr.mafoo.user.controller.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; + +@Schema(description = "이름 변경 요청") +public record ChangeNameRequest( + @Schema(description = "새 이름", example = "염수연") + String name +) { +} diff --git a/user-service/src/main/java/kr/mafoo/user/service/MemberService.java b/user-service/src/main/java/kr/mafoo/user/service/MemberService.java index c4e93a9..7afa507 100644 --- a/user-service/src/main/java/kr/mafoo/user/service/MemberService.java +++ b/user-service/src/main/java/kr/mafoo/user/service/MemberService.java @@ -63,4 +63,16 @@ public Mono createNewMember(String username, String profileImageUr .then(Mono.just(savedMember)) ); } + + @Transactional + public Mono changeName(String memberId, String name) { + return memberRepository + .findById(memberId) + .switchIfEmpty(Mono.error(new MemberNotFoundException())) + .map(member -> { + member.setName(name); + return member; + }) + .flatMap(memberRepository::save); + } }