Skip to content

Commit

Permalink
feat: 이름 변경 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Dec 12, 2024
1 parent fc2290e commit e6a53eb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
12 changes: 9 additions & 3 deletions user-service/src/main/java/kr/mafoo/user/api/MeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -26,4 +25,11 @@ Mono<MemberResponse> getMemberWhoRequested(
Mono<Void> deleteMemberWhoRequested(
@RequestMemberId @Parameter(hidden = true) String memberId
);

@Operation(summary = "이름 변경", description = "현재 토큰 주인의 이름을 변경합니다.")
@PostMapping("/name")
Mono<MemberResponse> changeName(
@RequestMemberId @Parameter(hidden = true) String memberId,
@RequestBody ChangeNameRequest name
);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,4 +25,11 @@ public Mono<Void> deleteMemberWhoRequested(String memberId) {
return memberService
.quitMemberByMemberId(memberId);
}

@Override
public Mono<MemberResponse> changeName(String memberId, ChangeNameRequest name) {
return memberService
.changeName(memberId, name.name())
.map(MemberResponse::fromEntity);
}
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ public Mono<MemberEntity> createNewMember(String username, String profileImageUr
.then(Mono.just(savedMember))
);
}

@Transactional
public Mono<MemberEntity> changeName(String memberId, String name) {
return memberRepository
.findById(memberId)
.switchIfEmpty(Mono.error(new MemberNotFoundException()))
.map(member -> {
member.setName(name);
return member;
})
.flatMap(memberRepository::save);
}
}

0 comments on commit e6a53eb

Please sign in to comment.