From 817e62fd72ef58b6d7e31d8fb53367a1eb73540d Mon Sep 17 00:00:00 2001 From: snacktime Date: Thu, 11 Jul 2024 17:21:25 +0900 Subject: [PATCH 1/2] =?UTF-8?q?!bug:=20TT-232=20VersionEntity=20=EB=B3=B5?= =?UTF-8?q?=ED=95=A9=ED=82=A4=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VersionEntity에서 themeId를 복합키로 추가 --- .../peech/script/domain/ScriptEntity.java | 3 ++- .../peech/script/domain/VersionEntity.java | 13 ++++++++----- .../twentythree/peech/script/domain/VersionPk.java | 1 + .../peech/script/service/ScriptService.java | 7 +++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/twentythree/peech/script/domain/ScriptEntity.java b/src/main/java/com/twentythree/peech/script/domain/ScriptEntity.java index af1305ac..adcbded1 100644 --- a/src/main/java/com/twentythree/peech/script/domain/ScriptEntity.java +++ b/src/main/java/com/twentythree/peech/script/domain/ScriptEntity.java @@ -25,7 +25,8 @@ public class ScriptEntity extends BaseCreatedAtEntity { @OneToOne @JoinColumns(value = { @JoinColumn(name = "major_version"), - @JoinColumn(name = "minor_version") + @JoinColumn(name = "minor_version"), + @JoinColumn(name = "theme_id") }) private VersionEntity version; diff --git a/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java b/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java index d8ca2848..640bf331 100644 --- a/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java +++ b/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java @@ -21,20 +21,23 @@ public class VersionEntity extends BaseCreatedAtEntity { @Id @Column(name = "minor_version") private Long minorVersion; + @Id + @Column(name = "theme_id") + private Long themeId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(nullable = false, name = "theme_id") private ThemeEntity ThemeEntity; - public static VersionEntity of(Long majorVersion, Long minorVersion, ThemeEntity ThemeEntity) { - return new VersionEntity(majorVersion, minorVersion, ThemeEntity); + public static VersionEntity of(Long majorVersion, Long minorVersion, Long themeId, ThemeEntity ThemeEntity) { + return new VersionEntity(majorVersion, minorVersion, themeId, ThemeEntity); } - public static VersionEntity ofCreateInputScriptVersion(Long latestMajorVersion, ThemeEntity ThemeEntity) { + public static VersionEntity ofCreateInputScriptVersion(Long latestMajorVersion, Long themeId, ThemeEntity ThemeEntity) { if (latestMajorVersion == null) { - return VersionEntity.of(1L, 0L, ThemeEntity); + return VersionEntity.of(1L, 0L, themeId, ThemeEntity); } else { - return VersionEntity.of(latestMajorVersion + 1L, 0L, ThemeEntity); + return VersionEntity.of(latestMajorVersion + 1L, 0L, themeId, ThemeEntity); } } diff --git a/src/main/java/com/twentythree/peech/script/domain/VersionPk.java b/src/main/java/com/twentythree/peech/script/domain/VersionPk.java index df607a78..eec51794 100644 --- a/src/main/java/com/twentythree/peech/script/domain/VersionPk.java +++ b/src/main/java/com/twentythree/peech/script/domain/VersionPk.java @@ -15,4 +15,5 @@ public class VersionPk implements Serializable { private Long majorVersion; private Long minorVersion; + private Long themeId; } diff --git a/src/main/java/com/twentythree/peech/script/service/ScriptService.java b/src/main/java/com/twentythree/peech/script/service/ScriptService.java index f17b89b9..272a9650 100644 --- a/src/main/java/com/twentythree/peech/script/service/ScriptService.java +++ b/src/main/java/com/twentythree/peech/script/service/ScriptService.java @@ -11,6 +11,7 @@ import com.twentythree.peech.script.repository.*; import com.twentythree.peech.common.utils.ScriptUtils; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,7 +24,7 @@ import java.util.List; import java.util.Map; - +@Slf4j @RequiredArgsConstructor @Service @Transactional(readOnly = true) @@ -52,11 +53,13 @@ public SaveScriptDTO saveInputScript(Long themeId, String[] paragraphs) { Long latestMajorVersion = scriptRepository.findByMaxMajorVersionInthemeId(themeId); - VersionEntity versionEntity = VersionEntity.ofCreateInputScriptVersion(latestMajorVersion, ThemeEntity); + VersionEntity versionEntity = VersionEntity.ofCreateInputScriptVersion(latestMajorVersion, themeId, ThemeEntity); ScriptEntity scriptEntity = ScriptEntity.ofCreateInputScript(versionEntity, script, expectedTime, InputAndSttType.INPUT); versionRepository.save(versionEntity); + log.info(" s_id {}, {}, {}", scriptEntity.getScriptId(), scriptEntity.getScriptContent(), scriptEntity.getTotalExpectTime()); scriptRepository.save(scriptEntity); + log.info("okay"); return new SaveScriptDTO(scriptEntity, ScriptUtils.calculateExpectedTime(script)); } From 4e9a77b0229b3180c7d09cf7666c391cf42ee156 Mon Sep 17 00:00:00 2001 From: snacktime Date: Thu, 11 Jul 2024 17:54:30 +0900 Subject: [PATCH 2/2] =?UTF-8?q?bug:=20TT-232=20=EB=B3=B5=ED=95=A9=ED=82=A4?= =?UTF-8?q?=20ManyToOne=20=EC=A4=91=EB=B3=B5=20db=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit theme_id와 ThemeEntity가 DB에 값을 중복해서 저장하려고해 ThemeEntity는 insertable = false, updatable = false로 중복 저장을 방지했다. --- .../java/com/twentythree/peech/script/domain/VersionEntity.java | 2 +- .../com/twentythree/peech/script/service/ScriptService.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java b/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java index 640bf331..53ed2f48 100644 --- a/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java +++ b/src/main/java/com/twentythree/peech/script/domain/VersionEntity.java @@ -26,7 +26,7 @@ public class VersionEntity extends BaseCreatedAtEntity { private Long themeId; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(nullable = false, name = "theme_id") + @JoinColumn(nullable = false, name = "theme_id", insertable = false, updatable = false) private ThemeEntity ThemeEntity; public static VersionEntity of(Long majorVersion, Long minorVersion, Long themeId, ThemeEntity ThemeEntity) { diff --git a/src/main/java/com/twentythree/peech/script/service/ScriptService.java b/src/main/java/com/twentythree/peech/script/service/ScriptService.java index 272a9650..f5e5024a 100644 --- a/src/main/java/com/twentythree/peech/script/service/ScriptService.java +++ b/src/main/java/com/twentythree/peech/script/service/ScriptService.java @@ -57,9 +57,7 @@ public SaveScriptDTO saveInputScript(Long themeId, String[] paragraphs) { ScriptEntity scriptEntity = ScriptEntity.ofCreateInputScript(versionEntity, script, expectedTime, InputAndSttType.INPUT); versionRepository.save(versionEntity); - log.info(" s_id {}, {}, {}", scriptEntity.getScriptId(), scriptEntity.getScriptContent(), scriptEntity.getTotalExpectTime()); scriptRepository.save(scriptEntity); - log.info("okay"); return new SaveScriptDTO(scriptEntity, ScriptUtils.calculateExpectedTime(script)); }