-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from ShwimPing/feat/lhj/mypage
[FEAT] 마이페이지 기능 구현
- Loading branch information
Showing
17 changed files
with
380 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/shwimping/be/bookmark/dto/response/BookMarkPlaceResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.shwimping.be.bookmark.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.shwimping.be.place.domain.type.Category; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalTime; | ||
|
||
@Builder | ||
public record BookMarkPlaceResponse( | ||
Long bookMarkId, | ||
Long placeId, | ||
String name, | ||
String address, | ||
Category category, | ||
@JsonFormat(pattern = "HH:mm") | ||
LocalTime openTime, | ||
@JsonFormat(pattern = "HH:mm") | ||
LocalTime closeTime, | ||
Double rating, | ||
Long reviewCount | ||
) { | ||
@JsonProperty("rating") | ||
public Double getFormattedRating() { | ||
return Math.round(rating * 10) / 10.0; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/shwimping/be/bookmark/dto/response/BookMarkPlaceResponseList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.shwimping.be.bookmark.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record BookMarkPlaceResponseList( | ||
Boolean hasNext, | ||
List<BookMarkPlaceResponse> bookMarkList | ||
) { | ||
public static BookMarkPlaceResponseList of(Boolean hasNext, List<BookMarkPlaceResponse> bookMarkPlaceResponseList) { | ||
return new BookMarkPlaceResponseList(hasNext, bookMarkPlaceResponseList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/shwimping/be/bookmark/repository/BookMarkRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.shwimping.be.bookmark.repository; | ||
|
||
import com.shwimping.be.bookmark.dto.response.BookMarkPlaceResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface BookMarkRepositoryCustom { | ||
|
||
List<BookMarkPlaceResponse> getBookMarkList(Long userId, Long lastBookMarkId, Long size); | ||
|
||
Boolean hasNext(Long userId, Long lastBookMarkId, Long size); | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/shwimping/be/bookmark/repository/BookMarkRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.shwimping.be.bookmark.repository; | ||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.shwimping.be.bookmark.dto.response.BookMarkPlaceResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static com.shwimping.be.bookmark.domain.QBookMark.bookMark; | ||
import static com.shwimping.be.place.domain.QPlace.place; | ||
import static com.shwimping.be.review.domain.QReview.review; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class BookMarkRepositoryImpl implements BookMarkRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<BookMarkPlaceResponse> getBookMarkList(Long userId, Long lastBookMarkId, Long size) { | ||
return queryFactory.select( | ||
Projections.constructor(BookMarkPlaceResponse.class, | ||
bookMark.id, // bookmarkId | ||
place.id, // placeId | ||
place.name, // name | ||
place.address, // address | ||
place.category, // category | ||
place.openTime, // openTime | ||
place.closeTime, // closeTime | ||
review.rating.avg().coalesce(0.0), // averageRating | ||
review.id.count().coalesce(0L) // reviewCount | ||
) | ||
) | ||
.from(bookMark) // 북마크 테이블에서 시작 | ||
.join(bookMark.place, place) // 북마크와 장소 조인 | ||
.leftJoin(place.reviewList, review) // 장소와 리뷰를 왼쪽 조인 | ||
.where(bookMark.user.id.eq(userId), // 사용자 ID 필터 | ||
bookMark.id.lt(lastBookMarkId)) // 마지막 북마크 ID 필터 | ||
.groupBy(bookMark.id) // 그룹화 추가 | ||
.orderBy(bookMark.id.desc()) // 내림차순 정렬 | ||
.limit(size) // 제한 | ||
.fetch(); | ||
} | ||
|
||
|
||
|
||
@Override | ||
public Boolean hasNext(Long userId, Long lastBookMarkId, Long size) { | ||
return queryFactory.selectOne() | ||
.from(bookMark) | ||
.where(bookMark.user.id.eq(userId), bookMark.id.lt(lastBookMarkId - size)) | ||
.fetchFirst() != null; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/com/shwimping/be/place/application/PlaceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.