From e7a443b4c734b1c565c725012b2bb56b9ed936a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Mon, 23 Sep 2024 13:42:08 +0900 Subject: [PATCH 1/4] feature :: add getParticipantsCountToday service logic --- .../com/dnd/spaced/domain/quiz/application/QuizService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/dnd/spaced/domain/quiz/application/QuizService.java b/src/main/java/com/dnd/spaced/domain/quiz/application/QuizService.java index 309688a..9f4a8cd 100644 --- a/src/main/java/com/dnd/spaced/domain/quiz/application/QuizService.java +++ b/src/main/java/com/dnd/spaced/domain/quiz/application/QuizService.java @@ -47,6 +47,10 @@ public QuizResponseDto getQuiz(Long quizId) { return QuizServiceMapper.toResponse(quiz.getId(), quiz.getQuestions()); } + public long getParticipantsCountToday() { + return quizResultRepository.countParticipantsToday(); + } + @Transactional public List submitAnswers(Long quizId, QuizRequestDto requestDto) { List questions = findQuizById(quizId).getQuestions(); From c0e6c66959bc63f0d9e799ff7f6a4add86345786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Mon, 23 Sep 2024 13:42:25 +0900 Subject: [PATCH 2/4] feature :: add getParticipantsCountToday query --- .../domain/quiz/domain/repository/QuizResultRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/dnd/spaced/domain/quiz/domain/repository/QuizResultRepository.java b/src/main/java/com/dnd/spaced/domain/quiz/domain/repository/QuizResultRepository.java index 20fdac3..57ed043 100644 --- a/src/main/java/com/dnd/spaced/domain/quiz/domain/repository/QuizResultRepository.java +++ b/src/main/java/com/dnd/spaced/domain/quiz/domain/repository/QuizResultRepository.java @@ -2,9 +2,12 @@ import com.dnd.spaced.domain.quiz.domain.QuizResult; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository public interface QuizResultRepository extends CrudRepository { + @Query("SELECT COUNT(DISTINCT qr.accountId) FROM QuizResult qr WHERE DATE(qr.createdAt) = CURRENT_DATE") + long countParticipantsToday(); } From 0e4509ab2a013f05b42b1b3a17732d1701140a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Mon, 23 Sep 2024 13:42:37 +0900 Subject: [PATCH 3/4] feature :: add column to quiz result --- .../dnd/spaced/domain/quiz/domain/QuizResult.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dnd/spaced/domain/quiz/domain/QuizResult.java b/src/main/java/com/dnd/spaced/domain/quiz/domain/QuizResult.java index a171e7a..bd238fd 100644 --- a/src/main/java/com/dnd/spaced/domain/quiz/domain/QuizResult.java +++ b/src/main/java/com/dnd/spaced/domain/quiz/domain/QuizResult.java @@ -8,6 +8,8 @@ import jakarta.persistence.Id; import lombok.*; +import java.time.LocalDate; + @Entity @Getter @EqualsAndHashCode(of = "id") @@ -17,6 +19,8 @@ public class QuizResult { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + private Long accountId; + @ManyToOne @JoinColumn(name = "quiz_question_id") private QuizQuestion quizQuestion; @@ -27,14 +31,20 @@ public class QuizResult { private boolean isCorrect; + private LocalDate createdAt; + @Builder private QuizResult( QuizQuestion quizQuestion, QuizOption selectedOption, - boolean isCorrect + boolean isCorrect, + Long accountId, + LocalDate createdAt ) { this.quizQuestion = quizQuestion; this.selectedOption = selectedOption; this.isCorrect = isCorrect; + this.accountId = accountId; + this.createdAt = createdAt; } } From 04cb39b5909f37496d67d9b2f5539729d50ae4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Mon, 23 Sep 2024 13:42:47 +0900 Subject: [PATCH 4/4] feature :: add /today/participants api --- .../dnd/spaced/domain/quiz/presentation/QuizController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/dnd/spaced/domain/quiz/presentation/QuizController.java b/src/main/java/com/dnd/spaced/domain/quiz/presentation/QuizController.java index 42a7cac..05e2d3a 100644 --- a/src/main/java/com/dnd/spaced/domain/quiz/presentation/QuizController.java +++ b/src/main/java/com/dnd/spaced/domain/quiz/presentation/QuizController.java @@ -47,4 +47,10 @@ public ResponseEntity> submitQuiz(@PathVariable Long id, List results = quizService.submitAnswers(id, requestDto); return ResponseEntity.ok(results); } + + @GetMapping("/today/participants") + public ResponseEntity getParticipantsCountToday() { + long participantsCount = quizService.getParticipantsCountToday(); + return ResponseEntity.ok(participantsCount); + } }