Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COT-14]Feature: 기수 단건 조회 #176

Merged
merged 4 commits into from
Oct 11, 2024
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
@@ -1,5 +1,6 @@
package org.cotato.csquiz.api.generation.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.time.LocalDate;
Expand All @@ -16,6 +17,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -52,9 +54,17 @@ public ResponseEntity<Void> changeGenerationPeriod(@RequestBody @Valid ChangeGen
return ResponseEntity.noContent().build();
}

@Operation(summary = "현재 날짜 기준 세션 정보 반환 API")
@GetMapping("/current")
public ResponseEntity<GenerationInfoResponse> findCurrentGeneration() {
LocalDate currentDate = LocalDate.now();
return ResponseEntity.ok().body(generationService.findCurrentGeneration(currentDate));
}

@Operation(summary = "기수 단건 조회 API")
@GetMapping("/{generationId}")
public ResponseEntity<GenerationInfoResponse> findGenerationById(
@PathVariable("generationId") Long generationId) {
return ResponseEntity.ok().body(generationService.findGenerationById(generationId));
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package org.cotato.csquiz.api.generation.dto;

import java.time.LocalDate;
import org.cotato.csquiz.domain.generation.entity.Generation;

public record GenerationInfoResponse(
Long generationId,
Integer generationNumber,
Integer sessionCount
Integer sessionCount,
LocalDate startDate,
LocalDate endDate
) {

public static GenerationInfoResponse from(Generation generation) {
return new GenerationInfoResponse(
generation.getId(),
generation.getNumber(),
generation.getSessionCount()
generation.getSessionCount(),
generation.getPeriod().getStartDate(),
generation.getPeriod().getEndDate()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ public GenerationInfoResponse findCurrentGeneration(LocalDate currentDate) {
.orElseThrow(() -> new EntityNotFoundException("현재 날짜에 해당하는 기수가 존재하지 않습니다")));
return GenerationInfoResponse.from(currentGeneration);
}

public GenerationInfoResponse findGenerationById(Long generationId) {
Generation generation = generationRepository.findById(generationId)
.orElseThrow(() -> new EntityNotFoundException("찾으려는 기수가 존재하지 않습니다."));
return GenerationInfoResponse.from(generation);
}
}
Loading