Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service layer의 조회 methods naming 변경 #410

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BookmarkCommandService {
public BookmarkDto mark(long memberId, long placeId) {
validateNotAlreadyMarked(memberId, placeId);

Member member = memberQueryService.findById(memberId);
Member member = memberQueryService.getById(memberId);
Place place = placeRepository.findById(placeId).orElseThrow(PlaceNotFoundException::new);

Bookmark bookmark = bookmarkRepository.save(Bookmark.of(member, place));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MemberController {
)
@GetMapping(value = "/v1/members/me", headers = API_MINOR_VERSION_HEADER_NAME + "=1")
public GetMyInfoResponse getMyInfoV1_1(@AuthenticationPrincipal UserPrincipal userPrincipal) {
return GetMyInfoResponse.from(memberQueryService.findDtoById(userPrincipal.getMemberId()));
return GetMyInfoResponse.from(memberQueryService.getDtoById(userPrincipal.getMemberId()));
}

@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.zelusik.eatery.domain.member.dto.MemberDto;
import com.zelusik.eatery.domain.member.dto.request.MemberUpdateRequest;
import com.zelusik.eatery.domain.member.entity.Member;
import com.zelusik.eatery.domain.member.exception.MemberNotFoundByIdException;
import com.zelusik.eatery.domain.member.exception.MemberNotFoundException;
import com.zelusik.eatery.domain.member.repository.MemberRepository;
import com.zelusik.eatery.domain.member_deletion_survey.constant.MemberDeletionSurveyType;
Expand Down Expand Up @@ -60,7 +59,7 @@ public MemberDto save(MemberDto memberDto) {
@CacheEvict(value = "member", key = "#memberId")
@Transactional
public void rejoin(Long memberId) {
Member member = findByIdWithDeleted(memberId);
Member member = memberQueryService.getByIdWithDeleted(memberId);
member.rejoin();
}

Expand All @@ -74,7 +73,7 @@ public void rejoin(Long memberId) {
@CachePut(value = "member", key = "#memberId")
@Transactional
public MemberDto update(Long memberId, MemberUpdateRequest updateRequest) {
Member member = memberQueryService.findById(memberId);
Member member = memberQueryService.getById(memberId);

MultipartFile profileImageForUpdate = updateRequest.getProfileImage();
if (profileImageForUpdate == null) {
Expand All @@ -84,7 +83,7 @@ public MemberDto update(Long memberId, MemberUpdateRequest updateRequest) {
updateRequest.getGender()
);
} else {
Optional<ProfileImage> oldProfileImage = profileImageQueryService.findOptionalByMember(member);
Optional<ProfileImage> oldProfileImage = profileImageQueryService.findByMember(member);
oldProfileImage.ifPresent(profileImageCommandService::softDelete);

ProfileImage profileImage = profileImageCommandService.upload(member, profileImageForUpdate);
Expand All @@ -109,7 +108,7 @@ public MemberDto update(Long memberId, MemberUpdateRequest updateRequest) {
@CachePut(value = "member", key = "#memberId")
@Transactional
public MemberDto updateFavoriteFoodCategories(Long memberId, List<FoodCategoryValue> favoriteFoodCategories) {
Member member = memberQueryService.findById(memberId);
Member member = memberQueryService.getById(memberId);

favoriteFoodCategoryRepository.deleteAll(member.getFavoriteFoodCategories());
member.getFavoriteFoodCategories().clear();
Expand All @@ -135,7 +134,7 @@ public MemberDto updateFavoriteFoodCategories(Long memberId, List<FoodCategoryVa
@CacheEvict(value = "member", key = "#memberId")
@Transactional
public MemberDeletionSurveyDto delete(Long memberId, MemberDeletionSurveyType surveyType) {
Member member = memberQueryService.findById(memberId);
Member member = memberQueryService.getById(memberId);
if (member.getDeletedAt() != null) {
throw new MemberNotFoundException();
}
Expand All @@ -148,17 +147,4 @@ public MemberDeletionSurveyDto delete(Long memberId, MemberDeletionSurveyType su
memberDeletionSurveyRepository.save(deletionSurvey);
return MemberDeletionSurveyDto.from(deletionSurvey);
}

/**
* 주어진 PK에 해당하는 회원 entity를 DB에서 조회한다.
* 삭제된 회원도 포함해서 조회한다.
*
* @param memberId 조회할 회원의 PK
* @return 조회한 회원 entity
* @throws MemberNotFoundByIdException 일치하는 회원이 없는 경우
*/
private Member findByIdWithDeleted(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new MemberNotFoundByIdException(memberId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,33 @@ public class MemberQueryService {
* @return 조회한 회원 entity
* @throws MemberNotFoundByIdException 일치하는 회원이 없는 경우
*/
public Member findById(Long memberId) {
public Member getById(Long memberId) {
return memberRepository.findByIdAndDeletedAtNull(memberId)
.orElseThrow(() -> new MemberNotFoundByIdException(memberId));
}

/**
* 주어진 PK에 해당하는 회원 entity를 DB에서 조회한다.
* 삭제된 회원도 포함해서 조회한다.
*
* @param memberId 조회할 회원의 PK
* @return 조회한 회원 entity
* @throws MemberNotFoundByIdException 일치하는 회원이 없는 경우
*/
public Member getByIdWithDeleted(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new MemberNotFoundByIdException(memberId));
}

/**
* 주어진 PK에 해당하는 회원을 조회한다.
*
* @param memberId 조회할 회원의 PK
* @return 조회한 회원 dto
*/
@Cacheable(value = "member", key = "#memberId")
public MemberDto findDtoById(Long memberId) {
return MemberDto.from(findById(memberId));
public MemberDto getDtoById(Long memberId) {
return MemberDto.from(getById(memberId));
}

/**
Expand All @@ -51,7 +64,7 @@ public MemberDto findDtoById(Long memberId) {
* @param socialUid 조회할 회원의 socialUid
* @return 조회한 회원 dto. <code>Optional</code> 그대로 반환한다.
*/
public Optional<MemberDto> findOptionalDtoBySocialUidWithDeleted(String socialUid) {
public Optional<MemberDto> findDtoBySocialUidWithDeleted(String socialUid) {
return memberRepository.findBySocialUid(socialUid).map(MemberDto::from);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public FindPlaceResponse findPlaceByIdV1_1(
example = "3"
) @PathVariable Long placeId
) {
PlaceWithMarkedStatusAndImagesDto placeDtos = placeQueryService.findDtoWithMarkedStatusAndImagesById(userPrincipal.getMemberId(), placeId);
PlaceWithMarkedStatusAndImagesDto placeDtos = placeQueryService.getDtoWithMarkedStatusAndImagesById(userPrincipal.getMemberId(), placeId);
return FindPlaceResponse.from(placeDtos);
}

Expand All @@ -108,7 +108,7 @@ public FindPlaceResponse findPlaceByKakaoPidV1_1(
example = "263830255"
) @RequestParam @NotBlank String kakaoPid
) {
PlaceWithMarkedStatusAndImagesDto placeDtos = placeQueryService.findDtoWithMarkedStatusAndImagesByKakaoPid(userPrincipal.getMemberId(), kakaoPid);
PlaceWithMarkedStatusAndImagesDto placeDtos = placeQueryService.getDtoWithMarkedStatusAndImagesByKakaoPid(userPrincipal.getMemberId(), kakaoPid);
return FindPlaceResponse.from(placeDtos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class PlaceQueryService {
* @param kakaoPid 조회하고자 하는 장소의 kakaoPid
* @return 조회한 장소의 optional entity
*/
public Optional<Place> findOptByKakaoPid(String kakaoPid) {
public Optional<Place> findByKakaoPid(String kakaoPid) {
return placeRepository.findByKakaoPid(kakaoPid);
}

Expand All @@ -53,7 +53,7 @@ public Optional<Place> findOptByKakaoPid(String kakaoPid) {
* @return 조회한 장소 entity
* @throws PlaceNotFoundException 조회하고자 하는 장소가 존재하지 않는 경우
*/
public Place findById(Long placeId) {
public Place getById(Long placeId) {
return placeRepository.findById(placeId).orElseThrow(PlaceNotFoundException::new);
}

Expand All @@ -65,8 +65,8 @@ public Place findById(Long placeId) {
* @throws PlaceNotFoundException 조회하고자 하는 장소가 존재하지 않는 경우
*/
@NonNull
public Place findByKakaoPid(@NonNull String kakaoPid) {
return findOptByKakaoPid(kakaoPid).orElseThrow(() -> new PlaceNotFoundByKakaoPidException(kakaoPid));
public Place getByKakaoPid(@NonNull String kakaoPid) {
return findByKakaoPid(kakaoPid).orElseThrow(() -> new PlaceNotFoundByKakaoPidException(kakaoPid));
}

/**
Expand All @@ -75,8 +75,8 @@ public Place findByKakaoPid(@NonNull String kakaoPid) {
* @param placeId 조회하고자 하는 장소의 PK
* @return 조회한 장소 dto
*/
public PlaceWithMarkedStatusAndImagesDto findDtoWithMarkedStatusAndImagesById(Long memberId, Long placeId) {
Place foundPlace = findById(placeId);
public PlaceWithMarkedStatusAndImagesDto getDtoWithMarkedStatusAndImagesById(Long memberId, Long placeId) {
Place foundPlace = getById(placeId);
boolean isMarked = bookmarkQueryService.isMarkedPlace(memberId, foundPlace);
List<ReviewImageDto> latest3Images = reviewImageQueryService.findLatest3ByPlace(foundPlace.getId());
return PlaceWithMarkedStatusAndImagesDto.from(foundPlace, isMarked, latest3Images);
Expand All @@ -89,8 +89,8 @@ public PlaceWithMarkedStatusAndImagesDto findDtoWithMarkedStatusAndImagesById(Lo
* @return 조회한 장소 dto
*/
@NonNull
public PlaceWithMarkedStatusAndImagesDto findDtoWithMarkedStatusAndImagesByKakaoPid(@NonNull Long memberId, @NonNull String kakaoPid) {
Place foundPlace = findByKakaoPid(kakaoPid);
public PlaceWithMarkedStatusAndImagesDto getDtoWithMarkedStatusAndImagesByKakaoPid(@NonNull Long memberId, @NonNull String kakaoPid) {
Place foundPlace = getByKakaoPid(kakaoPid);
boolean isMarked = bookmarkQueryService.isMarkedPlace(memberId, foundPlace);
List<ReviewImageDto> latest3ByPlace = reviewImageQueryService.findLatest3ByPlace(foundPlace.getId());
return PlaceWithMarkedStatusAndImagesDto.from(foundPlace, isMarked, latest3ByPlace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ResponseEntity<PlaceMenusResponse> savePlaceMenusByKakaoPidV1_1(@Paramete
})
@GetMapping(value = "/v1/places/{placeId}/menus", headers = API_MINOR_VERSION_HEADER_NAME + "=1")
public PlaceMenusResponse findPlaceMenusByPlaceIdV1_1(@Parameter(description = "PK of place", example = "3") @PathVariable Long placeId) {
PlaceMenusDto result = placeMenusQueryService.findDtoByPlaceId(placeId);
PlaceMenusDto result = placeMenusQueryService.getDtoByPlaceId(placeId);
return PlaceMenusResponse.fromWithoutIds(result);
}

Expand All @@ -93,7 +93,7 @@ public PlaceMenusResponse findPlaceMenusByPlaceIdV1_1(@Parameter(description = "
)
@GetMapping(value = "/v1/places/menus", headers = API_MINOR_VERSION_HEADER_NAME + "=1")
public PlaceMenusResponse findPlaceMenusByKakaoPidV1_1(@Parameter(description = "장소의 고유 id", example = "1879186093") @RequestParam String kakaoPid) {
PlaceMenusDto result = placeMenusQueryService.findDtoByKakaoPid(kakaoPid);
PlaceMenusDto result = placeMenusQueryService.getDtoByKakaoPid(kakaoPid);
return PlaceMenusResponse.fromWithoutIds(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PlaceMenusDto savePlaceMenus(@NonNull Long placeId) {
if (placeMenusRepository.existsByPlace_Id(placeId)) {
throw new PlaceMenusAlreadyExistsException(placeId);
}
Place place = placeQueryService.findById(placeId);
Place place = placeQueryService.getById(placeId);
return savePlaceMenus(place);
}

Expand All @@ -55,7 +55,7 @@ public PlaceMenusDto savePlaceMenus(@NonNull String kakaoPid) {
if (placeMenusRepository.existsByPlace_KakaoPid(kakaoPid)) {
throw new PlaceMenusAlreadyExistsException(kakaoPid);
}
Place place = placeQueryService.findByKakaoPid(kakaoPid);
Place place = placeQueryService.getByKakaoPid(kakaoPid);
return savePlaceMenus(place);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PlaceMenusQueryService {
* @throws PlaceMenusNotFoundByPlaceIdException placeId에 해당하는 장소 메뉴 데이터가 없는 경우
*/
@NonNull
public PlaceMenusDto findDtoByPlaceId(@NonNull Long placeId) {
public PlaceMenusDto getDtoByPlaceId(@NonNull Long placeId) {
PlaceMenus placeMenus = placeMenusRepository.findByPlace_Id(placeId).orElseThrow(() -> new PlaceMenusNotFoundByPlaceIdException(placeId));
return PlaceMenusDto.from(placeMenus);
}
Expand All @@ -38,7 +38,7 @@ public PlaceMenusDto findDtoByPlaceId(@NonNull Long placeId) {
* @throws PlaceMenusNotFoundByPlaceIdException <code>kakaoPid</code>에 해당하는 장소 메뉴 데이터가 없는 경우
*/
@NonNull
public PlaceMenusDto findDtoByKakaoPid(@NonNull String kakaoPid) {
public PlaceMenusDto getDtoByKakaoPid(@NonNull String kakaoPid) {
PlaceMenus placeMenus = placeMenusRepository.findByPlace_KakaoPid(kakaoPid)
.orElseThrow(() -> new PlaceMenusNotFoundByKakaoPidException(kakaoPid));
return PlaceMenusDto.from(placeMenus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ProfileImageQueryService {
* @param member Member
* @return 조회된 ProfileImage
*/
public Optional<ProfileImage> findOptionalByMember(Member member) {
public Optional<ProfileImage> findByMember(Member member) {
return profileImageRepository.findByMemberAndDeletedAtIsNull(member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class RecommendedReviewCommandService {
* @return 저장된 추천 리뷰 dto
*/
public RecommendedReviewDto saveRecommendedReview(long memberId, long reviewId, short ranking) {
Member member = memberQueryService.findById(memberId);
Review review = reviewQueryService.findById(reviewId);
Member member = memberQueryService.getById(memberId);
Review review = reviewQueryService.getById(reviewId);

RecommendedReview recommendedReview = RecommendedReview.of(member, review, ranking);
recommendedReviewRepository.save(recommendedReview);
Expand All @@ -50,13 +50,13 @@ public RecommendedReviewDto saveRecommendedReview(long memberId, long reviewId,
* @return 갱신된 추천 리뷰 목록
*/
public List<RecommendedReviewDto> batchUpdateRecommendedReviews(long memberId, BatchUpdateRecommendedReviewsRequest batchUpdateRecommendedReviewsRequest) {
Member member = memberQueryService.findById(memberId);
Member member = memberQueryService.getById(memberId);
recommendedReviewRepository.deleteAllByMember(member);
recommendedReviewRepository.flush();

List<RecommendedReview> recommendedReviewsForBatchUpdate = batchUpdateRecommendedReviewsRequest.getRecommendedReviews().stream()
.map(request -> {
Review review = reviewQueryService.findById(request.getReviewId());
Review review = reviewQueryService.getById(request.getReviewId());
return RecommendedReview.of(member, review, request.getRanking());
})
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public FindReviewResponse findReviewV1_1(
) @PathVariable Long reviewId
) {
Long loginMemberId = userPrincipal.getMemberId();
ReviewWithPlaceMarkedStatusDto reviewWithPlaceMarkedStatusDto = reviewQueryService.findDtoById(loginMemberId, reviewId);
ReviewWithPlaceMarkedStatusDto reviewWithPlaceMarkedStatusDto = reviewQueryService.getDtoById(loginMemberId, reviewId);
return FindReviewResponse.from(reviewWithPlaceMarkedStatusDto, loginMemberId);
}

Expand Down Expand Up @@ -163,7 +163,7 @@ public SliceResponse<FindReviewFeedResponse> findReviewFeedV1_1(
example = "15"
) @RequestParam(required = false, defaultValue = "15") int size
) {
Slice<ReviewWithPlaceMarkedStatusDto> reviewDtos = reviewQueryService.findReviewReed(userPrincipal.getMemberId(), PageRequest.of(page, size));
Slice<ReviewWithPlaceMarkedStatusDto> reviewDtos = reviewQueryService.findReviewFeed(userPrincipal.getMemberId(), PageRequest.of(page, size));
return new SliceResponse<FindReviewFeedResponse>().from(reviewDtos.map(FindReviewFeedResponse::from));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class ReviewCommandService {
*/
public ReviewWithPlaceMarkedStatusDto create(Long writerId, ReviewCreateRequest reviewRequest) {
List<ReviewImageCreateRequest> images = reviewRequest.getImages();
Place place = placeQueryService.findById(reviewRequest.getPlaceId());
Member writer = memberQueryService.findById(writerId);
Place place = placeQueryService.getById(reviewRequest.getPlaceId());
Member writer = memberQueryService.getById(writerId);

// 리뷰 저장
ReviewDto reviewWithPlaceMarkedStatusDto = reviewRequest.toDto(PlaceDto.from(place));
Expand Down Expand Up @@ -106,7 +106,7 @@ public ReviewWithPlaceMarkedStatusDto create(Long writerId, ReviewCreateRequest
* @throws ReviewUpdatePermissionDeniedException 리뷰 수정 권한이 없는 경우
*/
public ReviewWithPlaceMarkedStatusDto update(Long memberId, Long reviewId, @Nullable String content) {
Review review = reviewQueryService.findById(reviewId);
Review review = reviewQueryService.getById(reviewId);
validateReviewUpdatePermission(memberId, review);
review.update(content);

Expand All @@ -122,8 +122,8 @@ public ReviewWithPlaceMarkedStatusDto update(Long memberId, Long reviewId, @Null
* @throws ReviewDeletePermissionDeniedException 리뷰 삭제 권한이 없는 경우
*/
public void delete(Long memberId, Long reviewId) {
Member member = memberQueryService.findById(memberId);
Review review = reviewQueryService.findById(reviewId);
Member member = memberQueryService.getById(memberId);
Review review = reviewQueryService.getById(reviewId);

validateReviewDeletePermission(member, review);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ReviewQueryService {
* @param reviewId 조회하고자 하는 리뷰의 PK
* @return 조회된 리뷰
*/
public Review findById(Long reviewId) {
public Review getById(Long reviewId) {
return reviewRepository.findByIdAndDeletedAtNull(reviewId)
.orElseThrow(() -> new ReviewNotFoundByIdException(reviewId));
}
Expand All @@ -43,8 +43,8 @@ public Review findById(Long reviewId) {
* @param reviewId 조회하고자 하는 리뷰의 PK
* @return 조회된 리뷰 dto
*/
public ReviewWithPlaceMarkedStatusDto findDtoById(Long memberId, Long reviewId) {
Review review = findById(reviewId);
public ReviewWithPlaceMarkedStatusDto getDtoById(Long memberId, Long reviewId) {
Review review = getById(reviewId);
boolean isMarkedPlace = bookmarkQueryService.isMarkedPlace(memberId, review.getPlace());
return ReviewWithPlaceMarkedStatusDto.from(review, List.of(WRITER, PLACE), isMarkedPlace);
}
Expand Down Expand Up @@ -78,7 +78,7 @@ public Slice<ReviewWithPlaceMarkedStatusDto> findDtos(long loginMemberId, Long w
* @param pageable paging 정보
* @return 조회된 리뷰 dtos
*/
public Slice<ReviewWithPlaceMarkedStatusDto> findReviewReed(long loginMemberId, Pageable pageable) {
public Slice<ReviewWithPlaceMarkedStatusDto> findReviewFeed(long loginMemberId, Pageable pageable) {
return reviewRepository.findReviewFeed(loginMemberId, pageable);
}
}
Loading