Skip to content

Commit

Permalink
Merge pull request #102 from miinyeong/main
Browse files Browse the repository at this point in the history
[#101]Feat: 오늘자 퀴즈 확인API 생성
  • Loading branch information
miinyeong authored Nov 21, 2023
2 parents 0c132f2 + b86f18a commit c6556da
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public List<QuizAnswerCheckDTO> checkAnswer(@PathVariable Long quiz_id){
//퀴즈 목록 확인
@GetMapping(value = "/quiz/quizList/{family_id}")
public List<QuizListDTO> quizList(@PathVariable String family_id){return quizService.quizList(family_id);}

//오늘의 퀴즈 확인
@GetMapping(value = "/quiz/todayQuiz/{family_id}")
public QuizListDTO todayQuiz(@PathVariable String family_id){return quizService.todayQuiz(family_id);}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.onestep.server.repository;

import com.onestep.server.entity.Family;
import com.onestep.server.entity.Letter;
import com.onestep.server.entity.Quiz;
import com.onestep.server.entity.QuizAnswer;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -20,4 +18,5 @@ public interface IQuizRepository extends JpaRepository<Quiz, Long> {

@Query("select q from Quiz q where q.user.family.fam_id =:family_id")
List<Quiz> findQuizByFamily(@Param("family_id") String family_id);

}
49 changes: 48 additions & 1 deletion src/main/java/com/onestep/server/service/quiz/QuizService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ public Boolean canQuiz(String family_id){
Boolean canQuiz = true;
Date writeDate = new Date();
LocalTime now = LocalTime.now();

log.info("Tset1 ={}",writeDate);
if(now.getHour()<6){
Date dDate = new Date();
writeDate = new Date(dDate.getTime()+(1000*60*60*24*-1));
log.info("Tset2 ={}",writeDate);
}
Optional<Quiz> optionalQuiz = iQuizRepository.findQuizByWriteDate(family_id,writeDate);
log.info("Tset3 ={}",optionalQuiz);
// 같은 날에 퀴즈를 생성 했을 시
if(optionalQuiz.isPresent()){
log.info("Tset4 ={}",optionalQuiz.get());
canQuiz = false;
}

Expand Down Expand Up @@ -161,4 +164,48 @@ public List<QuizListDTO> quizList(String family_id){
}
return quizLists;
}

//오늘의 퀴즈 확인
public QuizListDTO todayQuiz(String family_id){
Date writeDate = new Date();
LocalTime now = LocalTime.now();

if(now.getHour()<6){
Date dDate = new Date();
writeDate = new Date(dDate.getTime()+(1000*60*60*24*-1));
}
Optional<Quiz> optionalQuiz = iQuizRepository.findQuizByWriteDate(family_id,writeDate);

// 같은 날에 퀴즈를 생성 했을 시
if(optionalQuiz.isPresent()){
Quiz q = optionalQuiz.get();
QuizListDTO quizListDTO = new QuizListDTO();
quizListDTO.setQuiz_id(q.getQuiz_id());
quizListDTO.setWriter_id(q.getUser().getUser_id());
quizListDTO.setQuiz_txt(q.getQuiz_txt());
quizListDTO.setAnswer1(q.getAnswer1());
quizListDTO.setAnswer2(q.getAnswer2());
quizListDTO.setAnswer3(q.getAnswer3());
quizListDTO.setAnswer4(q.getAnswer4());
quizListDTO.setQuiz_ans(q.getQuiz_ans());
quizListDTO.setWrite_date(q.getWrite_date());

List<QuizAnswer> quizAnswers = q.getQuizAnswers();
List<QuizAnswerCheckDTO> quizAnswerCheck = new ArrayList<>();
for (QuizAnswer qa : quizAnswers) {
QuizAnswerCheckDTO quizAnswerCheckDTO = new QuizAnswerCheckDTO();
User answer = qa.getUser();
quizAnswerCheckDTO.setQuizAnswer_id(qa.getQuizAnswer_id());
quizAnswerCheckDTO.setUser_id(answer.getUser_id());
quizAnswerCheckDTO.setQuiz_ans(qa.getQuiz_ans());
quizAnswerCheckDTO.setQuiz_state(qa.getQuiz_state());

quizAnswerCheck.add(quizAnswerCheckDTO);
}
quizListDTO.setQuizAnswers(quizAnswerCheck);
return quizListDTO;
}else{
return null;
}
}
}

0 comments on commit c6556da

Please sign in to comment.