Skip to content

Commit

Permalink
feat: 이름 수정 API 구현 및 Facade 적용 (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywonchae1 committed Jul 30, 2024
1 parent 449993d commit f6afb4d
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface MemberPersistencePort {
void updateRefresh(Long memberId, String refreshToken);

Optional<Member> updateGoal(Long memberId, Integer goal);

Optional<Member> updateName(Long memberId, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ public MemberEntity updateGoal(Integer goal) {
this.goal = goal;
return this;
}

public MemberEntity updateName(String name) {
this.name = name;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ public Optional<Member> updateGoal(Long memberId, Integer goal) {
.findById(memberId)
.map(memberEntity -> memberEntity.updateGoal(goal).toModel());
}

@Override
public Optional<Member> updateName(Long memberId, String name) {
return memberJpaRepository
.findById(memberId)
.map(memberEntity -> memberEntity.updateName(name).toModel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MemberFindOneResponse> getMember(@PathVariable("id") Long id);

@Operation(summary = "닉네임 수정")
ApiResponse<MemberFindOneResponse> updateName(
@LoginMember Long id,
@RequestBody NameUpdateRequest updateNameRequest);
}
Original file line number Diff line number Diff line change
@@ -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<MemberFindOneResponse> 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<MemberFindOneResponse> updateName(
@LoginMember Long id,
@RequestBody NameUpdateRequest updateNameRequest) {
Member member = memberFacade.updateName(id, updateNameRequest.name());
return ApiResponse.success(MemberSuccessType.UPDATE_NAME_SUCCESS, MemberFindOneResponse.of(member));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.depromeet.member.dto.request;

import jakarta.validation.constraints.NotNull;

public record NameUpdateRequest(@NotNull String name) {
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit f6afb4d

Please sign in to comment.