diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/UpdateNameRequest.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/UpdateNameRequest.java index 430d79ab..9bbb2a07 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/UpdateNameRequest.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/UpdateNameRequest.java @@ -34,6 +34,9 @@ public class UpdateNameRequest { @Embedded private Name name; + @Column(name = "BEFORE_NAME", nullable = false, length = 50) + private String beforeName; + @CreatedDate @Column( name = "DATE_REQUESTED", @@ -55,6 +58,7 @@ public class UpdateNameRequest { public UpdateNameRequest(Member member, String name) { this.member = member; this.name = new Name(name); + this.beforeName = member.getName(); this.dateRequested = LocalDateTime.now(); this.requestStatus = PENDING; } diff --git a/resource-server/src/main/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImpl.java b/resource-server/src/main/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImpl.java index 3a6ebd71..e495eed0 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImpl.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImpl.java @@ -15,6 +15,7 @@ import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.auth.domain.oauth2.member.domain.entity.UpdateNameRequest; import com.inhabas.api.auth.domain.oauth2.member.domain.exception.MemberNotFoundException; +import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.RequestStatus; import com.inhabas.api.auth.domain.oauth2.member.dto.*; import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository; import com.inhabas.api.auth.domain.oauth2.member.repository.UpdateNameRequestRepository; @@ -132,7 +133,7 @@ public List getMyInfoMyRequests(Long memberId) { .studentId(request.getMember().getStudentId()) .major(request.getMember().getSchoolInformation().getMajor()) .role(request.getMember().getRole()) - .beforeName(request.getMember().getName()) + .beforeName(request.getBeforeName()) .afterName(request.getName().getValue()) .dateRequested(request.getDateRequested()) .status(request.getRequestStatus()) @@ -166,6 +167,7 @@ public List getMyInfoRequests() { } @Override + @Transactional public void handleMyInfoRequest(HandleNameRequestDto handleNameRequestDto) { UpdateNameRequest updateNameRequest = @@ -177,5 +179,11 @@ public void handleMyInfoRequest(HandleNameRequestDto handleNameRequestDto) { handleNameRequestDto.getStatus(), handleNameRequestDto.getRejectReason()); updateNameRequestRepository.save(updateNameRequest); + + if (updateNameRequest.getRequestStatus() == RequestStatus.APPROVED) { + Member member = updateNameRequest.getMember(); + member.setName(updateNameRequest.getName().getValue()); + memberRepository.save(member); + } } } diff --git a/resource-server/src/main/java/com/inhabas/api/web/MyInfoController.java b/resource-server/src/main/java/com/inhabas/api/web/MyInfoController.java index 296120c8..3c1bad5b 100644 --- a/resource-server/src/main/java/com/inhabas/api/web/MyInfoController.java +++ b/resource-server/src/main/java/com/inhabas/api/web/MyInfoController.java @@ -123,7 +123,7 @@ public ResponseEntity updateMyProfileImage( return ResponseEntity.noContent().build(); } - @Operation(summary = "내 정보 이름 수정", description = "이름 수정, 회장의 승인 필요") + @Operation(summary = "내 정보 이름 수정 요청", description = "이름 수정, 회장의 승인 필요") @ApiResponses( value = { @ApiResponse(responseCode = "204"), @@ -199,7 +199,7 @@ public ResponseEntity> getMyInfoRequests( return ResponseEntity.ok(new PagedResponseDto<>(pageInfoDto, pagedDtos)); } - @Operation(summary = "이름 수정 요청 처리", description = "이름 수정 요청 처리") + @Operation(summary = "이름 수정 요청 처리", description = "이름 수정이 승인되면 이름 변경, 거절되면 사유 작성") @ApiResponses( value = { @ApiResponse(responseCode = "204"), diff --git a/resource-server/src/test/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImplTest.java b/resource-server/src/test/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImplTest.java index aa2478db..fd063406 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImplTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/member/usecase/MemberProfileServiceImplTest.java @@ -12,6 +12,8 @@ import org.springframework.web.multipart.MultipartFile; import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; +import com.inhabas.api.auth.domain.oauth2.member.domain.entity.UpdateNameRequest; +import com.inhabas.api.auth.domain.oauth2.member.dto.HandleNameRequestDto; import com.inhabas.api.auth.domain.oauth2.member.dto.MyProfileDto; import com.inhabas.api.auth.domain.oauth2.member.dto.ProfileDetailDto; import com.inhabas.api.auth.domain.oauth2.member.dto.ProfileIntroDto; @@ -108,6 +110,32 @@ void requestMyProfileNameTest() { then(updateNameRequestRepository).should(times(1)).save(any()); } + @DisplayName("회장이 내 정보 [이름] 변경 요청을 승인하면, 회원의 이름이 업데이트된다.") + @Test + void approveNameChangeRequestUpdatesMemberNameTest() { + // given + Long requestId = 1L; + String newName = "송민석"; + Member member = MemberTest.basicMember1(); + + UpdateNameRequest updateNameRequest = new UpdateNameRequest(member, newName); + updateNameRequest.handleRequest("pass", null); + + given(updateNameRequestRepository.findById(any())).willReturn(Optional.of(updateNameRequest)); + given(memberRepository.save(any())).willAnswer(invocation -> invocation.getArgument(0)); + + HandleNameRequestDto handleNameRequestDto = new HandleNameRequestDto(requestId, "pass", null); + + // when + memberProfileService.handleMyInfoRequest(handleNameRequestDto); + + // then + then(memberRepository).should(times(1)).save(memberArgumentCaptor.capture()); + Member updatedMember = memberArgumentCaptor.getValue(); + + assertThat(updatedMember.getName()).as("이름 변경사항이 일치하지 않습니다.").isEqualTo(newName); + } + @DisplayName("내 정보 [프로필 사진] 수정시 null이 주어지면 기본 프로필 사진으로 업데이트한다.") @Test void updateMyProfileImageWithNullTest() {