Skip to content

Commit

Permalink
feat: 학교 축제 목록 조회 캐싱 사용하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed May 28, 2024
1 parent 98ae09c commit a0e29e7
Showing 1 changed file with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.festago.school.presentation.v1;

import com.festago.common.aop.ValidPageable;
import com.festago.common.dto.SliceResponse;
import com.festago.school.application.v1.SchoolFestivalsV1QueryService;
import com.festago.school.application.v1.SchoolV1QueryService;
import com.festago.school.dto.v1.SchoolDetailV1Response;
import com.festago.school.dto.v1.SchoolFestivalV1Response;
import com.festago.school.repository.v1.SchoolFestivalV1SearchCondition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -27,6 +23,7 @@
public class SchoolV1Controller {

private final SchoolV1QueryService schoolV1QueryService;
private final SchoolFestivalsV1QueryService schoolFestivalsV1QueryService;

@GetMapping("/{schoolId}")
@Operation(description = "학교의 정보를 조회한다.", summary = "학교 정보 조회")
Expand All @@ -36,23 +33,19 @@ public ResponseEntity<SchoolDetailV1Response> findDetailById(@PathVariable Long
}

@GetMapping("/{schoolId}/festivals")
@ValidPageable(maxSize = 20)
@Operation(description = "학교의 축제 목록을 조회한다.", summary = "학교 축제 목록 조회")
public ResponseEntity<SliceResponse<SchoolFestivalV1Response>> findFestivalsBySchoolId(
@PathVariable Long schoolId,
@RequestParam(required = false) Long lastFestivalId,
@RequestParam(required = false) LocalDate lastStartDate,
@RequestParam(defaultValue = "false") Boolean isPast,
@Parameter(description = "0 < size <= 20") @RequestParam(defaultValue = "10") int size
@RequestParam(defaultValue = "false") boolean isPast
) {
LocalDate today = LocalDate.now();
var searchCondition = new SchoolFestivalV1SearchCondition(lastFestivalId, lastStartDate, isPast,
PageRequest.ofSize(size));
Slice<SchoolFestivalV1Response> response = schoolV1QueryService.findFestivalsBySchoolId(
schoolId,
today,
searchCondition
);
return ResponseEntity.ok(SliceResponse.from(response));
var response = new SliceResponse<>(true, getResponse(isPast, schoolId));
return ResponseEntity.ok(response);
}

private List<SchoolFestivalV1Response> getResponse(boolean isPast, Long schoolId) {
if (isPast) {
return schoolFestivalsV1QueryService.findPastFestivalsBySchoolId(schoolId);
}
return schoolFestivalsV1QueryService.findFestivalsBySchoolId(schoolId);
}
}

0 comments on commit a0e29e7

Please sign in to comment.