Skip to content

Commit

Permalink
Fix : summary id to null when video inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
D-w-nJ committed Feb 26, 2024
1 parent 60e4781 commit d9f1c22
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ public void updateLastViewTime(Timestamp timestamp) {
}

public MaterialStatus getMaterialStatus() {
if(summary == null){
return MaterialStatus.CREATING;
}else{
return MaterialStatus.from(summary.getSummaryId());
}
return video.getMaterialStatus();
}
}
14 changes: 9 additions & 5 deletions src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,19 @@ public SummaryEntity getSummary() {
}

public void setSummary(SummaryEntity summary) {
this.getSummaries().add(summary);
this.summaryId = summary.getSummaryId();
if(summary != null){
this.getSummaries().add(summary);
this.summaryId = summary.getSummaryId();
}else{
this.summaryId = null;
}
}

public void setMaterialStatus(MaterialStatus status) {
this.materialStatus = status.getValue();
}

if (status.equals(MaterialStatus.CREATION_FAILED)) {
this.summaryId = (long) MaterialStatus.CREATION_FAILED.getValue();
}
public MaterialStatus getMaterialStatus(){
return MaterialStatus.getByInt(materialStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public VideoEntity save(VideoEntity video) {
video.getDuration(),
video.getChannel(),
video.getThumbnail(),
video.getSummaryId(),
video.getDescription(),
video.getTitle(),
video.getLanguage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class VideoRepositorySql {

public static final String SAVE = """
INSERT
INTO video (video_code, duration, channel, thumbnail, summary_id, description, title, language, license,
INTO video (video_code, duration, channel, thumbnail, description, title, language, license,
view_count, published_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""

public static final String GET_BY_CODE = """
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/m9d/sroom/course/vo/CourseVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public VideoCompletionStatus getCompletionStatus(int viewDuration, int videoDura
}

public MaterialStatus getMaterialStatus() {
return MaterialStatus.from(summaryId);
if(summaryId != null){
return MaterialStatus.CREATED;
}else{
return MaterialStatus.CREATION_FAILED;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void saveMaterials(MaterialResultVo materialVo) throws VideoNotFoundFromD

if (materialVo.getIsValid() == MaterialVaildStatus.IN_VALID.getValue()) {
videoEntity.setMaterialStatus(MaterialStatus.CREATION_FAILED);
videoEntity.setSummary(null);
} else {
videoEntity.setMaterialStatus(MaterialStatus.CREATED);
videoEntity.setSummary(summaryRepository.save(SummaryEntity.create(videoEntity, materialVo.getSummary())));
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/m9d/sroom/material/model/MaterialStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ public int getValue() {
return value;
}

public static MaterialStatus from(Long summaryId) {
if (summaryId == CREATING.getValue()) {
return MaterialStatus.CREATING;
} else if (summaryId == CREATION_FAILED.getValue()) {
return MaterialStatus.CREATION_FAILED;
} else {
return MaterialStatus.CREATED;
public static MaterialStatus getByInt(int value){
for (MaterialStatus status : MaterialStatus.values()) {
if (status.getValue() == value) {
return status;
}
}
return null;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/m9d/sroom/video/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void putVideo(Video video) {

VideoEntity videoEntity;
if (videoEntityOptional.isEmpty()) {
videoEntity = videoRepository.save(new VideoEntity(video, (long) MaterialStatus.CREATING.getValue()));
videoEntity = videoRepository.save(new VideoEntity(video, null));
} else if (!DateUtil.hasRecentUpdate(videoEntityOptional.get().getUpdatedAt(), VideoConstant.VIDEO_UPDATE_THRESHOLD_HOURS)) {
videoEntity = videoRepository.updateById(videoEntityOptional.get().getVideoId(), videoEntityOptional.get()
.updateByYoutube(video, videoEntityOptional.get().getSummaryId()));
Expand Down

0 comments on commit d9f1c22

Please sign in to comment.