Skip to content

Commit

Permalink
Merge pull request #125 from Me1tingPot/feature/#124
Browse files Browse the repository at this point in the history
Feature: 마이페이지 파티 참여 내역 조회 구현
  • Loading branch information
JangYouJung authored Jul 6, 2024
2 parents 4232525 + 5aa71cc commit daa7ead
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import meltingpot.server.domain.entity.Account;
import meltingpot.server.domain.entity.party.Party;
import meltingpot.server.domain.entity.party.enums.PartyStatus;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

Expand All @@ -14,4 +18,7 @@ public interface PartyRepository extends JpaRepository<Party, Integer>, JpaSpeci
Party findByAccountAndPartyStatus(Account account, PartyStatus status);

int countByAccountAndPartyStatus(Account account, PartyStatus status);

@Query("SELECT DISTINCT p FROM Party p LEFT JOIN p.partyParticipants pp WHERE (p.account = :account OR pp.account = :account) AND p.deletedAt IS NULL ORDER BY p.createdAt DESC")
Slice<Party> findByAccountFromPartyAndPartyParticipant(@Param("account") Account account, Pageable pageable);
}
24 changes: 12 additions & 12 deletions src/main/java/meltingpot/server/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ public ResponseEntity<ResponseData<SliceResponse<PostResponseDto>>> readUsersCom
}
}

// // 프로필 상세 보기: 사용자가 참여한 파티 조회
// @GetMapping("/parties/{userId}")
// @Operation(summary="마이페이지 사용자가 참여한 파티 조회", description="마이페이지에서 사용자가 참여 혹은 주최한 파티를 불러옵니다.\n" )
// public ResponseEntity<ResponseData<SliceResponse<PartyResponse>>> readUsersParties(
// @PathVariable long userId, @RequestParam(value = "page", defaultValue = "0") Integer page
// ){
// try {
// return ResponseData.toResponseEntity(ResponseCode.READ_USERS_PARTIES_SUCCESS, userService.readUsersParties(userId, page));
// } catch (NoSuchElementException e) {
// return ResponseData.toResponseEntity(ResponseCode.READ_USERS_PARTIES_FAIL, null);
// }
// }
// 프로필 상세 보기: 사용자가 참여한 파티 조회
@GetMapping("/parties/{userId}")
@Operation(summary="마이페이지 사용자가 참여한 파티 조회", description="마이페이지에서 사용자가 참여 혹은 주최한 파티를 불러옵니다.\n" )
public ResponseEntity<ResponseData<SliceResponse<PartyResponse>>> readUsersParties(
@PathVariable long userId, @RequestParam(value = "page", defaultValue = "0") Integer page
){
try {
return ResponseData.toResponseEntity(ResponseCode.READ_USERS_PARTIES_SUCCESS, userService.readUsersParties(userId, page));
} catch (NoSuchElementException e) {
return ResponseData.toResponseEntity(ResponseCode.READ_USERS_PARTIES_FAIL, null);
}
}

}
14 changes: 9 additions & 5 deletions src/main/java/meltingpot/server/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import meltingpot.server.domain.entity.Account;
import meltingpot.server.domain.entity.AccountProfileImage;
import meltingpot.server.domain.entity.party.Party;
import meltingpot.server.util.Constants;
import meltingpot.server.domain.entity.comment.Comment;
import meltingpot.server.domain.entity.party.enums.ParticipantStatus;
Expand Down Expand Up @@ -143,7 +144,7 @@ public ResponseCode deleteProfileImage(Account account, long imageId) {
return ResponseCode.PROFILE_IMAGE_UPDATE_NOT_OWNER;
}

// 삭제하려는 사진이 대표 사진인 경우 다른 사진을 대표 사진으로 임시 설정
// 삭제하려는 사진이 대표 사진인 경우 다른 사진을 대표 사진으로 임시 설정한다.
if(oldProfileImage.isThumbnail()){
List<AccountProfileImage> profileImages = accountProfileImageRepository.findAllByAccountAndDeletedAtIsNull(account);

Expand Down Expand Up @@ -198,7 +199,7 @@ public ResponseCode changeThumbnailImage(Account account, long imageId) {

@Transactional
public SliceResponse<PostResponseDto> readUsersPosts(Long userId, Integer page) {
Account account = accountRepository.findById(userId).orElseThrow();
Account account = accountRepository.findById(userId).orElseThrow( () -> new NoSuchElementException("계정을 찾을 수 없습니다"));
PageRequest pageRequest = PageRequest.of(page, Constants.PAGE_DEFAULT_SIZE, Sort.by("createdAt").descending());
return new SliceResponse<>(postRepository.findAllByAccountAndDeletedAtIsNullOrderByIdDesc(account, pageRequest)
.map(post -> PostResponseDto.of(post, getThumbnailImage(post.getAccount()))));
Expand All @@ -207,7 +208,7 @@ public SliceResponse<PostResponseDto> readUsersPosts(Long userId, Integer page)

@Transactional
public SliceResponse<PostResponseDto> readUsersComments(Long userId, Integer page) {
Account account = accountRepository.findById(userId).orElseThrow();
Account account = accountRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("계정을 찾을 수 없습니다"));
PageRequest pageRequest = PageRequest.of(page, Constants.PAGE_DEFAULT_SIZE, Sort.by("createdAt").descending());

// Post 중복 제거
Expand All @@ -216,7 +217,6 @@ public SliceResponse<PostResponseDto> readUsersComments(Long userId, Integer pa
.map(Comment::getPost)
.collect(Collectors.toCollection(LinkedHashSet::new));

// uniquePosts를 Pageable로 변환하여 Slice로 생성
Slice<PostResponseDto> postSlice = uniquePosts.stream()
.map(post -> PostResponseDto.of(post, getThumbnailImage(post.getAccount())))
.collect(Collectors.collectingAndThen(Collectors.toList(), list -> {
Expand All @@ -229,8 +229,12 @@ public SliceResponse<PostResponseDto> readUsersComments(Long userId, Integer pa
}

public SliceResponse<PartyResponse> readUsersParties(Long userId, Integer page) {
Account account = accountRepository.findById(userId).orElseThrow(() -> new NoSuchElementException("계정을 찾을 수 없습니다"));
PageRequest pageRequest = PageRequest.of(page, Constants.PAGE_DEFAULT_SIZE, Sort.by("createdAt").descending());

return null;

return new SliceResponse<> (partyRepository.findByAccountFromPartyAndPartyParticipant(account,pageRequest)
.map(party -> PartyResponse.of(party)));

}
}
2 changes: 1 addition & 1 deletion src/main/java/meltingpot/server/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class Constants {
public static final Integer AUTH_TIME_LIMIT = 10;

// 무한스크롤 페이지 디폴트 사이즈
public static final Integer PAGE_DEFAULT_SIZE = 5;
public static final Integer PAGE_DEFAULT_SIZE = 7;

// 기본 프로필 이미지키
public static final String DEFAULT_PROFILE_IMAGE_KEY = "65352995-3744-4482-8d0f-8b7baf5d0903";
Expand Down

0 comments on commit daa7ead

Please sign in to comment.