Add ThemeSetting entity

pull/146/head
johnniang 2019-04-08 23:23:03 +08:00
parent edefa7e810
commit 1fe26cb7d8
3 changed files with 51 additions and 12 deletions

View File

@ -20,7 +20,7 @@ import javax.persistence.*;
@SQLDelete(sql = "update options set deleted = true where id = ?") @SQLDelete(sql = "update options set deleted = true where id = ?")
@Where(clause = "deleted = false") @Where(clause = "deleted = false")
@Data @Data
@ToString @ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@NoArgsConstructor @NoArgsConstructor
public class Option extends BaseEntity { public class Option extends BaseEntity {
@ -33,13 +33,13 @@ public class Option extends BaseEntity {
* option key * option key
*/ */
@Column(name = "option_key", columnDefinition = "varchar(100) not null") @Column(name = "option_key", columnDefinition = "varchar(100) not null")
private String optionKey; private String key;
/** /**
* option value * option value
*/ */
@Column(name = "option_value", columnDefinition = "varchar(1023) not null") @Column(name = "option_value", columnDefinition = "varchar(1023) not null")
private String optionValue; private String value;
/** /**
* source,default is system * source,default is system
@ -47,9 +47,9 @@ public class Option extends BaseEntity {
@Column(name = "option_source", columnDefinition = "int default 0") @Column(name = "option_source", columnDefinition = "int default 0")
private OptionSource source; private OptionSource source;
public Option(String optionKey, String optionValue) { public Option(String key, String value) {
this.optionKey = optionKey; this.key = key;
this.optionValue = optionValue; this.value = value;
} }
@Override @Override

View File

@ -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;
}

View File

@ -61,16 +61,16 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
// TODO Consider cache options with map // TODO Consider cache options with map
Option option = optionRepository.findByOptionKey(key).map(anOption -> { 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 // Exist
anOption.setOptionValue(value); anOption.setValue(value);
return anOption; return anOption;
}).orElseGet(() -> { }).orElseGet(() -> {
log.debug("Creating option key: [{}], value: [{}]", key, value); log.debug("Creating option key: [{}], value: [{}]", key, value);
// Not exist // Not exist
Option anOption = new Option(); Option anOption = new Option();
anOption.setOptionKey(key); anOption.setKey(key);
anOption.setOptionValue(value); anOption.setValue(value);
anOption.setSource(source); anOption.setSource(source);
return anOption; return anOption;
}); });
@ -131,7 +131,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
*/ */
@Override @Override
public Map<String, String> listOptions() { public Map<String, String> listOptions() {
return ServiceUtils.convertToMap(listAll(), Option::getOptionKey, Option::getOptionValue); return ServiceUtils.convertToMap(listAll(), Option::getKey, Option::getValue);
} }
@Override @Override
@ -159,7 +159,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
public Optional<String> getByKey(String key) { public Optional<String> getByKey(String key) {
Assert.hasText(key, "Option key must not be blank"); Assert.hasText(key, "Option key must not be blank");
return optionRepository.findByOptionKey(key).map(Option::getOptionValue); return optionRepository.findByOptionKey(key).map(Option::getValue);
} }
@Override @Override