From f6afb4dfbabfc3fe360b803550886c02a5362c83 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Tue, 30 Jul 2024 21:56:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20API=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20Facade=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20(#94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../port/in/usecase/NameUpdateUseCase.java | 7 +++++ .../persistence/MemberPersistencePort.java | 2 ++ .../member/service/MemberService.java | 10 ++++++- .../type/member/MemberErrorType.java | 3 +- .../type/member/MemberSuccessType.java | 3 +- .../depromeet/member/entity/MemberEntity.java | 5 ++++ .../member/repository/MemberRepository.java | 7 +++++ .../oauth/CustomOAuth2UserService.java | 4 +-- .../com/depromeet/member/api/MemberApi.java | 8 +++++ .../member/api/MemberController.java | 20 +++++++++---- .../member/dto/request/NameUpdateRequest.java | 6 ++++ .../depromeet/member/facade/MemberFacade.java | 29 +++++++++++++++++++ 12 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 module-domain/src/main/java/com/depromeet/member/port/in/usecase/NameUpdateUseCase.java create mode 100644 module-presentation/src/main/java/com/depromeet/member/dto/request/NameUpdateRequest.java create mode 100644 module-presentation/src/main/java/com/depromeet/member/facade/MemberFacade.java diff --git a/module-domain/src/main/java/com/depromeet/member/port/in/usecase/NameUpdateUseCase.java b/module-domain/src/main/java/com/depromeet/member/port/in/usecase/NameUpdateUseCase.java new file mode 100644 index 00000000..fd164925 --- /dev/null +++ b/module-domain/src/main/java/com/depromeet/member/port/in/usecase/NameUpdateUseCase.java @@ -0,0 +1,7 @@ +package com.depromeet.member.port.in.usecase; + +import com.depromeet.member.domain.Member; + +public interface NameUpdateUseCase { + Member updateName(Long memberId, String name); +} diff --git a/module-domain/src/main/java/com/depromeet/member/port/out/persistence/MemberPersistencePort.java b/module-domain/src/main/java/com/depromeet/member/port/out/persistence/MemberPersistencePort.java index edb532b7..1db11d7e 100644 --- a/module-domain/src/main/java/com/depromeet/member/port/out/persistence/MemberPersistencePort.java +++ b/module-domain/src/main/java/com/depromeet/member/port/out/persistence/MemberPersistencePort.java @@ -13,4 +13,6 @@ public interface MemberPersistencePort { void updateRefresh(Long memberId, String refreshToken); Optional updateGoal(Long memberId, Integer goal); + + Optional updateName(Long memberId, String name); } diff --git a/module-domain/src/main/java/com/depromeet/member/service/MemberService.java b/module-domain/src/main/java/com/depromeet/member/service/MemberService.java index b316e78e..549331d6 100644 --- a/module-domain/src/main/java/com/depromeet/member/service/MemberService.java +++ b/module-domain/src/main/java/com/depromeet/member/service/MemberService.java @@ -7,6 +7,7 @@ import com.depromeet.member.port.in.command.SocialMemberCommand; import com.depromeet.member.port.in.usecase.GoalUpdateUseCase; import com.depromeet.member.port.in.usecase.MemberUseCase; +import com.depromeet.member.port.in.usecase.NameUpdateUseCase; import com.depromeet.member.port.out.persistence.MemberPersistencePort; import com.depromeet.type.member.MemberErrorType; import lombok.RequiredArgsConstructor; @@ -16,7 +17,7 @@ @Service @Transactional @RequiredArgsConstructor -public class MemberService implements MemberUseCase, GoalUpdateUseCase { +public class MemberService implements MemberUseCase, GoalUpdateUseCase, NameUpdateUseCase { private final MemberPersistencePort memberPersistencePort; @Override @@ -49,4 +50,11 @@ public Member updateGoal(Long memberId, Integer goal) { .updateGoal(memberId, goal) .orElseThrow(() -> new InternalServerException(MemberErrorType.UPDATE_GOAL_FAILED)); } + + @Override + public Member updateName(Long memberId, String name) { + return memberPersistencePort + .updateName(memberId, name) + .orElseThrow(() -> new InternalServerException(MemberErrorType.UPDATE_NAME_FAILED)); + } } diff --git a/module-independent/src/main/java/com/depromeet/type/member/MemberErrorType.java b/module-independent/src/main/java/com/depromeet/type/member/MemberErrorType.java index 6001027d..4bc13eee 100644 --- a/module-independent/src/main/java/com/depromeet/type/member/MemberErrorType.java +++ b/module-independent/src/main/java/com/depromeet/type/member/MemberErrorType.java @@ -4,7 +4,8 @@ public enum MemberErrorType implements ErrorType { NOT_FOUND("MEMBER_1", "멤버가 존재하지 않습니다"), - UPDATE_GOAL_FAILED("MEMBER_2", "멤버의 목표 수정에 실패하였습니다"); + UPDATE_GOAL_FAILED("MEMBER_2", "멤버의 목표 수정에 실패하였습니다"), + UPDATE_NAME_FAILED("MEMBER_3", "멤버의 이름 수정에 실패하였습니다"); private final String code; private final String message; diff --git a/module-independent/src/main/java/com/depromeet/type/member/MemberSuccessType.java b/module-independent/src/main/java/com/depromeet/type/member/MemberSuccessType.java index e039af54..c0d40a0b 100644 --- a/module-independent/src/main/java/com/depromeet/type/member/MemberSuccessType.java +++ b/module-independent/src/main/java/com/depromeet/type/member/MemberSuccessType.java @@ -5,7 +5,8 @@ public enum MemberSuccessType implements SuccessType { GET_SUCCESS("MEMBER_1", "멤버 조회에 성공하였습니다"), UPDATE_GOAL_SUCCESS("MEMBER_2", "멤버 목표 수정에 성공하였습니다"), - GET_GOAL_SUCCESS("MEMBER_3", "멤버 목표 조회에 성공하였습니다"); + GET_GOAL_SUCCESS("MEMBER_3", "멤버 목표 조회에 성공하였습니다"), + UPDATE_NAME_SUCCESS("MEMBER_4", "멤버 이름 수정에 성공하였습니다"); private final String code; diff --git a/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/entity/MemberEntity.java b/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/entity/MemberEntity.java index 35d2ee39..273eda66 100644 --- a/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/entity/MemberEntity.java +++ b/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/entity/MemberEntity.java @@ -87,4 +87,9 @@ public MemberEntity updateGoal(Integer goal) { this.goal = goal; return this; } + + public MemberEntity updateName(String name) { + this.name = name; + return this; + } } diff --git a/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/repository/MemberRepository.java b/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/repository/MemberRepository.java index ce241778..82ed57d6 100644 --- a/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/repository/MemberRepository.java +++ b/module-infrastructure/persistence-database/src/main/java/com/depromeet/member/repository/MemberRepository.java @@ -40,4 +40,11 @@ public Optional updateGoal(Long memberId, Integer goal) { .findById(memberId) .map(memberEntity -> memberEntity.updateGoal(goal).toModel()); } + + @Override + public Optional updateName(Long memberId, String name) { + return memberJpaRepository + .findById(memberId) + .map(memberEntity -> memberEntity.updateName(name).toModel()); + } } diff --git a/module-infrastructure/security/src/main/java/com/depromeet/oauth/CustomOAuth2UserService.java b/module-infrastructure/security/src/main/java/com/depromeet/oauth/CustomOAuth2UserService.java index 4fa9a033..7c1c9b5d 100644 --- a/module-infrastructure/security/src/main/java/com/depromeet/oauth/CustomOAuth2UserService.java +++ b/module-infrastructure/security/src/main/java/com/depromeet/oauth/CustomOAuth2UserService.java @@ -45,8 +45,8 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic MemberDto memberDto = MemberDto.builder() .id(member.getId()) - .name(nickname) - .email(email) + .name(member.getName()) + .email(member.getEmail()) .memberRole(member.getRole()) .build(); return new CustomOAuth2User(memberDto); diff --git a/module-presentation/src/main/java/com/depromeet/member/api/MemberApi.java b/module-presentation/src/main/java/com/depromeet/member/api/MemberApi.java index f4b5e5df..ba5b0b1e 100644 --- a/module-presentation/src/main/java/com/depromeet/member/api/MemberApi.java +++ b/module-presentation/src/main/java/com/depromeet/member/api/MemberApi.java @@ -1,13 +1,21 @@ package com.depromeet.member.api; import com.depromeet.dto.response.ApiResponse; +import com.depromeet.member.annotation.LoginMember; +import com.depromeet.member.dto.request.NameUpdateRequest; import com.depromeet.member.dto.response.MemberFindOneResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; @Tag(name = "사용자(members)") public interface MemberApi { @Operation(summary = "id로 member 단일 검색") ApiResponse getMember(@PathVariable("id") Long id); + + @Operation(summary = "닉네임 수정") + ApiResponse updateName( + @LoginMember Long id, + @RequestBody NameUpdateRequest updateNameRequest); } diff --git a/module-presentation/src/main/java/com/depromeet/member/api/MemberController.java b/module-presentation/src/main/java/com/depromeet/member/api/MemberController.java index 2b2e2335..03d38ede 100644 --- a/module-presentation/src/main/java/com/depromeet/member/api/MemberController.java +++ b/module-presentation/src/main/java/com/depromeet/member/api/MemberController.java @@ -1,25 +1,33 @@ package com.depromeet.member.api; import com.depromeet.dto.response.ApiResponse; +import com.depromeet.member.annotation.LoginMember; import com.depromeet.member.domain.Member; +import com.depromeet.member.dto.request.NameUpdateRequest; import com.depromeet.member.dto.response.MemberFindOneResponse; +import com.depromeet.member.facade.MemberFacade; import com.depromeet.member.port.in.usecase.MemberUseCase; import com.depromeet.type.member.MemberSuccessType; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @RequestMapping("/member") public class MemberController implements MemberApi { - private final MemberUseCase memberUseCase; + private final MemberFacade memberFacade; @GetMapping("/{id}") public ApiResponse getMember(@PathVariable("id") Long id) { - Member member = memberUseCase.findById(id); + Member member = memberFacade.findById(id); return ApiResponse.success(MemberSuccessType.GET_SUCCESS, MemberFindOneResponse.of(member)); } + + @PatchMapping + public ApiResponse updateName( + @LoginMember Long id, + @RequestBody NameUpdateRequest updateNameRequest) { + Member member = memberFacade.updateName(id, updateNameRequest.name()); + return ApiResponse.success(MemberSuccessType.UPDATE_NAME_SUCCESS, MemberFindOneResponse.of(member)); + } } diff --git a/module-presentation/src/main/java/com/depromeet/member/dto/request/NameUpdateRequest.java b/module-presentation/src/main/java/com/depromeet/member/dto/request/NameUpdateRequest.java new file mode 100644 index 00000000..af0ae194 --- /dev/null +++ b/module-presentation/src/main/java/com/depromeet/member/dto/request/NameUpdateRequest.java @@ -0,0 +1,6 @@ +package com.depromeet.member.dto.request; + +import jakarta.validation.constraints.NotNull; + +public record NameUpdateRequest(@NotNull String name) { +} diff --git a/module-presentation/src/main/java/com/depromeet/member/facade/MemberFacade.java b/module-presentation/src/main/java/com/depromeet/member/facade/MemberFacade.java new file mode 100644 index 00000000..ff615c07 --- /dev/null +++ b/module-presentation/src/main/java/com/depromeet/member/facade/MemberFacade.java @@ -0,0 +1,29 @@ +package com.depromeet.member.facade; + +import com.depromeet.member.domain.Member; +import com.depromeet.member.port.in.command.SocialMemberCommand; +import com.depromeet.member.port.in.usecase.MemberUseCase; +import com.depromeet.member.port.in.usecase.NameUpdateUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class MemberFacade { + private final MemberUseCase memberUseCase; + private final NameUpdateUseCase nameUpdateUseCase; + + public Member findById(Long memberId) { + return memberUseCase.findById(memberId); + } + + public Member findOrCreateMemberBy(SocialMemberCommand command) { + return memberUseCase.findOrCreateMemberBy(command); + } + + public Member updateName(Long memberId, String name) { + return nameUpdateUseCase.updateName(memberId, name); + } +}