Skip to content

Commit

Permalink
feat: cafe roadAddress 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jung-woo-kim committed Nov 12, 2023
1 parent ada2ac4 commit cfbc66b
Show file tree
Hide file tree
Showing 34 changed files with 210 additions and 176 deletions.
10 changes: 9 additions & 1 deletion src/main/java/mocacong/server/domain/Cafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class Cafe extends BaseTime {
@Column(name = "map_id", unique = true, nullable = false)
private String mapId;

@Column(name = "road_address", nullable = false)
private String roadAddress;

@OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Score> score;

Expand All @@ -44,9 +47,10 @@ public class Cafe extends BaseTime {
@OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY)
private List<Comment> comments;

public Cafe(String mapId, String name) {
public Cafe(String mapId, String name, String roadAddress) {
this.mapId = mapId;
this.name = name;
this.roadAddress = roadAddress;
this.cafeDetail = new CafeDetail();
this.cafeImages = new ArrayList<>();
this.score = new ArrayList<>();
Expand All @@ -71,6 +75,10 @@ public void updateCafeDetails() {
this.cafeDetail = new CafeDetail(studyType, wifi, parking, toilet, desk, power, sound);
}

public void updateCafeRoadAddress(String roadAddress) {
this.roadAddress = roadAddress;
}

private StudyType getMostFrequentStudyType() {
int solo = 0, group = 0;
for (Review review : reviews) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public class CafeRegisterRequest {

@NotBlank(message = "1012:공백일 수 없습니다.")
private String name;

@NotBlank(message = "1012:공백일 수 없습니다.")
private String roadAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class MyCommentCafeResponse {
private String name;
private String studyType;
private String comment;
private String roadAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
@AllArgsConstructor
@ToString
public class MyFavoriteCafeResponse {

private String mapId;
private String name;
private String studyType;
private double score;
private String roadAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public class MyReviewCafeResponse {
private String name;
private String myStudyType;
private int myScore;
private String roadAddress;

public MyReviewCafeResponse(String mapId, String name, StudyType myStudyType, int myScore) {
public MyReviewCafeResponse(String mapId, String name, StudyType myStudyType, int myScore, String roadAddress) {
this.mapId = mapId;
this.name = name;
this.myStudyType = myStudyType.getValue();
this.myStudyType = myStudyType.toString();
this.myScore = myScore;
this.roadAddress = roadAddress;
}
}
4 changes: 2 additions & 2 deletions src/main/java/mocacong/server/repository/CafeRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public interface CafeRepository extends JpaRepository<Cafe, Long> {
"where m.id = :id")
Slice<Cafe> findByMyFavoriteCafes(Long id, Pageable pageRequest);

@Query("select new mocacong.server.dto.response.MyReviewCafeResponse(c.mapId,c.name,r.cafeDetail.studyType,s.score) from Review r " +
@Query("select new mocacong.server.dto.response.MyReviewCafeResponse(c.mapId,c.name,r.cafeDetail.studyType,s.score,c.roadAddress) from Review r " +
"join r.cafe c " +
"join r.member m " +
"join c.score s "+
"join c.score s " +
"where m.id = :id and s.member.id = :id")
Slice<MyReviewCafeResponse> findMyReviewCafesById(Long id, Pageable pageRequest);
}
15 changes: 12 additions & 3 deletions src/main/java/mocacong/server/service/CafeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -53,7 +54,14 @@ public class CafeService {

@Transactional
public void save(CafeRegisterRequest request) {
Cafe cafe = new Cafe(request.getId(), request.getName());
Cafe cafe = new Cafe(request.getId(), request.getName(), request.getRoadAddress());

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

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

try {
cafeRepository.save(cafe);
Expand Down Expand Up @@ -149,7 +157,7 @@ public MyFavoriteCafesResponse findMyFavoriteCafes(Long memberId, Integer page,
List<MyFavoriteCafeResponse> responses = myFavoriteCafes
.getContent()
.stream()
.map(cafe -> new MyFavoriteCafeResponse(cafe.getMapId(), cafe.getName(), cafe.getStudyType(), cafe.findAverageScore()))
.map(cafe -> new MyFavoriteCafeResponse(cafe.getMapId(), cafe.getName(), cafe.getStudyType(), cafe.findAverageScore(), cafe.getRoadAddress()))
.collect(Collectors.toList());
return new MyFavoriteCafesResponse(myFavoriteCafes.isLast(), responses);
}
Expand All @@ -176,7 +184,8 @@ public MyCommentCafesResponse findMyCommentCafes(Long memberId, int page, int co
comment.getCafe().getMapId(),
comment.getCafe().getName(),
comment.getCafe().getStudyType(),
comment.getContent()
comment.getContent(),
comment.getCafe().getRoadAddress()
))
.collect(Collectors.toList());
return new MyCommentCafesResponse(comments.isLast(), responses);
Expand Down
30 changes: 15 additions & 15 deletions src/test/java/mocacong/server/acceptance/CafeAcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CafeAcceptanceTest extends AcceptanceTest {
@Test
@DisplayName("카페를 정상적으로 등록한다")
void cafeSave() {
CafeRegisterRequest request = new CafeRegisterRequest("1", "메리네 카페");
CafeRegisterRequest request = new CafeRegisterRequest("1", "메리네 카페", "서울시 강남구");

RestAssured.given().log().all()
.contentType(MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -36,7 +36,7 @@ void cafeSave() {
@DisplayName("특정 카페 정보를 조회한다")
void findCafe() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand All @@ -55,7 +55,7 @@ void findCafe() {
@DisplayName("카페에 대한 리뷰를 작성한다")
void saveCafeReview() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand Down Expand Up @@ -83,7 +83,7 @@ void saveCafeReview() {
@DisplayName("카페에 대해 내가 작성한 리뷰를 조회한다")
void findMyCafeReview() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand All @@ -103,7 +103,7 @@ void findMyCafeReview() {
@DisplayName("카페에 대한 리뷰를 다시 작성할 수 없다")
void saveCafeReviewManyTimes() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand All @@ -126,7 +126,7 @@ void saveCafeReviewManyTimes() {
@DisplayName("등록한 카페에 대한 리뷰를 수정한다")
void updateCafeReview() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));
MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
String token = 로그인_토큰_발급(signUpRequest.getEmail(), signUpRequest.getPassword());
Expand Down Expand Up @@ -157,7 +157,7 @@ void updateCafeReview() {
@DisplayName("등록하지 않은 카페에 대한 리뷰는 수정할 수 없다")
void updateCafeReviewNotFoundReview() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));
MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
String token = 로그인_토큰_발급(signUpRequest.getEmail(), signUpRequest.getPassword());
Expand All @@ -178,7 +178,7 @@ void updateCafeReviewNotFoundReview() {
@DisplayName("카페 정보를 미리보기한다")
void previewCafe() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "100"));

MemberSignUpRequest signUpRequest1 = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
MemberSignUpRequest signUpRequest2 = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "메리");
Expand Down Expand Up @@ -206,9 +206,9 @@ void getCafesFilterStudyType() {
String mapId1 = "12332312";
String mapId2 = "12355412";
String mapId3 = "18486512";
카페_등록(new CafeRegisterRequest(mapId1, "메리네 카페 본점"));
카페_등록(new CafeRegisterRequest(mapId2, "메리네 카페 2호점"));
카페_등록(new CafeRegisterRequest(mapId3, "메리네 카페 3호점"));
카페_등록(new CafeRegisterRequest(mapId1, "메리네 카페 본점", "서울시 강남구"));
카페_등록(new CafeRegisterRequest(mapId2, "메리네 카페 2호점", "서울시 강남구"));
카페_등록(new CafeRegisterRequest(mapId3, "메리네 카페 3호점", "서울시 강남구"));
MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
String token = 로그인_토큰_발급(signUpRequest.getEmail(), signUpRequest.getPassword());
Expand Down Expand Up @@ -242,9 +242,9 @@ void getCafesFilterFavorites() {
String mapId1 = "12332312";
String mapId2 = "12355412";
String mapId3 = "18486512";
카페_등록(new CafeRegisterRequest(mapId1, "메리네 카페 본점"));
카페_등록(new CafeRegisterRequest(mapId2, "메리네 카페 2호점"));
카페_등록(new CafeRegisterRequest(mapId3, "메리네 카페 3호점"));
카페_등록(new CafeRegisterRequest(mapId1, "메리네 카페 본점", "서울시 강남구"));
카페_등록(new CafeRegisterRequest(mapId2, "메리네 카페 2호점", "서울시 강남구"));
카페_등록(new CafeRegisterRequest(mapId3, "메리네 카페 3호점", "서울시 강남구"));
MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
String token = 로그인_토큰_발급(signUpRequest.getEmail(), signUpRequest.getPassword());
Expand All @@ -270,7 +270,7 @@ void getCafesFilterFavorites() {
@DisplayName("특정 카페 이미지들을 조회한다")
void getCafeImages() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페 본점"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페 본점", "서울시 강남구"));
MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
String token = 로그인_토큰_발급(signUpRequest.getEmail(), signUpRequest.getPassword());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CommentAcceptanceTest extends AcceptanceTest {
void saveComment() {
String expected = "공부하기 좋아요~🥰";
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "100"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand All @@ -51,7 +51,7 @@ void saveComment() {
@DisplayName("카페 코멘트 목록을 조회한다")
void findComments() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "100"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand All @@ -71,7 +71,7 @@ void findComments() {
@DisplayName("카페 코멘트 첫번째 목록을 조회한다")
void findCommentsFirstPage() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "베어네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "베어네 카페", "100"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "베어");
회원_가입(signUpRequest);
Expand All @@ -94,7 +94,7 @@ void findCommentsFirstPage() {
@DisplayName("카페 코멘트 첫번째 목록을 제외한 페이지를 조회한다")
void findCommentsNotFirstPage() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "베어네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "베어네 카페", "100"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "베어");
회원_가입(signUpRequest);
Expand All @@ -117,7 +117,7 @@ void findCommentsNotFirstPage() {
@DisplayName("카페 코멘트 목록 중 내가 작성한 코멘트만을 조회한다")
void findOnlyMyComments() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "100"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand Down Expand Up @@ -145,7 +145,7 @@ void findOnlyMyComments() {
void updateComment() {
String content = "공부하기 좋아요~🥰";
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "100"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand Down Expand Up @@ -179,7 +179,7 @@ void updateComment() {
void deleteComment() {
String content = "공부하기 좋아요~🥰";
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "100"));

MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CommentLikeAcceptanceTest extends AcceptanceTest{
void saveCommentLike() {
String mapId = "12332312";
String comment = "코딩하고 싶어지는 카페에요.";
카페_등록(new CafeRegisterRequest(mapId, "정우네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "정우네 카페", "서울시 강남구"));

MemberSignUpRequest signUpRequest1 = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "베어");
회원_가입(signUpRequest1);
Expand All @@ -43,7 +43,7 @@ void saveCommentLike() {
void deleteCommentLike() {
String mapId = "12332312";
String comment = "코딩하고 싶어지는 카페에요.";
카페_등록(new CafeRegisterRequest(mapId, "정우네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "정우네 카페", "서울시 강남구"));

MemberSignUpRequest signUpRequest1 = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "베어");
회원_가입(signUpRequest1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FavoriteAcceptanceTest extends AcceptanceTest {
@DisplayName("회원이 카페 즐겨찾기 등록을 진행한다")
void saveFavoriteCafe() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));
MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
String token = 로그인_토큰_발급(signUpRequest.getEmail(), signUpRequest.getPassword());
Expand All @@ -34,7 +34,7 @@ void saveFavoriteCafe() {
@DisplayName("회원이 카페 즐겨찾기 삭제를 진행한다")
void deleteFavoriteCafe() {
String mapId = "12332312";
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페"));
카페_등록(new CafeRegisterRequest(mapId, "메리네 카페", "서울시 강남구"));
MemberSignUpRequest signUpRequest = new MemberSignUpRequest("[email protected]", "a1b2c3d4", "케이");
회원_가입(signUpRequest);
String token = 로그인_토큰_발급(signUpRequest.getEmail(), signUpRequest.getPassword());
Expand Down
Loading

0 comments on commit cfbc66b

Please sign in to comment.