Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -54,6 +54,10 @@ List<Feed> findFeeds(
// 커서 기반 페이징 조회
List<Feed> findByUserIdAndFeedIdBefore(Long userId, Long cursorFeedId, Pageable pageable);

// 시리즈 필터링 추가된 페이징 조회
List<Feed> findByUser_IdAndSeries_SeriesId(Long userId, Long seriesId, Pageable pageable);
List<Feed> findByUser_IdAndSeries_SeriesIdAndFeedIdBefore(Long userId, Long seriesId, Long cursorFeedId, Pageable pageable);

@Modifying
@Query("DELETE FROM Feed f WHERE f.user.id = :userId")
void deleteByUserId(@Param("userId") Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
public interface FeedQueryService {
FeedResponseDto.FeedPreviewList getPreViewFeeds(String category, String sort, Long cursor, int limit);
FeedResponseDto.AuthorizedFeedDto getFeed(Long feedId);
UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize);
UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize, Long seriesId);
// FeedResponseDto.FeedPreviewList searchByUserIdByKeyword(Long userId, Long nextCursor, int pageSize);
UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize);
UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize, Long seriesId);
Map<Long, String> getMySeries();
Long getLikeCount(Long feedId);
Feed getFeedByFeedId(Long feedId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public FeedResponseDto.AuthorizedFeedDto getFeed(Long feedId) {
}

@Transactional
public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize) {
public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize, Long seriesId) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
boolean isAuthenticated = authentication != null
&& !(authentication instanceof AnonymousAuthenticationToken)
Expand All @@ -202,9 +202,19 @@ public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int
: List.of();

Pageable pageable = PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "feedId"));
List<Feed> feeds = (nextCursor == null)
? feedRepository.findByUser_Id(userId, pageable)
: feedRepository.findByUserIdAndFeedIdBefore(userId, nextCursor, pageable);
// List<Feed> feeds = (nextCursor == null)
// ? feedRepository.findByUser_Id(userId, pageable)
// : feedRepository.findByUserIdAndFeedIdBefore(userId, nextCursor, pageable);
List<Feed> feeds;
if (seriesId == 0) {
feeds = (nextCursor == null)
? feedRepository.findByUser_Id(userId, pageable)
: feedRepository.findByUserIdAndFeedIdBefore(userId, nextCursor, pageable);
} else {
feeds = (nextCursor == null)
? feedRepository.findByUser_IdAndSeries_SeriesId(userId, seriesId, pageable)
: feedRepository.findByUser_IdAndSeries_SeriesIdAndFeedIdBefore(userId, seriesId, nextCursor, pageable);
}

List<FeedResponseDto.FeedDto> feedDtos = feeds.stream()
.map(feed -> {
Expand Down Expand Up @@ -233,13 +243,20 @@ public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int
}

@Override
public UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize) {
public UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize, Long seriesId) {
User user = authService.getCurrentUser();

Pageable pageable = PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "feedId"));
List<Feed> feeds = (nextCursor == null)
? feedRepository.findByUser_Id(user.getId(), pageable)
: feedRepository.findByUserIdAndFeedIdBefore(user.getId(), nextCursor, pageable);
List<Feed> feeds;
if (seriesId == 0) {
feeds = (nextCursor == null)
? feedRepository.findByUser_Id(user.getId(), pageable)
: feedRepository.findByUserIdAndFeedIdBefore(user.getId(), nextCursor, pageable);
} else {
feeds = (nextCursor == null)
? feedRepository.findByUser_IdAndSeries_SeriesId(user.getId(), seriesId, pageable)
: feedRepository.findByUser_IdAndSeries_SeriesIdAndFeedIdBefore(user.getId(), seriesId, nextCursor, pageable);
}

List<Long> likedFeedIds = feedLikeRepository.findFeedIdsByUserId(user.getId());
List<Long> savedFeedIds = feedSaveRepository.findFeedIdsByUserId(user.getId());
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/stackpot/stackpot/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import stackpot.stackpot.apiPayload.code.status.ErrorStatus;
import stackpot.stackpot.common.swagger.ApiErrorCodeExamples;
import stackpot.stackpot.feed.service.FeedQueryService;
import stackpot.stackpot.pot.dto.CompletedPotRequestDto;
import stackpot.stackpot.pot.dto.PotResponseDto;
import stackpot.stackpot.pot.dto.*;
import stackpot.stackpot.pot.service.pot.MyPotService;
import stackpot.stackpot.pot.service.pot.PotCommandService;
import stackpot.stackpot.pot.dto.*;
import stackpot.stackpot.user.dto.request.MyDescriptionRequestDto;
import stackpot.stackpot.user.dto.request.TokenRequestDto;
import stackpot.stackpot.user.dto.request.UserRequestDto;
Expand Down Expand Up @@ -179,7 +177,7 @@ public ResponseEntity<ApiResponse<UserResponseDto.loginDto>> googleCallback(@Req
@PatchMapping("/profile")
@Operation(
summary = "회원가입 API",
description = "신규 User 회원가입 시 필요한 정보를 저장합니다.\n"+
description = "신규 User 회원가입 시 필요한 정보를 저장합니다.\n" +
"- interests: 다중 선택 가능하며 string입니다. [사이드 프로젝트, 1인 개발, 공모전, 창업, 네트워킹 행사]\n"
)
public ResponseEntity<ApiResponse<UserSignUpResponseDto>> signup(@Valid @RequestBody UserRequestDto.JoinDto request) {
Expand Down Expand Up @@ -253,7 +251,7 @@ public ResponseEntity<ApiResponse<String>> deleteUser(@RequestHeader("Authorizat
ErrorStatus.USER_NOT_FOUND
})
public ResponseEntity<ApiResponse<UserResponseDto.UserInfoDto>> usersPages(
@PathVariable(name = "userId") Long userId){
@PathVariable(name = "userId") Long userId) {
UserResponseDto.UserInfoDto userDetails = userCommandService.getUsers(userId);
return ResponseEntity.ok(ApiResponse.onSuccess(userDetails));
}
Expand All @@ -267,15 +265,15 @@ public ResponseEntity<ApiResponse<UserResponseDto.UserInfoDto>> usersPages(
ErrorStatus.USER_NOT_FOUND,
ErrorStatus.USER_ALREADY_WITHDRAWN,
})
public ResponseEntity<ApiResponse<UserResponseDto.UserInfoDto>> usersMyPages(){
public ResponseEntity<ApiResponse<UserResponseDto.UserInfoDto>> usersMyPages() {
UserResponseDto.UserInfoDto userDetails = userCommandService.getMyUsers();
return ResponseEntity.ok(ApiResponse.onSuccess(userDetails));
}

@PatchMapping("/profile/update")
@Operation(
summary = "나의 프로필 수정 API",
description = "사용자의 역할, 관심사, 한 줄 소개, 카카오 아이디를 수정합니다.\n"+
description = "사용자의 역할, 관심사, 한 줄 소개, 카카오 아이디를 수정합니다.\n" +
"- interests: 다중 선택 가능하며 string입니다. [사이드 프로젝트, 1인 개발, 공모전, 창업, 네트워킹 행사]\n"
)
@ApiErrorCodeExamples({
Expand Down Expand Up @@ -358,6 +356,7 @@ public ResponseEntity<ApiResponse<MyDescriptionResponseDto>> getMyDescription()
MyDescriptionResponseDto responseDto = userQueryService.getMyDescription();
return ResponseEntity.ok(ApiResponse.onSuccess(responseDto));
}

@GetMapping("/description/{userId}")
@Operation(
summary = "특정 사용자의 소개 조회 API",
Expand Down Expand Up @@ -401,7 +400,6 @@ public ResponseEntity<ApiResponse<Void>> deleteMyDescription() {
}



@GetMapping("/{userId}/feeds")
@Operation(
summary = "사용자별 피드 조회 API",
Expand All @@ -419,9 +417,11 @@ public ResponseEntity<ApiResponse<UserMyPageResponseDto>> getFeedsByUserId(
@RequestParam(value = "cursor", required = false) Long cursor,

@Parameter(description = "페이지 크기", example = "10")
@RequestParam(value = "size", defaultValue = "10") int size
@RequestParam(value = "size", defaultValue = "10") int size,

@RequestParam(value = "seriesId", required = false, defaultValue = "0") Long seriesId
) {
UserMyPageResponseDto mypage = feedQueryService.getFeedsByUserId(userId, cursor, size);
UserMyPageResponseDto mypage = feedQueryService.getFeedsByUserId(userId, cursor, size, seriesId);
return ResponseEntity.ok(ApiResponse.onSuccess(mypage));
}

Expand All @@ -436,9 +436,10 @@ public ResponseEntity<ApiResponse<UserMyPageResponseDto>> getFeedsByUserId(
})
public ResponseEntity<ApiResponse<UserMyPageResponseDto>> getFeeds(
@RequestParam(name = "cursor", required = false) Long cursor,
@RequestParam(name = "size", defaultValue = "10") int size
@RequestParam(name = "size", defaultValue = "10") int size,
@RequestParam(value = "seriesId", required = false, defaultValue = "0") Long seriesId
) {
UserMyPageResponseDto mypage = feedQueryService.getFeeds(cursor, size);
UserMyPageResponseDto mypage = feedQueryService.getFeeds(cursor, size, seriesId);
return ResponseEntity.ok(ApiResponse.onSuccess(mypage));
}

Expand Down