Fix some implicit bugs

pull/146/head
johnniang 2019-04-09 09:10:25 +08:00
parent 468a0323b4
commit 1f703ecf45
4 changed files with 8 additions and 8 deletions

View File

@ -15,7 +15,7 @@ import javax.persistence.*;
* @date 4/8/19 * @date 4/8/19
*/ */
@Entity @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 = ?") @SQLDelete(sql = "update theme_settings set deleted = true where id = ?")
@Where(clause = "deleted = false") @Where(clause = "deleted = false")
@Data @Data

View File

@ -19,12 +19,12 @@ public interface OptionRepository extends BaseRepository<Option, Integer> {
* @param key key * @param key key
* @return Option * @return Option
*/ */
Optional<Option> findByOptionKey(String key); Optional<Option> findByKey(String key);
/** /**
* Delete option by key * Delete option by key
* *
* @param key key * @param key key
*/ */
void removeByOptionKey(String key); void removeByKey(String key);
} }

View File

@ -46,13 +46,13 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
if (StringUtils.isBlank(value)) { if (StringUtils.isBlank(value)) {
// If the value is blank, remove the key // If the value is blank, remove the key
optionRepository.removeByOptionKey(key); optionRepository.removeByKey(key);
log.debug("Removed option key: [{}]", key); log.debug("Removed option key: [{}]", key);
return; return;
} }
// TODO Consider cache options with map // 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); log.debug("Updating option key: [{}], value: from [{}] to [{}]", key, anOption.getValue(), value);
// Exist // Exist
anOption.setValue(value); anOption.setValue(value);
@ -143,7 +143,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::getValue); return optionRepository.findByKey(key).map(Option::getValue);
} }
@Override @Override

View File

@ -76,13 +76,13 @@ public class OptionServiceImplTest {
QnYunProperties zoneProperty = QnYunProperties.ZONE; QnYunProperties zoneProperty = QnYunProperties.ZONE;
// Given // Given
given(optionRepository.findByOptionKey(zoneProperty.getValue())).willReturn(Optional.ofNullable(option)); given(optionRepository.findByKey(zoneProperty.getValue())).willReturn(Optional.ofNullable(option));
// When // When
Zone zone = optionService.getQnYunZone(); Zone zone = optionService.getQnYunZone();
// Then // Then
then(optionRepository).should().findByOptionKey(zoneProperty.getValue()); then(optionRepository).should().findByKey(zoneProperty.getValue());
assertNotNull(zone); assertNotNull(zone);
assertThat(zone.getRegion(), equalTo(actualZone.getRegion())); assertThat(zone.getRegion(), equalTo(actualZone.getRegion()));