mirror of https://github.com/halo-dev/halo
Refactor list options by keys
parent
cea6a55963
commit
aabc665ba0
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.controller.admin.api;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import run.halo.app.model.dto.OptionDTO;
|
||||
import run.halo.app.model.params.OptionParam;
|
||||
|
@ -38,12 +39,17 @@ public class OptionController {
|
|||
|
||||
@GetMapping("map_view")
|
||||
@ApiOperation("Lists all options with map view")
|
||||
public Map<String, Object> listAllWithMapView() {
|
||||
return optionService.listOptions();
|
||||
public Map<String, Object> listAllWithMapView(@RequestParam(value = "key", required = false) List<String> keys) {
|
||||
if (CollectionUtils.isEmpty(keys)) {
|
||||
return optionService.listOptions();
|
||||
}
|
||||
|
||||
return optionService.listOptions(keys);
|
||||
}
|
||||
|
||||
@GetMapping("map_keys")
|
||||
@ApiOperation("List all of options by keys")
|
||||
@Deprecated
|
||||
public Map<String, Object> listByKeysWithMapView(@RequestParam(value = "keys") String keys) {
|
||||
return optionService.listByKeys(keys);
|
||||
}
|
||||
|
|
|
@ -73,6 +73,9 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
@NonNull
|
||||
Map<String, Object> listOptions();
|
||||
|
||||
@NonNull
|
||||
Map<String, Object> listOptions(List<String> keys);
|
||||
|
||||
/**
|
||||
* List by keys
|
||||
*
|
||||
|
@ -80,6 +83,7 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
* @return Map
|
||||
*/
|
||||
@NonNull
|
||||
@Deprecated
|
||||
Map<String, Object> listByKeys(String params);
|
||||
|
||||
/**
|
||||
|
|
|
@ -178,6 +178,23 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> listOptions(List<String> keys) {
|
||||
if (CollectionUtils.isEmpty(keys)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<String, Object> optionMap = listOptions();
|
||||
|
||||
Map<String, Object> result = new HashMap<>(keys.size());
|
||||
|
||||
keys.stream()
|
||||
.filter(optionMap::containsKey)
|
||||
.forEach(key -> result.put(key, optionMap.get(key)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> listByKeys(String params) {
|
||||
Assert.notNull(params, "Keys must not be null");
|
||||
|
|
Loading…
Reference in New Issue