From e6a53eb5666e0f19071f475a3e42d00a7e2a32a0 Mon Sep 17 00:00:00 2001 From: ChuYong Date: Thu, 12 Dec 2024 23:40:02 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/kr/mafoo/user/api/MeApi.java | 12 +++++++++--- .../java/kr/mafoo/user/controller/MeController.java | 8 ++++++++ .../controller/dto/request/ChangeNameRequest.java | 10 ++++++++++ .../java/kr/mafoo/user/service/MemberService.java | 12 ++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 user-service/src/main/java/kr/mafoo/user/controller/dto/request/ChangeNameRequest.java 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); + } }