Skip to content

Commit

Permalink
Merge pull request #79 from kimh7537/develop
Browse files Browse the repository at this point in the history
Fix: MatchPost정보 조회 수정
  • Loading branch information
kimh7537 authored Aug 21, 2024
2 parents 9f6cedb + c0a3096 commit 73b1f72
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ public ResponseEntity<MatchCreateResponse> createMatch(@RequestBody MatchCreateR

@GetMapping
@Operation(summary = "모든 매칭 조회", description = "모든 매칭 게시글을 조회합니다.")
public ResponseEntity<MatchCreateResponseWrapper> getAllMatches(@RequestParam Long clubMemberId) {
List<MatchCreateResponse> responses = matchService.findAllMatches(clubMemberId);
public ResponseEntity<MatchCreateResponseWrapper> getAllMatches() {
List<MatchCreateResponse> responses = matchService.findAllMatches();
return ResponseEntity.ok(MatchCreateResponseWrapper.from(responses));
}

@GetMapping("/paged")
@Operation(summary = "모든 매칭 조회 (페이징)", description = "모든 매칭 게시글을 페이징 처리하여 조회합니다.")
public ResponseEntity<MatchCreateResponseWrapper> getAllMatchesPaged(
@RequestParam Long clubMemberId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<MatchCreateResponse> responses = matchService.findAllMatches(clubMemberId, pageable);
Page<MatchCreateResponse> responses = matchService.findAllMatches(pageable);
return ResponseEntity.ok(MatchCreateResponseWrapper.from(responses));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@ public ResponseEntity<MercenaryCreateResponse> createMatch(@RequestBody Mercenar
}

@GetMapping
@Operation(summary = "모든 용병 매칭 조회", description = "모든 용병 매칭 게시글을 조회합니다. 자신이 속한 동아리에서 올린 정보는 보이지 않습니다.")
public ResponseEntity<MercenaryCreateResponseWrapper> getAllMatches(@RequestParam Long clubMemberId) {
List<MercenaryCreateResponse> responses = mercenaryService.findAllMatches(clubMemberId);
@Operation(summary = "모든 용병 매칭 조회", description = "모든 용병 매칭 게시글을 조회합니다")
public ResponseEntity<MercenaryCreateResponseWrapper> getAllMatches() {
List<MercenaryCreateResponse> responses = mercenaryService.findAllMatches();
return ResponseEntity.ok(MercenaryCreateResponseWrapper.from(responses));
}

@GetMapping("/paged")
@Operation(summary = "모든 용병 매칭 조회 (페이징)", description = "모든 용병 매칭 게시글을 페이징(10개) 처리하여 조회합니다.")
public ResponseEntity<MercenaryCreateResponseWrapper> getAllMatchesPaged(
@RequestParam Long clubMemberId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<MercenaryCreateResponse> responses = mercenaryService.findAllMatches(clubMemberId, pageable);
Page<MercenaryCreateResponse> responses = mercenaryService.findAllMatches(pageable);
return ResponseEntity.ok(MercenaryCreateResponseWrapper.from(responses));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
public interface MatchPostRepository extends JpaRepository<MatchPost, Long>, MatchPostRepositoryCustom {


@Query("SELECT m FROM MatchPost m WHERE m.homeClub <> :homeClub " +
"AND (m.matchStartDate > :date " +
"OR (m.matchStartDate = :date AND m.matchStartTime > :time))")
Page<MatchPost> findAllByHomeClubNotAndMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
@Param("homeClub") Club homeClub,
@Query("SELECT m FROM MatchPost m WHERE m.matchStartDate > :date " +
"OR (m.matchStartDate = :date AND m.matchStartTime > :time)")
Page<MatchPost> findAllByMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
@Param("date") LocalDate date,
@Param("time") LocalTime time,
Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
@Repository
public interface MercenaryPostRepository extends JpaRepository<MercenaryPost, Long>, MercenaryPostRepositoryCustom {

@Query("SELECT m FROM MercenaryPost m WHERE m.homeClub <> :homeClub " +
"AND (m.matchStartDate > :date " +
"OR (m.matchStartDate = :date AND m.matchStartTime > :time))")
Page<MercenaryPost> findAllByHomeClubNotAndMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
@Param("homeClub") Club homeClub,
@Query("SELECT m FROM MercenaryPost m WHERE m.matchStartDate > :date " +
"OR (m.matchStartDate = :date AND m.matchStartTime > :time)")
Page<MercenaryPost> findAllByMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
@Param("date") LocalDate date,
@Param("time") LocalTime time,
Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,29 @@ public MatchCreateResponse createMatch(MatchCreateRequest matchCreateRequest) {
}


public List<MatchCreateResponse> findAllMatches(Long memberId) {
public List<MatchCreateResponse> findAllMatches() {

ClubMember clubMember = clubMemberRepository.findClubMemberByClubMemberIdx(memberId)
.orElseThrow(() -> new EntityNotFoundException("동아리 멤버를 찾을 수 없습니다."));

Club userClub = clubMember.getClub();
LocalDateTime now = LocalDateTime.now();

return matchPostRepository.findAll().stream()
.filter(matchPost -> {
LocalDateTime matchDateTime = LocalDateTime.of(matchPost.getMatchStartDate(), matchPost.getMatchStartTime());
return !matchPost.getHomeClub().equals(userClub) && matchDateTime.isAfter(now);
return matchDateTime.isAfter(now);
})
.map(MatchCreateResponse::from)
.collect(Collectors.toList());
}


public Page<MatchCreateResponse> findAllMatches(Long memberId, Pageable pageable) {
ClubMember clubMember = clubMemberRepository.findClubMemberByClubMemberIdx(memberId)
.orElseThrow(() -> new EntityNotFoundException("동아리 멤버를 찾을 수 없습니다."));
public Page<MatchCreateResponse> findAllMatches(Pageable pageable) {

Club userClub = clubMember.getClub();
LocalDate today = LocalDate.now();
LocalTime nowTime = LocalTime.now();

// 데이터베이스에서 직접 필터링 및 페이징 처리하여 가져오기
Page<MatchPost> matchPostPage = matchPostRepository
.findAllByHomeClubNotAndMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
userClub, today, nowTime, pageable);
.findAllByMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
today, nowTime, pageable);

// 페이지 내용을 DTO로 변환
return matchPostPage.map(MatchCreateResponse::from);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,29 @@ public MercenaryCreateResponse createMatch(MercenaryCreateRequest mercenaryCreat



public List<MercenaryCreateResponse> findAllMatches(Long memberId) {
public List<MercenaryCreateResponse> findAllMatches() {

ClubMember clubMember = clubMemberRepository.findClubMemberByClubMemberIdx(memberId)
.orElseThrow(() -> new EntityNotFoundException("동아리 멤버를 찾을 수 없습니다."));

Club userClub = clubMember.getClub();
LocalDateTime now = LocalDateTime.now();

return mercenaryPostRepository.findAll().stream()
.filter(mercenaryPost -> {
LocalDateTime matchDateTime = LocalDateTime.of(mercenaryPost.getMatchStartDate(), mercenaryPost.getMatchStartTime());
return !mercenaryPost.getHomeClub().equals(userClub) && matchDateTime.isAfter(now);
return matchDateTime.isAfter(now);
})
.map(MercenaryCreateResponse::from)
.collect(Collectors.toList());
}


public Page<MercenaryCreateResponse> findAllMatches(Long memberId, Pageable pageable) {
ClubMember clubMember = clubMemberRepository.findClubMemberByClubMemberIdx(memberId)
.orElseThrow(() -> new EntityNotFoundException("동아리 멤버를 찾을 수 없습니다."));
public Page<MercenaryCreateResponse> findAllMatches(Pageable pageable) {

Club userClub = clubMember.getClub();
LocalDate today = LocalDate.now();
LocalTime nowTime = LocalTime.now();

// 데이터베이스에서 직접 페이징 처리하여 가져오기
Page<MercenaryPost> mercenaryPostsPage = mercenaryPostRepository
.findAllByHomeClubNotAndMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
userClub, today, nowTime, pageable);
.findAllByMatchStartDateAfterOrMatchStartDateEqualsAndMatchStartTimeAfter(
today, nowTime, pageable);


// 페이지 내용을 DTO로 변환
Expand Down

0 comments on commit 73b1f72

Please sign in to comment.