Skip to content

Commit

Permalink
Merge pull request #107 from 4m9d/refactor/#101/refactor-material-ser…
Browse files Browse the repository at this point in the history
…vice(swm-323)

Refactor/#101/refactor material service(swm 323)
  • Loading branch information
D-w-nJ authored Oct 1, 2023
2 parents 9c52eac + baafbf1 commit 639a326
Show file tree
Hide file tree
Showing 39 changed files with 672 additions and 1,263 deletions.
439 changes: 0 additions & 439 deletions src/main/java/com/m9d/sroom/course/repository/CourseRepository.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/com/m9d/sroom/global/mapper/CourseQuiz.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.Data;
import org.springframework.jdbc.core.RowMapper;

import java.sql.Timestamp;

Expand All @@ -26,4 +27,18 @@ public class CourseQuiz {
private Boolean scrapped;

private Timestamp submittedTime;

public static RowMapper<CourseQuiz> getRowMapper() {
return (rs, rowNum) -> CourseQuiz.builder()
.id(rs.getLong("course_quiz_id"))
.courseId(rs.getLong("course_id"))
.quizId(rs.getLong("quiz_id"))
.videoId(rs.getLong("video_id"))
.submittedAnswer(rs.getString("submitted_answer"))
.correct(rs.getBoolean("is_correct"))
.scrapped(rs.getBoolean("is_scrapped"))
.submittedTime(rs.getTimestamp("submitted_time"))
.courseVideoId(rs.getLong("course_video_id"))
.build();
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/m9d/sroom/global/mapper/Quiz.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.Data;
import org.springframework.jdbc.core.RowMapper;

@Data
@Builder
Expand All @@ -18,4 +19,15 @@ public class Quiz {
private String subjectiveAnswer;

private Integer choiceAnswer;

public static RowMapper<Quiz> getRowMapper() {
return (rs, rowNum) -> Quiz.builder()
.id(rs.getLong("quiz_id"))
.videoId(rs.getLong("video_id"))
.type(rs.getInt("type"))
.question(rs.getString("question"))
.subjectiveAnswer(rs.getString("subjective_answer"))
.choiceAnswer(rs.getInt("choice_answer"))
.build();
}
}
13 changes: 12 additions & 1 deletion src/main/java/com/m9d/sroom/global/mapper/QuizOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.Data;
import org.springframework.jdbc.core.RowMapper;

@Data
@Builder
Expand All @@ -13,5 +14,15 @@ public class QuizOption {

private String optionText;

private int index;
private int optionIndex;

public static RowMapper<QuizOption> getRowMapper() {
return (rs, rowNum) -> QuizOption.builder()
.quizOptionId(rs.getLong("quiz_option_id"))
.quizId(rs.getLong("quiz_id"))
.optionText(rs.getString("option_text"))
.optionIndex(rs.getInt("option_index"))
.build();

}
}
11 changes: 11 additions & 0 deletions src/main/java/com/m9d/sroom/global/mapper/Summary.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import lombok.Builder;
import lombok.Data;
import org.springframework.jdbc.core.RowMapper;

import java.sql.Timestamp;

Expand All @@ -25,4 +26,14 @@ public class Summary {
private Timestamp updatedAt;

private boolean modified;

public static RowMapper<Summary> getRowMapper() {
return (rs, rowNum) -> Summary.builder()
.id(rs.getLong("summary_id"))
.videoId(rs.getLong("video_id"))
.content(rs.getString("content"))
.updatedAt(rs.getTimestamp("updated_time"))
.modified(rs.getBoolean("is_modified"))
.build();
}
}
9 changes: 6 additions & 3 deletions src/main/java/com/m9d/sroom/gpt/service/GPTService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.util.UriComponentsBuilder;

import java.time.Duration;

@Service
@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -42,9 +44,9 @@ public void saveResultFromFastApi() {
return;
}

if(resultStr == null){
if (resultStr == null) {
return;
}else{
} else {
log.debug("response body from gpt server = {}", resultStr);
}

Expand All @@ -65,6 +67,7 @@ private String getResultStr(String requestUrl) {
.toUri())
.retrieve()
.bodyToMono(String.class)
.timeout(Duration.ofSeconds(4))
.block();
} catch (Exception e) {
log.error("Error occurred while making a request to fastAPI server. message = {}", e.getMessage());
Expand All @@ -77,7 +80,7 @@ private MaterialVo getMaterialVo(String resultStr) throws NullPointerException {
MaterialVo resultVo = null;
try {
resultVo = gson.fromJson(resultStr, MaterialVo.class);
if(resultVo.getResults().size() > 0) {
if (!resultVo.getResults().isEmpty()) {
log.info("received video material count is = {}", resultVo.getResults().size());
}
} catch (JsonSyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class QuizRes {
private List<String> options;

@JsonProperty("is_submitted")
private boolean submitted;
private Boolean submitted;

private String answer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.m9d.sroom.material.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.m9d.sroom.global.mapper.Summary;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SummaryBrief {

private String content;
Expand All @@ -17,11 +22,9 @@ public class SummaryBrief {

private String modifiedAt;

@Builder
public SummaryBrief(String content, boolean modified, Timestamp timestamp) {
SimpleDateFormat simpleDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
this.content = content;
this.modified = modified;
this.modifiedAt = simpleDateFormatter.format(timestamp);
public SummaryBrief(Summary summary) {
this.content = summary.getContent();
this.modified = summary.isModified();
this.modifiedAt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(summary.getUpdatedAt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class CourseQuizNotFoundException extends NotFoundException {

private static final String MESSAGE = "해당 courseQuiz를 찾을 수 없습니다.";


public CourseQuizNotFoundException() {
super(MESSAGE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.m9d.sroom.material.exception;

import com.m9d.sroom.global.error.NotMatchException;

public class QuizNotMatchException extends NotMatchException {

private static final String MESSAGE = "입력받은 여러 퀴즈 id가 일치하지 않습니다.";
public QuizNotMatchException() {
super(MESSAGE);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/m9d/sroom/material/model/QuizType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ public int getValue() {
return value;
}

public static QuizType fromValue(int value) {
for (QuizType type : values()) {
if (type.getValue() == value) {
return type;
}
}
throw new IllegalArgumentException("Invalid QuizType value: " + value);
}

}
Loading

0 comments on commit 639a326

Please sign in to comment.