Skip to content

Commit

Permalink
Merge pull request #190 from twenty-three-23/feature/TT-232
Browse files Browse the repository at this point in the history
!TT-232 VersionEntity 복합키 설정
  • Loading branch information
snacktime81 authored Jul 11, 2024
2 parents 390fc4c + 4e9a77b commit b545103
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
@JoinColumn(nullable = false, name = "theme_id", insertable = false, updatable = false)
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
public class VersionPk implements Serializable {
private Long majorVersion;
private Long minorVersion;
private Long themeId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +24,7 @@
import java.util.List;
import java.util.Map;


@Slf4j
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -52,7 +53,7 @@ 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);
Expand Down

0 comments on commit b545103

Please sign in to comment.