Skip to content

Commit

Permalink
Merge pull request #691 from Kernel360/635-place-in-course
Browse files Browse the repository at this point in the history
좋아요 한 장소 목록을 페이지에서 슬라이스로 변경
  • Loading branch information
Uknow928 committed Mar 28, 2024
2 parents b5e15ec + f0ab70a commit aad3bc2
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public interface CourseRepository extends JpaRepository<Course, Long> {
Slice<Course> findByPlaceNameContaining(@Param("keyword") String keyword, Pageable pageable);

@Query("SELECT c FROM Course c inner JOIN Favor f ON c.id = f.travel.id WHERE c.isDeleted = false AND f.member.id = :memberId")
Page<Course> findAllMembersFavoriteCourses(Long memberId, Pageable pageRequest);
Slice<Course> findAllMembersFavoriteCourses(Long memberId, Pageable pageRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ public interface SpotRepository extends JpaRepository<Spot, Long> {
List<Long> findPlaceIdByMemberId(Long memberId);

@Query("SELECT s FROM Spot s INNER JOIN Favor f ON s.id = f.travel.id WHERE s.isDeleted = false AND f.member.id = :memberId")
Page<Spot> findAllMembersFavoriteSpot(Long memberId, Pageable pageRequest);
Slice<Spot> findAllMembersFavoriteSpot(Long memberId, Pageable pageRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ public PointInfo(Point point) {
@Data
public static class MyFavoriteCoursesInfo {
private final List<FavoriteCourseInfo> contents;
private final int totalPages;
private final boolean hasNext;

public MyFavoriteCoursesInfo(List<FavoriteCourseInfo> contents, boolean hasNext) {
this.contents = contents;
this.hasNext = hasNext;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public interface CourseReader {

Slice<Course> searchCourseByPlaceName(String keyword, Pageable pageable);

Page<Course> getFavoriteCourses(Long memberId, Pageable pageRequest);
Slice<Course> getFavoriteCourses(Long memberId, Pageable pageRequest);
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -128,14 +129,14 @@ public CourseInfo.Slice searchCourseByPlaceName(String keyword, Accessor accesso

@Override
public CourseInfo.MyFavoriteCoursesInfo getFavoriteCoursesInfo(Long memberId, PageRequest pageRequest) {
Page<Course> favoriteCourses = courseReader.getFavoriteCourses(memberId, pageRequest);
Slice<Course> favoriteCourses = courseReader.getFavoriteCourses(memberId, pageRequest);
List<CourseInfo.FavoriteCourseInfo> favoriteCourseInfoList = favoriteCourses.getContent().stream()
.map(course -> {
boolean isFollowing = followReader.isFollowing(memberId, course.getMember().getId());
return new CourseInfo.FavoriteCourseInfo(course, isFollowing);
}
)
.toList();
return new CourseInfo.MyFavoriteCoursesInfo(favoriteCourseInfoList, favoriteCourses.getTotalPages());
return new CourseInfo.MyFavoriteCoursesInfo(favoriteCourseInfoList, favoriteCourses.hasNext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ public Slice(List<Main> mains, boolean hasNext) {
@Getter
public static class MyFavoriteSpotsInfo{
private final List<FavoriteSpotInfo> contents;
private final int totalPages;
private final boolean hasNext;

public MyFavoriteSpotsInfo(List<FavoriteSpotInfo> favoriteSpots, int totalPages){
public MyFavoriteSpotsInfo(List<FavoriteSpotInfo> favoriteSpots, boolean hasNext){
this.contents = favoriteSpots;
this.totalPages = totalPages;
this.hasNext = hasNext;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public interface SpotReader {

List<Long> getMySpotPlaceIds(Long memberId);

Page<Spot> getFavoriteSpotList(Long memberId, Pageable pageRequest);
Slice<Spot> getFavoriteSpotList(Long memberId, Pageable pageRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ public void registerSpot(RegisterSpotRequest command, Long memberId) {
}

var attachFiles = spotSeriesFactory.initAttachFiles(command);
Place place = optionalPlace.orElseGet(() -> registerNewPlace(command.getRegisterPlaceRequest(), attachFiles.getFiles().getFirst()));

Place place = optionalPlace.orElseGet(() -> {
AttachFile placeAttachFile = new AttachFile(
attachFiles.getRepresentativeFile().getFileType(),
attachFiles.getRepresentativeFile().getFileUrl(),
attachFiles.getRepresentativeFile().getOriginalFileName(),
attachFiles.getRepresentativeFile().getFileSize()
);
return registerNewPlace(command.getRegisterPlaceRequest(), placeAttachFile);
});
placeCacheStore.incrementSpotCountInPlace(place.getId());
placeCacheStore.incrementSpotTotalRateInPlace(place.getId(), command.getRate());
spotStore.store(command.toEntity(member, place, false, attachFiles));
Expand Down Expand Up @@ -146,15 +155,15 @@ public CourseInfo.MySpotsInfo getMySpotsDetailInfo(List<Long> spotIds, Long memb
@Override
@Transactional(readOnly = true)
public SpotInfo.MyFavoriteSpotsInfo getFavoriteSpotsInfo(Long memberId, Pageable pageRequest) {
var pageSpot = spotReader.getFavoriteSpotList(memberId, pageRequest);
List<SpotInfo.FavoriteSpotInfo> spotInfoList = pageSpot.getContent().stream()
var sliceSpot = spotReader.getFavoriteSpotList(memberId, pageRequest);
List<SpotInfo.FavoriteSpotInfo> spotInfoList = sliceSpot.getContent().stream()
.map(spot -> {
boolean isFollowing = followReader.isFollowing(memberId, spot.getMember().getId());
return new SpotInfo.FavoriteSpotInfo(spot, isFollowing);
}

)
.toList();
return new SpotInfo.MyFavoriteSpotsInfo(spotInfoList, pageSpot.getTotalPages());
return new SpotInfo.MyFavoriteSpotsInfo(spotInfoList, sliceSpot.hasNext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Slice<Course> searchCourseByPlaceName(final String keyword, final Pageabl
}

@Override
public Page<Course> getFavoriteCourses(Long memberId, Pageable pageRequest) {
public Slice<Course> getFavoriteCourses(Long memberId, Pageable pageRequest) {
return courseRepository.findAllMembersFavoriteCourses(memberId, pageRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public List<Spot> store(RegisterCourseRequest request, Long memberId) {
.map(fileUploader::upload)
.collect(Collectors.toList()));

Place place = optionalPlace.orElseGet(() -> registerNewPlace(registerPlaceRequest, attachFiles.getFiles().getFirst()));
Place place = optionalPlace.orElseGet(() -> {
AttachFile placeAttachFile = new AttachFile(
attachFiles.getRepresentativeFile().getFileType(),
attachFiles.getRepresentativeFile().getFileUrl(),
attachFiles.getRepresentativeFile().getOriginalFileName(),
attachFiles.getRepresentativeFile().getFileSize()
);
return registerNewPlace(registerPlaceRequest, placeAttachFile);
});

placeCacheStore.incrementSpotCountInPlace(place.getId());
placeCacheStore.incrementSpotTotalRateInPlace(place.getId(), registerSpotRequest.getRate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public List<Long> getMySpotPlaceIds(Long memberId) {
}

@Override
public Page<Spot> getFavoriteSpotList(Long memberId, Pageable pageRequest) {
public Slice<Spot> getFavoriteSpotList(Long memberId, Pageable pageRequest) {
return spotRepository.findAllMembersFavoriteSpot(memberId, pageRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Data
public class MyFavoriteCoursesResponse {
List<FavoriteCourseDto> contents;
int totalPages;
boolean hasNext;

@Data
public static class FavoriteCourseDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Builder
public class MyFavoriteSpotsResponse{
private List<FavoriteSpotDto> contents;
private int totalPages;
private boolean hasNext;

@Getter
@Builder
Expand Down
32 changes: 16 additions & 16 deletions backend/yigil-api/src/main/resources/static/docs/course-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ <h5 id="_http_response_예시">HTTP Response 예시</h5>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 371
Content-Length: 370

{
"courses" : [ {
Expand All @@ -619,7 +619,7 @@ <h5 id="_http_response_예시">HTTP Response 예시</h5>
"map_static_image_url" : "test",
"rate" : 4.5,
"spot_count" : 10,
"create_date" : "2024-03-28T11:51:18.315179",
"create_date" : "2024-03-28T16:34:51.54599",
"owner_id" : 1,
"owner_profile_image_url" : "test",
"owner_nickname" : "test",
Expand Down Expand Up @@ -1103,7 +1103,7 @@ <h5 id="_http_response_예시_4">HTTP Response 예시</h5>
"rate" : 4.5,
"map_static_image_url" : "images/static.png",
"description" : "본문",
"created_date" : "2024-03-28T11:51:18.370614",
"created_date" : "2024-03-28T16:34:51.603072",
"line_string_json" : "lineStringJson",
"spots" : [ {
"id" : 1,
Expand Down Expand Up @@ -1698,7 +1698,7 @@ <h5 id="_http_response_예시_8">HTTP Response 예시</h5>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 323
Content-Length: 324

{
"courses" : [ {
Expand All @@ -1710,7 +1710,7 @@ <h5 id="_http_response_예시_8">HTTP Response 예시</h5>
"spot_count" : 3,
"rate" : 4.5,
"liked" : false,
"create_date" : "2024-03-28T11:51:18.25796"
"create_date" : "2024-03-28T16:34:51.487737"
} ],
"has_next" : false
}</code></pre>
Expand Down Expand Up @@ -1858,7 +1858,7 @@ <h5 id="_response_body">Response Body</h5>
"rate" : 4.5,
"description" : "스팟 본문",
"image_urls" : [ "images/spot.jpg", "images/spotted.png" ],
"create_date" : "2024-03-28T11:51:18.28317",
"create_date" : "2024-03-28T16:34:51.514692",
"point" : {
"x" : 1.0,
"y" : 1.0
Expand All @@ -1870,7 +1870,7 @@ <h5 id="_response_body">Response Body</h5>
"rate" : 4.5,
"description" : "스팟 본문",
"image_urls" : [ "images/spot.jpg", "images/spotted.png" ],
"create_date" : "2024-03-28T11:51:18.283472",
"create_date" : "2024-03-28T16:34:51.514976",
"point" : {
"x" : 2.0,
"y" : 2.0
Expand All @@ -1886,7 +1886,7 @@ <h5 id="_http_response_예시_9">HTTP Response 예시</h5>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 664
Content-Length: 665

{
"spot_details" : [ {
Expand All @@ -1896,7 +1896,7 @@ <h5 id="_http_response_예시_9">HTTP Response 예시</h5>
"rate" : 4.5,
"description" : "스팟 본문",
"image_urls" : [ "images/spot.jpg", "images/spotted.png" ],
"create_date" : "2024-03-28T11:51:18.28317",
"create_date" : "2024-03-28T16:34:51.514692",
"point" : {
"x" : 1.0,
"y" : 1.0
Expand All @@ -1908,7 +1908,7 @@ <h5 id="_http_response_예시_9">HTTP Response 예시</h5>
"rate" : 4.5,
"description" : "스팟 본문",
"image_urls" : [ "images/spot.jpg", "images/spotted.png" ],
"create_date" : "2024-03-28T11:51:18.283472",
"create_date" : "2024-03-28T16:34:51.514976",
"point" : {
"x" : 2.0,
"y" : 2.0
Expand Down Expand Up @@ -2037,9 +2037,9 @@ <h4 id="_response_10">Response</h4>
<td class="tableblock halign-left valign-top"><p class="tableblock">팔로잉 여부</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>total_pages</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Number</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">총 페이지 수</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>has_next</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Boolean</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">다음 페이지가 있는지 여부</p></td>
</tr>
</tbody>
</table>
Expand All @@ -2049,22 +2049,22 @@ <h5 id="_http_response_예시_10">HTTP Response 예시</h5>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 366
Content-Length: 367

{
"contents" : [ {
"course_id" : 1,
"title" : "test",
"rate" : 4.5,
"spot_count" : 10,
"created_date" : "2024-03-28T11:51:18.294820",
"created_date" : "2024-03-28T16:34:51.526412",
"map_static_image_url" : "images/map.jpg",
"writer_id" : 1,
"writer_nickname" : "nickname",
"writer_profile_image_url" : "images/profile.jpg",
"following" : true
} ],
"total_pages" : 1
"has_next" : false
}</code></pre>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ <h5 id="_path_parameter_4">Path parameter</h5>
<h5 id="_http_request_예시_4">HTTP Request 예시</h5>
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">GET /api/v1/follows/followers?page=1&amp;size=5&amp;sortBy=follower_name&amp;sortOrder=asc HTTP/1.1
<pre class="highlight nowrap"><code class="language-http" data-lang="http">GET /api/v1/follows/followers?page=1&amp;size=5&amp;sortBy=nickname&amp;sortOrder=asc HTTP/1.1
Host: spring.restdocs.test</code></pre>
</div>
</div>
Expand Down
Loading

0 comments on commit aad3bc2

Please sign in to comment.