Skip to content

Commit

Permalink
feat: 동행 시작 여부에 따른 동행글 목록 조회 api를 추가한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
min429 committed Nov 5, 2024
1 parent cea18b2 commit f9e4736
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public ResponseEntity<PageResponse<AccompanyBoardThumbnail>> readAll(
return ResponseEntity.ok(accompanyBoardService.getAllBoards(request, region));
}

@Operation(summary = "동행 시작 여부에 따른 동행글 목록 조회")
@PostMapping("/all/by-started")
public ResponseEntity<PageResponse<AccompanyBoardThumbnail>> readAllNotStarted(
@RequestBody @Valid PageRequest request,
@RequestParam(value = "region", required = false) Region region,
@RequestParam(value = "started") boolean started) {
return ResponseEntity.ok(accompanyBoardService.getAllBoards(request, region, started));
}

@Operation(summary = "내가 쓴 동행글 목록 조회")
@PostMapping("/mine")
public ResponseEntity<PageResponse<AccompanyBoardThumbnail>> readMine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import static com.dnd.accompany.domain.accompany.entity.enums.Role.*;
import static com.dnd.accompany.domain.review.entity.QReview.*;
import static com.dnd.accompany.domain.user.entity.QUser.*;
import static java.time.LocalDateTime.*;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -106,6 +108,40 @@ public Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int s
return createSlice(size, content);
}

@Override
public Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int size, Region region, boolean started) {
List<FindBoardThumbnailsResult> content = queryFactory
.select(Projections.constructor(FindBoardThumbnailsResult.class,
accompanyBoard.id,
accompanyBoard.title,
accompanyBoard.region,
accompanyBoard.startDate,
accompanyBoard.endDate,
user.nickname,
Expressions.stringTemplate("GROUP_CONCAT(DISTINCT {0})", accompanyImage.imageUrl),
Expressions.stringTemplate(
"CONCAT(DATE_FORMAT({0}, '%Y%m%d%H%i%S'), LPAD(CAST({1} AS STRING), 6, '0'))",
accompanyBoard.updatedAt,
accompanyBoard.id
))
)
.from(accompanyUser)
.join(accompanyUser.accompanyBoard, accompanyBoard)
.join(accompanyUser.user, user)
.leftJoin(accompanyImage).on(accompanyImage.accompanyBoard.id.eq(accompanyBoard.id))
.where(isHost())
.where(isRegion(region))
.where(isStarted(started))
.where(cursorCondition(cursor, accompanyBoard.updatedAt, accompanyBoard.id))
.groupBy(accompanyBoard.id, accompanyBoard.title, accompanyBoard.region,
accompanyBoard.startDate, accompanyBoard.endDate, user.nickname)
.orderBy(accompanyBoard.updatedAt.desc(), accompanyBoard.id.desc())
.limit(size + 1)
.fetch();

return createSlice(size, content);
}

@Override
public Slice<FindRecordThumbnailsResult> findRecordThumbnails(String cursor, int size, Long userId) {
List<FindRecordThumbnailsResult> content = queryFactory
Expand Down Expand Up @@ -224,4 +260,16 @@ private BooleanBuilder isContains(String keyword) {

return booleanBuilder;
}

private BooleanBuilder isStarted(boolean started) {
BooleanBuilder clause = new BooleanBuilder();

if(started){
clause.and(accompanyBoard.startDate.loe(now()));
return clause;
}

clause.and(accompanyBoard.startDate.gt(now()));
return clause;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface AccompanyBoardRepositoryCustom {

Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int size, Region region);

Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int size, Region region, boolean started);

Slice<FindRecordThumbnailsResult> findRecordThumbnails(String cursor, int size, Long userId);

Slice<FindBoardThumbnailsResult> findBoardThumbnailsByHostId(String cursor, int size, Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public PageResponse<AccompanyBoardThumbnail> getAllBoards(PageRequest request, R
return new PageResponse<>(sliceResult.hasNext(), thumbnails, getLastCursor(sliceResult.getContent()));
}

@Transactional(readOnly = true)
public PageResponse<AccompanyBoardThumbnail> getAllBoards(PageRequest request, Region region, boolean started) {
Slice<FindBoardThumbnailsResult> sliceResult = accompanyBoardRepository.findBoardThumbnails(request.cursor(), request.size(), region, started);

List<AccompanyBoardThumbnail> thumbnails = getBoardThumbnails(sliceResult.getContent());

return new PageResponse<>(sliceResult.hasNext(), thumbnails, getLastCursor(sliceResult.getContent()));
}

@Transactional(readOnly = true)
public PageResponse<AccompanyRecordThumbnail> getAllRecords(PageRequest request, Long userId) {
Slice<FindRecordThumbnailsResult> sliceResult = accompanyBoardRepository.findRecordThumbnails(request.cursor(), request.size(), userId);
Expand Down

0 comments on commit f9e4736

Please sign in to comment.