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

feat: 마이페이지 카페 조회 시 roadAddress 및 내가 남긴 리뷰 함께 조회 기능 구현 #137

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,6 +1,7 @@
package mocacong.server.dto.response;

import lombok.*;
import mocacong.server.domain.Comment;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -13,4 +14,14 @@ public class MyCommentCafeResponse {
private String studyType;
private String comment;
private String roadAddress;

public static MyCommentCafeResponse from(Comment comment) {
return new MyCommentCafeResponse(
comment.getCafe().getMapId(),
comment.getCafe().getName(),
comment.getCafe().getStudyType(),
comment.getContent(),
comment.getCafe().getRoadAddress()
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요런 정적팩터리메서드를 생각하긴 했는데요
MyCommentCafeResponse of(String content, Cafe commentCafe)

getter + getter를 좀 줄일만한 그런 느낌으로?
근데 어느게 나은진 잘 모르겠네요 😅

}
20 changes: 7 additions & 13 deletions src/main/java/mocacong/server/service/CafeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ public void save(CafeRegisterRequest request) {

Optional<Cafe> cafeOptional = cafeRepository.findByMapId(request.getId());

if (cafeOptional.isPresent()) {
cafeOptional.get().updateCafeRoadAddress(request.getRoadAddress());
return;
}

try {
cafeRepository.save(cafe);
cafeRepository.findByMapId(request.getId())
.ifPresentOrElse(
existedCafe -> existedCafe.updateCafeRoadAddress(request.getRoadAddress()),
() -> cafeRepository.save(cafe)
);
} catch (DataIntegrityViolationException e) {
throw new DuplicateCafeException();
}

}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -180,13 +180,7 @@ public MyCommentCafesResponse findMyCommentCafes(Long memberId, int page, int co
Slice<Comment> comments = commentRepository.findByMemberId(member.getId(), PageRequest.of(page, count));

List<MyCommentCafeResponse> responses = comments.stream()
.map(comment -> new MyCommentCafeResponse(
comment.getCafe().getMapId(),
comment.getCafe().getName(),
comment.getCafe().getStudyType(),
comment.getContent(),
comment.getCafe().getRoadAddress()
))
.map(MyCommentCafeResponse::from)
.collect(Collectors.toList());
return new MyCommentCafesResponse(comments.isLast(), responses);
}
Expand Down