Skip to content

Commit

Permalink
refactor: 불필요한 Member updateProfileUrl 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-sile committed Nov 1, 2023
1 parent 819ed48 commit 2b50448
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void test_findProfile() throws Exception {
void deleteMemberTest() throws Exception {
//given
final long memberId = 1L;
doNothing().when(memberUpdateService).deleteMember(any(), anyLong());
doNothing().when(memberCommandService).deleteMember(any(), anyLong());
final String accessToken = "access_token";

//when
Expand All @@ -272,7 +272,7 @@ void updateProfile() throws Exception {
final String accessToken = "access_token";
final MockMultipartHttpServletRequestBuilder builder = createUpdateProfileBuilder(memberId);

when(memberUpdateService.updateMemberProfile
when(memberCommandService.updateMemberProfile
(any(MultipartFile.class), anyLong(), any(Member.class)))
.thenReturn(memberImageResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.emmsale.member.application.InterestTagService;
import com.emmsale.member.application.MemberActivityService;
import com.emmsale.member.application.MemberQueryService;
import com.emmsale.member.application.MemberUpdateService;
import com.emmsale.member.application.MemberCommandService;
import com.emmsale.message_room.application.MessageCommandService;
import com.emmsale.message_room.application.RoomQueryService;
import com.emmsale.notification.application.FcmTokenRegisterService;
Expand Down Expand Up @@ -69,7 +69,7 @@ abstract class MockMvcTestHelper {
@MockBean
protected MemberActivityService memberActivityService;
@MockBean
protected MemberUpdateService memberUpdateService;
protected MemberCommandService memberCommandService;
@MockBean
protected MemberQueryService memberQueryService;
@MockBean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.emmsale.member.api;

import com.emmsale.member.application.MemberActivityService;
import com.emmsale.member.application.MemberActivityCommandService;
import com.emmsale.member.application.MemberActivityQueryService;
import com.emmsale.member.application.MemberCommandService;
import com.emmsale.member.application.MemberQueryService;
import com.emmsale.member.application.MemberUpdateService;
import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.MemberActivityAddRequest;
import com.emmsale.member.application.dto.MemberActivityInitialRequest;
import com.emmsale.member.application.dto.MemberActivityResponses;
import com.emmsale.member.application.dto.MemberImageResponse;
import com.emmsale.member.application.dto.MemberProfileResponse;
import com.emmsale.member.application.dto.OpenProfileUrlRequest;
import com.emmsale.member.domain.Member;
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -32,16 +31,17 @@
@RequiredArgsConstructor
public class MemberApi {

private final MemberActivityService memberActivityService;
private final MemberUpdateService memberUpdateService;
private final MemberActivityQueryService memberActivityQueryService;
private final MemberActivityCommandService memberActivityCommandService;
private final MemberCommandService memberCommandService;
private final MemberQueryService memberQueryService;

@PostMapping("/members")
public ResponseEntity<Void> register(
final Member member,
@RequestBody final MemberActivityInitialRequest memberActivityInitialRequest
) {
memberActivityService.registerActivities(member, memberActivityInitialRequest);
memberActivityCommandService.registerActivities(member, memberActivityInitialRequest);
return ResponseEntity.noContent().build();
}

Expand All @@ -51,37 +51,28 @@ public ResponseEntity<List<MemberActivityResponses>> addActivity(
@RequestBody final MemberActivityAddRequest memberActivityAddRequest
) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(memberActivityService.addActivity(member, memberActivityAddRequest));
.body(memberActivityCommandService.addActivity(member, memberActivityAddRequest));
}

@DeleteMapping("/members/activities")
public ResponseEntity<List<MemberActivityResponses>> deleteActivity(final Member member,
@RequestParam("activity-ids") final List<Long> deleteActivityIds) {
return ResponseEntity.ok(
memberActivityService.deleteActivity(member, deleteActivityIds));
memberActivityCommandService.deleteActivity(member, deleteActivityIds));
}

@GetMapping("/members/{member-id}/activities")
public ResponseEntity<List<MemberActivityResponses>> findActivity(
@PathVariable("member-id") final Long memberId) {
return ResponseEntity.ok(memberActivityService.findActivities(memberId));
}

@PutMapping("/members/open-profile-url")
public ResponseEntity<Void> updateOpenProfileUrl(
final Member member,
@RequestBody @Valid final OpenProfileUrlRequest openProfileUrlRequest
) {
memberUpdateService.updateOpenProfileUrl(member, openProfileUrlRequest);
return ResponseEntity.noContent().build();
return ResponseEntity.ok(memberActivityQueryService.findActivities(memberId));
}

@PutMapping("/members/description")
public ResponseEntity<Void> updateDescription(
final Member member,
@RequestBody final DescriptionRequest descriptionRequest
) {
memberUpdateService.updateDescription(member, descriptionRequest);
memberCommandService.updateDescription(member, descriptionRequest);
return ResponseEntity.noContent().build();
}

Expand All @@ -96,7 +87,7 @@ public ResponseEntity<Void> deleteMember(
@PathVariable final Long memberId,
final Member member
) {
memberUpdateService.deleteMember(member, memberId);
memberCommandService.deleteMember(member, memberId);
return ResponseEntity.noContent().build();
}

Expand All @@ -107,7 +98,7 @@ public ResponseEntity<MemberImageResponse> updateProfile(
final Member member
) {
final MemberImageResponse memberImageResponse
= memberUpdateService.updateMemberProfile(image, memberId, member);
= memberCommandService.updateMemberProfile(image, memberId, member);
return ResponseEntity.ok(memberImageResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.emmsale.image.application.S3Client;
import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.MemberImageResponse;
import com.emmsale.member.application.dto.MemberProfileResponse;
import com.emmsale.member.application.dto.OpenProfileUrlRequest;
import com.emmsale.member.domain.Member;
import com.emmsale.member.domain.MemberRepository;
import com.emmsale.member.exception.MemberException;
Expand All @@ -18,22 +16,11 @@
@Service
@Transactional
@RequiredArgsConstructor
public class MemberUpdateService {
public class MemberCommandService {

private final MemberRepository memberRepository;
private final S3Client s3Client;

public void updateOpenProfileUrl(
final Member member,
final OpenProfileUrlRequest openProfileUrlRequest
) {
final Member persistMember = memberRepository.findById(member.getId())
.orElseThrow(() -> new MemberException((MemberExceptionType.NOT_FOUND_MEMBER)));
final String openProfileUrl = openProfileUrlRequest.getOpenProfileUrl();

persistMember.updateOpenProfileUrl(openProfileUrl);
}

public void updateDescription(final Member member, final DescriptionRequest descriptionRequest) {
final String description = descriptionRequest.getDescription();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.emmsale.base.BaseEntity;
import com.emmsale.member.exception.MemberException;
import com.emmsale.member.exception.MemberExceptionType;
import java.util.Optional;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -30,9 +29,6 @@ public class Member extends BaseEntity {
private String name;
@Column(nullable = false)
private String description;
@Column
@Getter(value = AccessLevel.PRIVATE)
private String openProfileUrl;
@Column(nullable = false)
private String imageUrl;
@Column(nullable = false)
Expand All @@ -59,10 +55,6 @@ public void updateName(final String name) {
this.name = name;
}

public void updateOpenProfileUrl(final String openProfileUrl) {
this.openProfileUrl = openProfileUrl;
}

public void updateDescription(final String description) {
validateDescriptionNull(description);
validateDescriptionLength(description);
Expand Down Expand Up @@ -112,8 +104,4 @@ public boolean isOnboarded() {
public boolean isNotGithubProfile() {
return !imageUrl.startsWith(GITHUB_PROFILE_DOMAIN);
}

public Optional<String> getOptionalOpenProfileUrl() {
return Optional.ofNullable(openProfileUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import com.emmsale.helper.ServiceIntegrationTestHelper;
import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.OpenProfileUrlRequest;
import com.emmsale.member.domain.Member;
import com.emmsale.member.domain.MemberRepository;
import com.emmsale.member.exception.MemberException;
Expand All @@ -32,31 +31,13 @@
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.multipart.MultipartFile;

class MemberUpdateServiceTest extends ServiceIntegrationTestHelper {
class MemberCommandServiceTest extends ServiceIntegrationTestHelper {

@Autowired
private MemberUpdateService memberUpdateService;
private MemberCommandService memberCommandService;
@Autowired
private MemberRepository memberRepository;

@Test
@DisplayName("오픈 프로필 URL을 업데이트한다.")
void updateOpenProfileUrlTest() {
// given
final Member member = memberRepository.save(memberFixture());

final String expectOpenProfileUrl = "https://open.kakao.com/new/profile/url";
final OpenProfileUrlRequest request = new OpenProfileUrlRequest(expectOpenProfileUrl);

// when
memberUpdateService.updateOpenProfileUrl(member, request);

final Member actualMember = memberRepository.findById(member.getId()).get();

// then
assertThat(actualMember.getOptionalOpenProfileUrl().get()).isEqualTo(expectOpenProfileUrl);
}

@Nested
@DisplayName("한줄 자기소개를 업데이트한다.")
class UpdateDescription {
Expand All @@ -72,7 +53,7 @@ void updateDescription_success(final String inputDescription) {
final DescriptionRequest request = new DescriptionRequest(expectDescription);

// when
memberUpdateService.updateDescription(member, request);
memberCommandService.updateDescription(member, request);

final Member actualMember = memberRepository.findById(member.getId()).get();

Expand All @@ -90,7 +71,7 @@ void updateDescription_fail() {
final DescriptionRequest request = new DescriptionRequest(invalidDescription);

// when
final ThrowingCallable actual = () -> memberUpdateService.updateDescription(member, request);
final ThrowingCallable actual = () -> memberCommandService.updateDescription(member, request);

// then
assertThatThrownBy(actual)
Expand All @@ -110,7 +91,7 @@ void updateDescription_trim(final String inputDescription) {
final DescriptionRequest request = new DescriptionRequest(inputDescription);

// when
memberUpdateService.updateDescription(member, request);
memberCommandService.updateDescription(member, request);

final Member actualMember = memberRepository.findById(member.getId()).get();

Expand All @@ -131,7 +112,7 @@ void success() {
final Member member = memberRepository.findById(memberId).get();

//when
memberUpdateService.deleteMember(member, memberId);
memberCommandService.deleteMember(member, memberId);

//then
assertThat(memberRepository.findById(memberId))
Expand All @@ -146,7 +127,7 @@ void forbbidenDeleteMemberException() {
final Member member = memberRepository.findById(memberId).get();

//when && then
assertThatThrownBy(() -> memberUpdateService.deleteMember(member, otherMemberId))
assertThatThrownBy(() -> memberCommandService.deleteMember(member, otherMemberId))
.isInstanceOf(MemberException.class)
.hasMessage(MemberExceptionType.FORBIDDEN_DELETE_MEMBER.errorMessage());
}
Expand Down Expand Up @@ -178,7 +159,7 @@ void pastGithubUrl() {
final Member member = memberRepository.save(fixture);

//when
memberUpdateService.updateMemberProfile(image, member.getId(), member);
memberCommandService.updateMemberProfile(image, member.getId(), member);

//then
assertAll(
Expand All @@ -198,7 +179,7 @@ void pastCustomImage() {
final Member member = memberRepository.save(fixture);

//when
memberUpdateService.updateMemberProfile(image, member.getId(), member);
memberCommandService.updateMemberProfile(image, member.getId(), member);

//then
assertAll(
Expand All @@ -219,7 +200,7 @@ void validateMemberIsNotMe() {

//when && then
final ThrowingCallable testTarget = () ->
memberUpdateService.updateMemberProfile(image, member.getId() + 1, member);
memberCommandService.updateMemberProfile(image, member.getId() + 1, member);

assertThatThrownBy(testTarget)
.isInstanceOf(MemberException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ void trueCase() {
assertTrue(member.isNotGithubProfile());
}
}

}

0 comments on commit 2b50448

Please sign in to comment.