feat: 添加SysConfigHandler系统配置API
This commit is contained in:
+64
@@ -0,0 +1,64 @@
|
|||||||
|
package cn.novalon.manage.sys.handler.config;
|
||||||
|
|
||||||
|
import cn.novalon.manage.sys.core.domain.SysConfig;
|
||||||
|
import cn.novalon.manage.sys.core.service.ISysConfigService;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/config")
|
||||||
|
public class SysConfigHandler {
|
||||||
|
|
||||||
|
private final ISysConfigService configService;
|
||||||
|
|
||||||
|
public SysConfigHandler(ISysConfigService configService) {
|
||||||
|
this.configService = configService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Flux<SysConfig> getAllConfigs() {
|
||||||
|
return configService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Mono<ResponseEntity<SysConfig>> getConfigById(@PathVariable Long id) {
|
||||||
|
return configService.findById(id)
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.defaultIfEmpty(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/key/{configKey}")
|
||||||
|
public Mono<ResponseEntity<SysConfig>> getConfigByKey(@PathVariable String configKey) {
|
||||||
|
return configService.findByConfigKey(configKey)
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.defaultIfEmpty(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Mono<ResponseEntity<SysConfig>> createConfig(@RequestBody SysConfig config) {
|
||||||
|
return configService.save(config)
|
||||||
|
.map(c -> ResponseEntity.status(HttpStatus.CREATED).body(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public Mono<ResponseEntity<SysConfig>> updateConfig(@PathVariable Long id, @RequestBody SysConfig config) {
|
||||||
|
return configService.findById(id)
|
||||||
|
.flatMap(existing -> {
|
||||||
|
existing.setConfigName(config.getConfigName());
|
||||||
|
existing.setConfigValue(config.getConfigValue());
|
||||||
|
existing.setConfigType(config.getConfigType());
|
||||||
|
return configService.save(existing);
|
||||||
|
})
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.defaultIfEmpty(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Mono<ResponseEntity<Void>> deleteConfig(@PathVariable Long id) {
|
||||||
|
return configService.deleteById(id)
|
||||||
|
.then(Mono.just(ResponseEntity.noContent().build()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user