Skip to content

Commit

Permalink
AddTimeFieldToQuizResponseDto
Browse files Browse the repository at this point in the history
  • Loading branch information
ms0828 committed Nov 22, 2023
1 parent 83288c4 commit ee07d90
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class QuizResponseDto {
private Integer answer;
private String reason;
private Integer selectedAnswer;
private Integer secondTime;

public QuizResponseDto(Quiz quiz){
this.id = quiz.getId();
Expand All @@ -21,5 +22,6 @@ public QuizResponseDto(Quiz quiz){
this.answer = quiz.getAnswer();
this.reason = quiz.getReason();
this.selectedAnswer = -1;
this.secondTime = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.example.d3nserver.quiz.dto.response.QuizResponseDto;
import com.example.d3nserver.quiz.repository.QuizRepository;
import com.example.d3nserver.quiz.repository.SolvedQuizRepository;
import com.example.d3nserver.time.domain.QuizSolvingTime;
import com.example.d3nserver.time.repository.QuizSolvingTimeRepository;
import com.example.d3nserver.time.service.QuizSolvingTimeService;
import com.example.d3nserver.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -20,6 +23,7 @@
public class QuizService {
private final QuizRepository quizRepository;
private final SolvedQuizRepository solvedQuizRepository;
private final QuizSolvingTimeRepository quizSolvingTimeRepository;

public List<QuizResponseDto> getQuizList(Long newsId){
List<Quiz> quizList = quizRepository.findAllByNewsId(newsId);
Expand All @@ -32,6 +36,8 @@ public List<QuizResponseDto> getQuizListByUser(User user, Long newsId){
Optional<SolvedQuiz> solvedQuiz = solvedQuizRepository.findByUserAndQuiz(user, quiz);
QuizResponseDto quizResponseDto = new QuizResponseDto(quiz);
solvedQuiz.ifPresent(value -> quizResponseDto.setSelectedAnswer(value.getSelectedAnswer()));
Optional<QuizSolvingTime> quizSolvingTime = quizSolvingTimeRepository.findByUserIdAndQuizId(user.getId(), quiz.getId());
quizSolvingTime.ifPresent(value -> quizResponseDto.setSecondTime(value.getSecondTime()));
quizResponseDtoList.add(quizResponseDto);
}
return quizResponseDtoList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class NewsReadingTimeController {

@ApiDocumentResponse
@Operation(summary = "NewsReadingTime Update", description = "뉴스 읽는 시간을 갱신합니다.")
@PostMapping("/time")
@PatchMapping("/time")
public ResponseEntity<NewsReadingTimeResponseDto> updateNewsReadingTime(@ReqUser User user, @RequestBody @Parameter(description = "newsReadingTime request Dto",
content = @Content(schema = @Schema(implementation = NewsReadingTimeRequestDto.class))) NewsReadingTimeRequestDto requestDto){
newsReadingTimeService.updateNewsReadingTime(user,requestDto.getNewsId(),requestDto.getSecondTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Tag(name = "QuizSolvingTime v1.1 API", description = "퀴즈 푸는 시간 관련 api")
@RestController
Expand All @@ -29,7 +26,7 @@ public class QuizSolvingTimeController {

@ApiDocumentResponse
@Operation(summary = "Quiz Solving Update", description = "퀴즈 푸는 시간을 갱신합니다.")
@PostMapping("/time")
@PatchMapping("/time")
public ResponseEntity<QuizSolvingTimeResponseDto> updateQuizSolvingTime(@ReqUser User user, @RequestBody @Parameter(description = "quizSolvingTime request Dto",
content = @Content(schema = @Schema(implementation = QuizSolvingTimeRequestDto.class))) QuizSolvingTimeRequestDto requestDto){
quizSolvingTimeService.updateQuizSolvingTime(user,requestDto.getQuizId(),requestDto.getSecondTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class QuizSolvingTime extends BaseEntity {
public QuizSolvingTime(String userId, Long quizId){
this.userId = userId;
this.quizId = quizId;
this.secondTime = 0;
}

public void updateSolvingTime(int secondTime){
Expand Down

0 comments on commit ee07d90

Please sign in to comment.