Skip to content

Commit 958a5a4

Browse files
authored
Merge pull request #406 from Team-0ops/develop
메인 피드 및 상세 피드 API 수정
2 parents de7603b + 5da2696 commit 958a5a4

14 files changed

Lines changed: 551 additions & 277 deletions

‎src/main/java/Oops/backend/domain/post/controller/HomeFeedController.java‎

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import Oops.backend.domain.auth.AuthenticationContext;
77
import Oops.backend.domain.post.dto.PostResponse;
88
import Oops.backend.domain.post.service.HomeFeedService;
9+
import Oops.backend.domain.randomTopic.Service.RandomTopicService;
10+
import Oops.backend.domain.randomTopic.dto.RandomTopicResponse;
911
import Oops.backend.domain.user.entity.User;
1012
import io.swagger.v3.oas.annotations.Operation;
1113
import io.swagger.v3.oas.annotations.Parameter;
@@ -23,48 +25,61 @@
2325

2426
import java.util.List;
2527

26-
@Tag(name = "메인 화면 관련 API")
28+
@Tag(name = "메인페이지 관련 API")
2729
@Slf4j
2830
@RestController
2931
@RequiredArgsConstructor
3032
@RequestMapping("/api/feeds")
3133
public class HomeFeedController {
3234
private final HomeFeedService feedService;
35+
private final RandomTopicService randomTopicService;
3336

3437
/**
35-
* 홈화면 첫 로딩 - 로그인 O
38+
* 상단 배너 정보 조회
3639
*/
37-
@GetMapping("/home/first-auth")
38-
@Operation(summary = "로그인한 경우 홈화면 첫 로딩 API",description = "홈화면 처음 로딩 시 필요한 베스트 실패담 5개와 즐겨찾기한 실패담 10개만 우선 조회합니다.")
39-
public ResponseEntity<BaseResponse> getFirstPostList(@Parameter(hidden = true) @AuthenticatedUser User user) {
40+
@GetMapping("/home/banners")
41+
@Operation(summary = "홈화면 배너 API",description = "홈화면의 배너에 필요한 정보를 조회하는 api입니다. ")
42+
public ResponseEntity<BaseResponse> getBannarInfo (@Parameter(hidden = true) @AuthenticatedUser User user) {
4043

41-
log.info("Get /api/feeds/home/first 호출, User = {}", user.getUserName());
44+
RandomTopicResponse.BannarsInfoDto result = randomTopicService.getBannarInfo(user);
4245

43-
List<PostResponse.PostPreviewListDto> result = feedService.getFirstPostList(user);
4446
return BaseResponse.onSuccess(SuccessStatus._OK, result);
4547
}
4648

4749
/**
48-
* 홈화면 첫 로딩 - 로그인 X
50+
* 베스트 실패담 5개 조회
4951
*/
50-
@GetMapping("/home/first-guest")
51-
@Operation(summary = "로그인하지 않은 경우 홈화면 첫 로딩 API",description = "홈화면 처음 로딩 시 필요한 베스트 실패담 5개를 조회합니다. 즐찾 리스트는 null ")
52-
public ResponseEntity<BaseResponse> getFirstPostList() {
52+
@GetMapping("/home/best")
53+
@Operation(summary = "홈화면 베스트 실패담 조회 API",description = "베스트 실패담 5개를 조회합니다.")
54+
public ResponseEntity<BaseResponse> getBestPostList(@Parameter(hidden = true) @AuthenticatedUser User user) {
55+
56+
PostResponse.PostPreviewListDto result = feedService.getBestPostList(user);
5357

54-
List<PostResponse.PostPreviewListDto> result = feedService.getFirstPostListForGuest();
5558
return BaseResponse.onSuccess(SuccessStatus._OK, result);
5659
}
5760

5861
/**
59-
* 홈 화면 이후 로딩
62+
* 즐겨찾기한 카테고리 중 하나의 실패담 5개 조회
6063
*/
61-
@GetMapping("/home/later")
62-
@Operation(summary = "홈화면 이후 로딩 API",description ="카테고리별 최신글 하나씩 조회합니다.")
63-
public ResponseEntity<BaseResponse> getLaterPostList() {
64+
@GetMapping("/home/bookmarked")
65+
@Operation(summary = "홈화면 특정 즐겨찾기 카테고리의 실패담 조회 API",description = "즐겨찾기한 카테고리 중 사용자가 선택한 카테고리의 실패담 5개를 조회합니다.")
66+
public ResponseEntity<BaseResponse> getBookmarkedPostList(@Parameter(hidden = true) @AuthenticatedUser User user,
67+
@Parameter(description = "카테고리 아이디: 0이면 전체 카테고리 조회입니다.")
68+
@RequestParam Long categoryId) {
69+
70+
PostResponse.PostPreviewListDto result = feedService.getBookmarkedPostList(user, categoryId);
6471

65-
log.info("Get /api/feeds/home/later");
72+
return BaseResponse.onSuccess(SuccessStatus._OK, result);
73+
}
74+
75+
/**
76+
* 카테고리별 최신글 1개씩 조회
77+
*/
78+
@GetMapping("/home/categories")
79+
@Operation(summary = "카테고리별 최신글 1개씩 조회 API",description ="카테고리별 최신글 하나씩 조회합니다.")
80+
public ResponseEntity<BaseResponse> getCategoriesPostList() {
6681

67-
PostResponse.PostPreviewListDto result = feedService.getLaterPostList();
82+
PostResponse.PostPreviewListDto result = feedService.getCategoriesPostList();
6883
return BaseResponse.onSuccess(SuccessStatus._OK, result);
6984
}
7085

@@ -84,4 +99,4 @@ public ResponseEntity<BaseResponse> getAllPostsByKeyword(@RequestParam String ke
8499

85100
return BaseResponse.onSuccess(SuccessStatus._OK, result);
86101
}
87-
}
102+
}

‎src/main/java/Oops/backend/domain/post/controller/SpecFeedController.java‎

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Oops.backend.common.status.SuccessStatus;
77
import Oops.backend.domain.auth.AuthenticatedUser;
88
import Oops.backend.domain.post.dto.PostResponse;
9+
import Oops.backend.domain.post.entity.SortType;
910
import Oops.backend.domain.post.model.Situation;
1011
import Oops.backend.domain.post.service.SpecFeedService;
1112
import Oops.backend.domain.user.entity.User;
@@ -36,50 +37,52 @@ public class SpecFeedController {
3637
* 베스트 Failers 피드
3738
*/
3839
@GetMapping("/best/all")
39-
@Operation(summary = "베스트 Failers 피드 조회 API",description = "실패담을 베스트 지표에 따라 정렬하여 보여줍니다.")
40+
@Operation(summary = "베스트 Failers 피드 조회 API",description = "베스트 지표에 따라 선정된 베스트 실패담 50개를 정렬 기준에 따라 조회합니다.")
4041
public ResponseEntity<BaseResponse> getBestPostList(@Parameter(description = "페이지 번호 (0부터 시작)")
4142
@RequestParam(defaultValue = "0") int page,
4243
@Parameter(description = "페이지당 게시글 수")
43-
@RequestParam(defaultValue = "10") int limit) {
44-
45-
log.info("Get /api/feeds/best/all 호출");
46-
44+
@RequestParam(defaultValue = "10") int limit,
45+
@Parameter(description = "정렬 기준 (BEST, LATEST, LIKE, VIEW, COMMENT)")
46+
@RequestParam(defaultValue = "LATEST") SortType sort) {
4747
LocalDateTime cutoff = LocalDateTime.now();
4848
Pageable pageable = PageRequest.of(page, limit);
4949

50-
PostResponse.PostPreviewListDto result = specFeedService.getBestPostList(cutoff, pageable);
50+
PostResponse.PostPreviewListDto result = specFeedService.getBestPostList(cutoff, pageable, sort);
5151
return BaseResponse.onSuccess(SuccessStatus._OK, result);
5252
}
5353

5454
/**
5555
* 즐겨찾기한 카테고리 피드
5656
*/
57-
@GetMapping("/bookmarked/all")
58-
@Operation(summary = "즐겨찾기한 카테고리 피드 조회 API",description = "즐겨찾기한 카테고리의 글 중 요청 situation인 게시글을 최신순으로 조회합니다.")
59-
public ResponseEntity<BaseResponse> getMarkedPostList(@Parameter(
60-
description = "게시글 상태 (OOPS: 웁스중, OVERCOMING: 극복중, OVERCOME: 극복완료)"
61-
)
57+
@GetMapping("/bookmarked/{categoryId}/all")
58+
@Operation(summary = "즐겨찾기한 카테고리 피드 조회 API",description = "즐겨찾기한 카테고리 중 선택된 카테고리의 글 중 요청 situation인 게시글을 정렬 기준에 따라 조회합니다.")
59+
public ResponseEntity<BaseResponse> getMarkedPostList(@Parameter(description = "카테고리 아이디: 0이면 전체 카테고리 조회입니다.")
60+
@PathVariable Long categoryId,
61+
@Parameter(description = "게시글 상태 (OOPS: 웁스중, OVERCOMING: 극복중, OVERCOME: 극복완료)")
6262
@RequestParam("situation") Situation situation,
6363
@Parameter(description = "페이지 번호 (0부터 시작)")
6464
@RequestParam(defaultValue = "0") int page,
6565
@Parameter(description = "페이지당 게시글 수")
6666
@RequestParam(defaultValue = "10") int limit,
67-
@Parameter(hidden = true) @AuthenticatedUser User user) {
68-
69-
log.info("Get /api/feeds/bookmarked/all 호출");
67+
@Parameter(hidden = true) @AuthenticatedUser User user,
68+
@Parameter(description = "정렬 기준 (LATEST, LIKE, VIEW, COMMENT)")
69+
@RequestParam(defaultValue = "LATEST") SortType sort) {
70+
if(categoryId<0 || categoryId>15){
71+
throw new GeneralException(ErrorStatus.INVALID_CATEGORY_ID);
72+
}
7073

7174
LocalDateTime cutoff = LocalDateTime.now();
72-
Pageable pageable = PageRequest.of(page, limit, Sort.by(Sort.Direction.DESC, "createdAt"));
75+
Pageable pageable = PageRequest.of(page, limit);
7376

74-
PostResponse.PostPreviewListDto result = specFeedService.getMarkedPostList(situation, cutoff, pageable, user);
77+
PostResponse.PostPreviewListDto result = specFeedService.getMarkedPostList(situation, cutoff, pageable, user, sort, categoryId);
7578
return BaseResponse.onSuccess(SuccessStatus._OK, result);
7679
}
7780

7881
/**
7982
* 카테고리별 피드
8083
*/
8184
@GetMapping("/categories/{categoryId}/all")
82-
@Operation(summary = "카테고리별 피드 조회 API",description = "선택된 카테고리의 글 중 요청 situation인 게시글을 최신순으로 조회합니다.")
85+
@Operation(summary = "카테고리별 피드 조회 API",description = "선택된 카테고리의 글 중 요청 situation인 게시글을 정렬 기준에 따라 조회합니다.")
8386
public ResponseEntity<BaseResponse> getMarkedPostList(@PathVariable Long categoryId,
8487
@Parameter(
8588
description = "게시글 상태 (OOPS: 웁스중, OVERCOMING: 극복중, OVERCOME: 극복완료)"
@@ -88,17 +91,17 @@ public ResponseEntity<BaseResponse> getMarkedPostList(@PathVariable Long categor
8891
@Parameter(description = "페이지 번호 (0부터 시작)")
8992
@RequestParam(defaultValue = "0") int page,
9093
@Parameter(description = "페이지당 게시글 수")
91-
@RequestParam(defaultValue = "10") int limit) {
92-
93-
log.info("Get /api/feeds/categories/{categoryId}/all 호출");
94+
@RequestParam(defaultValue = "10") int limit,
95+
@Parameter(description = "정렬 기준 (LATEST, LIKE, VIEW, COMMENT)")
96+
@RequestParam(defaultValue = "LATEST") SortType sort) {
9497

9598
if(categoryId<1 || categoryId>15){
9699
throw new GeneralException(ErrorStatus.INVALID_CATEGORY_ID);
97100
}
98101
LocalDateTime cutoff = LocalDateTime.now();
99-
Pageable pageable = PageRequest.of(page, limit, Sort.by(Sort.Direction.DESC, "createdAt"));
102+
Pageable pageable = PageRequest.of(page, limit);
100103

101-
PostResponse.PostPreviewListDto result = specFeedService.getPostByCategoryList(situation, cutoff, pageable, categoryId);
104+
PostResponse.PostPreviewListDto result = specFeedService.getPostByCategoryList(situation, cutoff, pageable, categoryId, sort);
102105

103106
return BaseResponse.onSuccess(SuccessStatus._OK, result);
104107
}
@@ -107,19 +110,21 @@ public ResponseEntity<BaseResponse> getMarkedPostList(@PathVariable Long categor
107110
* 이번주 랜덤 주제 피드
108111
*/
109112
@GetMapping("/randomTopic/current/all")
110-
@Operation(summary = "이번주 랜덤주제 피드 API",description = "이번주 랜덤주제의 글 중 요청 situation인 게시글을 최신순으로 조회합니다.")
113+
@Operation(summary = "이번주 랜덤주제 피드 API",description = "이번주 랜덤주제의 글 중 요청 situation인 게시글을 정렬 기준에 따라 조회합니다.")
111114
public ResponseEntity<BaseResponse> getThisWeekPostList(@Parameter(
112115
description = "게시글 상태 (OOPS: 웁스중, OVERCOMING: 극복중, OVERCOME: 극복완료)"
113116
)
114117
@RequestParam("situation") Situation situation,
115118
@Parameter(description = "페이지 번호 (0부터 시작)")
116119
@RequestParam(defaultValue = "0") int page,
117120
@Parameter(description = "페이지당 게시글 수")
118-
@RequestParam(defaultValue = "10") int limit) {
121+
@RequestParam(defaultValue = "10") int limit,
122+
@Parameter(description = "정렬 기준 (LATEST, LIKE, VIEW, COMMENT)")
123+
@RequestParam(defaultValue = "LATEST") SortType sort) {
119124
LocalDateTime cutoff = LocalDateTime.now();
120-
Pageable pageable = PageRequest.of(page, limit, Sort.by(Sort.Direction.DESC, "createdAt"));
125+
Pageable pageable = PageRequest.of(page, limit);
121126

122-
PostResponse.PostPreviewListDto result = specFeedService.getThisWeekPostList(situation, cutoff, pageable);
127+
PostResponse.PostPreviewListDto result = specFeedService.getThisWeekPostList(situation, cutoff, pageable, sort);
123128

124129
return BaseResponse.onSuccess(SuccessStatus._OK, result);
125130
}
@@ -128,20 +133,22 @@ public ResponseEntity<BaseResponse> getThisWeekPostList(@Parameter(
128133
* 저번주 랜덤 주제 피드
129134
*/
130135
@GetMapping("/randomTopic/last/all")
131-
@Operation(summary = "저번주 랜덤주제 피드 API",description = "저번주 랜덤주제 top3 글과 요청 situation인 게시글을 최신순으로 조회합니다.")
136+
@Operation(summary = "저번주 랜덤주제 피드 API",description = "저번주 랜덤주제 top3 글과 요청 situation인 게시글을 정렬 기준에 따라 조회합니다.")
132137
public ResponseEntity<BaseResponse> getLastWeekPostList(@Parameter(
133138
description = "게시글 상태 (OOPS: 웁스중, OVERCOMING: 극복중, OVERCOME: 극복완료)"
134139
)
135140
@RequestParam("situation") Situation situation,
136141
@Parameter(description = "페이지 번호 (0부터 시작)")
137142
@RequestParam(defaultValue = "0") int page,
138143
@Parameter(description = "페이지당 게시글 수")
139-
@RequestParam(defaultValue = "10") int limit) {
144+
@RequestParam(defaultValue = "10") int limit,
145+
@Parameter(description = "정렬 기준 (LATEST, LIKE, VIEW, COMMENT)")
146+
@RequestParam(defaultValue = "LATEST") SortType sort) {
140147

141148
LocalDateTime cutoff = LocalDateTime.now();
142-
Pageable pageable = PageRequest.of(page, limit, Sort.by(Sort.Direction.DESC, "createdAt"));
149+
Pageable pageable = PageRequest.of(page, limit);
143150

144-
List<PostResponse.PostPreviewListDto> result = specFeedService.getLastWeekPostList(situation, cutoff, pageable);
151+
List<PostResponse.PostPreviewListDto> result = specFeedService.getLastWeekPostList(situation, cutoff, pageable, sort);
145152

146153
return BaseResponse.onSuccess(SuccessStatus._OK, result);
147154
}

‎src/main/java/Oops/backend/domain/post/dto/PostResponse.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import Oops.backend.domain.comment.dto.CommentResponse;
44
import Oops.backend.domain.comment.model.CommentType;
55
import Oops.backend.domain.post.entity.Post;
6-
import Oops.backend.config.s3.S3ImageService;
76
import lombok.AllArgsConstructor;
87
import lombok.Builder;
98
import lombok.Getter;
@@ -52,7 +51,7 @@ public static PostPreviewDto from(Post post, String CategoryOrTopicName, String
5251
@NoArgsConstructor
5352
@AllArgsConstructor
5453
public static class PostPreviewListDto {
55-
String name; // 베스트 or 즐겨찾기 or 카테고리
54+
String comment;
5655
List<PostPreviewDto> posts;
5756
boolean isLast;
5857
}

‎src/main/java/Oops/backend/domain/post/dto/PostSummaryDto.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static PostSummaryDto from(Post post) {
1717
return PostSummaryDto.builder()
1818
.postId(post.getId())
1919
.title(post.getTitle())
20-
.situation(post.getSituation().name()) // 그대로 Enum name 사용
20+
.situation(post.getSituation().name()) // 그대로 Enum comment 사용
2121
.build();
2222
}
2323
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package Oops.backend.domain.post.entity;
2+
3+
public enum SortType {
4+
BEST, // 인기순 -> 베스트 피드용
5+
LATEST, // 최신순
6+
LIKE, // 좋아요순
7+
VIEW, // 조회순
8+
COMMENT // 댓글 많은 순
9+
}

‎src/main/java/Oops/backend/domain/post/repository/HomeFeedRepository.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,22 @@ public interface HomeFeedRepository extends JpaRepository<Post, Long> {
2525
"ORDER BY (p.watching + 5 * p.likes + 10 * COUNT(c)) DESC")
2626
List<Post> findTopBestPostBefore(@Param("cutoff") LocalDateTime cutoff, Pageable pageable);
2727

28-
// 즐찾 카테고리 중 최신 실패담 10개 조회
28+
// 즐겨찾기한 카테고리들의 최신 실패담 5개 조회
2929
@Query("SELECT p FROM Post p WHERE p.category.id IN :categoryIds ORDER BY p.createdAt DESC")
3030
List<Post> findTop5ByCategoryIdsOrderByCreatedAtDesc(@Param("categoryIds") List<Long> categoryIds, Pageable pageable);
3131

32+
// 특정 카테고리 중 최신 실패담 5개 조회
33+
@Query("""
34+
SELECT p
35+
FROM Post p
36+
WHERE p.category.id = :categoryId
37+
ORDER BY p.createdAt DESC
38+
""")
39+
List<Post> findLatestByCategory(
40+
@Param("categoryId") Long categoryId,
41+
Pageable pageable
42+
);
43+
3244
// 각 카테고리별 최신글 1개씩 조회
3345
@Query(value = """
3446
SELECT p.* FROM post p

0 commit comments

Comments
 (0)