From 1fe26cb7d84e0f86c3dcfe9e58f63862191402ed Mon Sep 17 00:00:00 2001 From: johnniang Date: Mon, 8 Apr 2019 23:23:03 +0800 Subject: [PATCH] Add ThemeSetting entity --- .../run/halo/app/model/entity/Option.java | 12 +++--- .../halo/app/model/entity/ThemeSetting.java | 39 +++++++++++++++++++ .../app/service/impl/OptionServiceImpl.java | 12 +++--- 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 src/main/java/run/halo/app/model/entity/ThemeSetting.java diff --git a/src/main/java/run/halo/app/model/entity/Option.java b/src/main/java/run/halo/app/model/entity/Option.java index c99c85995..539a20ec7 100644 --- a/src/main/java/run/halo/app/model/entity/Option.java +++ b/src/main/java/run/halo/app/model/entity/Option.java @@ -20,7 +20,7 @@ import javax.persistence.*; @SQLDelete(sql = "update options set deleted = true where id = ?") @Where(clause = "deleted = false") @Data -@ToString +@ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) @NoArgsConstructor public class Option extends BaseEntity { @@ -33,13 +33,13 @@ public class Option extends BaseEntity { * option key */ @Column(name = "option_key", columnDefinition = "varchar(100) not null") - private String optionKey; + private String key; /** * option value */ @Column(name = "option_value", columnDefinition = "varchar(1023) not null") - private String optionValue; + private String value; /** * source,default is system @@ -47,9 +47,9 @@ public class Option extends BaseEntity { @Column(name = "option_source", columnDefinition = "int default 0") private OptionSource source; - public Option(String optionKey, String optionValue) { - this.optionKey = optionKey; - this.optionValue = optionValue; + public Option(String key, String value) { + this.key = key; + this.value = value; } @Override diff --git a/src/main/java/run/halo/app/model/entity/ThemeSetting.java b/src/main/java/run/halo/app/model/entity/ThemeSetting.java new file mode 100644 index 000000000..966f6535d --- /dev/null +++ b/src/main/java/run/halo/app/model/entity/ThemeSetting.java @@ -0,0 +1,39 @@ +package run.halo.app.model.entity; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import javax.persistence.*; + +/** + * Theme setting entity. + * + * @author johnniang + * @date 4/8/19 + */ +@Entity +@Table(name = "theme_settings", indexes = {@Index(columnList = "theme"), @Index(columnList = "setting_key")}) +@SQLDelete(sql = "update theme_settings set deleted = true where id = ?") +@Where(clause = "deleted = false") +@Data +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class ThemeSetting extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(name = "theme", columnDefinition = "varchar(255) not null") + private String theme; + + @Column(name = "setting_key", columnDefinition = "varchar(255) not null") + private String key; + + @Column(name = "setting_value", columnDefinition = "varchar(10239) not null") + private String value; + +} diff --git a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java index 631aca3f9..cf01a5f58 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -61,16 +61,16 @@ public class OptionServiceImpl extends AbstractCrudService impl // TODO Consider cache options with map Option option = optionRepository.findByOptionKey(key).map(anOption -> { - log.debug("Updating option key: [{}], value: from [{}] to [{}]", key, anOption.getOptionValue(), value); + log.debug("Updating option key: [{}], value: from [{}] to [{}]", key, anOption.getValue(), value); // Exist - anOption.setOptionValue(value); + anOption.setValue(value); return anOption; }).orElseGet(() -> { log.debug("Creating option key: [{}], value: [{}]", key, value); // Not exist Option anOption = new Option(); - anOption.setOptionKey(key); - anOption.setOptionValue(value); + anOption.setKey(key); + anOption.setValue(value); anOption.setSource(source); return anOption; }); @@ -131,7 +131,7 @@ public class OptionServiceImpl extends AbstractCrudService impl */ @Override public Map listOptions() { - return ServiceUtils.convertToMap(listAll(), Option::getOptionKey, Option::getOptionValue); + return ServiceUtils.convertToMap(listAll(), Option::getKey, Option::getValue); } @Override @@ -159,7 +159,7 @@ public class OptionServiceImpl extends AbstractCrudService impl public Optional getByKey(String key) { Assert.hasText(key, "Option key must not be blank"); - return optionRepository.findByOptionKey(key).map(Option::getOptionValue); + return optionRepository.findByOptionKey(key).map(Option::getValue); } @Override