mirror of https://github.com/halo-dev/halo
Fix some implicit bugs
parent
468a0323b4
commit
1f703ecf45
|
@ -15,7 +15,7 @@ import javax.persistence.*;
|
|||
* @date 4/8/19
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "theme_settings", indexes = {@Index(columnList = "theme"), @Index(columnList = "setting_key")})
|
||||
@Table(name = "theme_settings", indexes = {@Index(columnList = "setting_key")})
|
||||
@SQLDelete(sql = "update theme_settings set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
|
|
|
@ -19,12 +19,12 @@ public interface OptionRepository extends BaseRepository<Option, Integer> {
|
|||
* @param key key
|
||||
* @return Option
|
||||
*/
|
||||
Optional<Option> findByOptionKey(String key);
|
||||
Optional<Option> findByKey(String key);
|
||||
|
||||
/**
|
||||
* Delete option by key
|
||||
*
|
||||
* @param key key
|
||||
*/
|
||||
void removeByOptionKey(String key);
|
||||
void removeByKey(String key);
|
||||
}
|
||||
|
|
|
@ -46,13 +46,13 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
|
||||
if (StringUtils.isBlank(value)) {
|
||||
// If the value is blank, remove the key
|
||||
optionRepository.removeByOptionKey(key);
|
||||
optionRepository.removeByKey(key);
|
||||
log.debug("Removed option key: [{}]", key);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Consider cache options with map
|
||||
Option option = optionRepository.findByOptionKey(key).map(anOption -> {
|
||||
Option option = optionRepository.findByKey(key).map(anOption -> {
|
||||
log.debug("Updating option key: [{}], value: from [{}] to [{}]", key, anOption.getValue(), value);
|
||||
// Exist
|
||||
anOption.setValue(value);
|
||||
|
@ -143,7 +143,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::getValue);
|
||||
return optionRepository.findByKey(key).map(Option::getValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,13 +76,13 @@ public class OptionServiceImplTest {
|
|||
QnYunProperties zoneProperty = QnYunProperties.ZONE;
|
||||
|
||||
// Given
|
||||
given(optionRepository.findByOptionKey(zoneProperty.getValue())).willReturn(Optional.ofNullable(option));
|
||||
given(optionRepository.findByKey(zoneProperty.getValue())).willReturn(Optional.ofNullable(option));
|
||||
|
||||
// When
|
||||
Zone zone = optionService.getQnYunZone();
|
||||
|
||||
// Then
|
||||
then(optionRepository).should().findByOptionKey(zoneProperty.getValue());
|
||||
then(optionRepository).should().findByKey(zoneProperty.getValue());
|
||||
|
||||
assertNotNull(zone);
|
||||
assertThat(zone.getRegion(), equalTo(actualZone.getRegion()));
|
||||
|
|
Loading…
Reference in New Issue