Skip to content

Commit

Permalink
[refactor/Inhabas#264] 이름 변경 승인 시 변경된 이름 적용
Browse files Browse the repository at this point in the history
[refactor/Inhabas#264] 이름 변경 승인 시 변경된 이름 적용
  • Loading branch information
whitem4rk authored Mar 28, 2024
2 parents 23768cf + 1f4cd5e commit 4864a40
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +133,7 @@ public List<UpdateNameRequestDto> 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())
Expand Down Expand Up @@ -166,6 +167,7 @@ public List<UpdateNameRequestDto> getMyInfoRequests() {
}

@Override
@Transactional
public void handleMyInfoRequest(HandleNameRequestDto handleNameRequestDto) {

UpdateNameRequest updateNameRequest =
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public ResponseEntity<Void> updateMyProfileImage(
return ResponseEntity.noContent().build();
}

@Operation(summary = "내 정보 이름 수정", description = "이름 수정, 회장의 승인 필요")
@Operation(summary = "내 정보 이름 수정 요청", description = "이름 수정, 회장의 승인 필요")
@ApiResponses(
value = {
@ApiResponse(responseCode = "204"),
Expand Down Expand Up @@ -199,7 +199,7 @@ public ResponseEntity<PagedResponseDto<UpdateNameRequestDto>> getMyInfoRequests(
return ResponseEntity.ok(new PagedResponseDto<>(pageInfoDto, pagedDtos));
}

@Operation(summary = "이름 수정 요청 처리", description = "이름 수정 요청 처리")
@Operation(summary = "이름 수정 요청 처리", description = "이름 수정이 승인되면 이름 변경, 거절되면 사유 작성")
@ApiResponses(
value = {
@ApiResponse(responseCode = "204"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 4864a40

Please sign in to comment.