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 = ?")
@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

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
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<Option, Integer> impl
*/
@Override
public Map<String, String> 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<Option, Integer> impl
public Optional<String> 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