|
|
|
@ -18,42 +18,50 @@
|
|
|
|
|
*/
|
|
|
|
|
package com.example.Public.Configuration.controller;
|
|
|
|
|
|
|
|
|
|
import com.example.Public.Configuration.dto.DeviceConfigDto;
|
|
|
|
|
import com.example.Public.Configuration.model.DeviceConfig;
|
|
|
|
|
import com.example.Public.Configuration.response.Response;
|
|
|
|
|
import com.example.Public.Configuration.service.impl.DeviceConfigServiceImpl;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
import jakarta.validation.Validation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/device-config")
|
|
|
|
|
@Validated
|
|
|
|
|
public class DeviceConfigController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceConfigServiceImpl deviceConfigService;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
|
|
public ResponseEntity<?> createDeviceConfigProfile(@RequestBody DeviceConfig deviceConfig) {
|
|
|
|
|
DeviceConfig newDeviceConfig = deviceConfigService.getByConfigId(deviceConfig.getConfigId());
|
|
|
|
|
if (newDeviceConfig == null) {
|
|
|
|
|
deviceConfigService.saveConfigProfile(deviceConfig);
|
|
|
|
|
@PostMapping("/")
|
|
|
|
|
public ResponseEntity<?> createDeviceConfigProfile(@Valid @RequestBody DeviceConfigDto deviceConfig) {
|
|
|
|
|
Gson ConfigProfile = new Gson();
|
|
|
|
|
String profileJson = ConfigProfile.toJson(deviceConfig.getConfigProfile());
|
|
|
|
|
DeviceConfig newConfig = new DeviceConfig();
|
|
|
|
|
newConfig.setConfigId(deviceConfig.getConfigId());
|
|
|
|
|
newConfig.setConfigProfile(profileJson);
|
|
|
|
|
newConfig.setConfigContent(deviceConfig.getConfigContent());
|
|
|
|
|
deviceConfigService.saveConfigProfile(newConfig);
|
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.CREATED.value(),
|
|
|
|
|
"Device Config created successfully"), HttpStatus.CREATED);
|
|
|
|
|
}
|
|
|
|
|
return new ResponseEntity<>("Device already exists", HttpStatus.BAD_REQUEST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/configs")
|
|
|
|
|
@GetMapping("/")
|
|
|
|
|
public List<DeviceConfig> getConfigsDevices() {
|
|
|
|
|
|
|
|
|
|
return deviceConfigService.getAllDeviceConfigs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/{configId}/ones")
|
|
|
|
|
@GetMapping("/{configId}")
|
|
|
|
|
public ResponseEntity<?> fetchConfigByConfigId(@PathVariable int configId) {
|
|
|
|
|
DeviceConfig deviceConfig1 = deviceConfigService.getByConfigId(configId);
|
|
|
|
|
DeviceConfig deviceConfig1 = deviceConfigService.getConfigProfileByConfigId(configId);
|
|
|
|
|
if (deviceConfig1 == null) {
|
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|
|
"No Device found for Config ID: +configId"), HttpStatus.NOT_FOUND);
|
|
|
|
@ -63,7 +71,7 @@ public class DeviceConfigController {
|
|
|
|
|
|
|
|
|
|
@PutMapping("/{configId}")
|
|
|
|
|
public ResponseEntity<?> updateDeviceDetails(@PathVariable int configId, @RequestBody DeviceConfig deviceConfig) {
|
|
|
|
|
DeviceConfig updateConfig = deviceConfigService.getByConfigId(configId);
|
|
|
|
|
DeviceConfig updateConfig = deviceConfigService.getConfigProfileByConfigId(configId);
|
|
|
|
|
if (updateConfig == null) {
|
|
|
|
|
deviceConfigService.UpdateConfigDetails(deviceConfig);
|
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|
@ -75,7 +83,7 @@ public class DeviceConfigController {
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{configId}")
|
|
|
|
|
public ResponseEntity<?> deleteConfigConfigId(@PathVariable int configId) {
|
|
|
|
|
DeviceConfig deleteConfig = deviceConfigService.getByConfigId(configId);
|
|
|
|
|
DeviceConfig deleteConfig = deviceConfigService.getConfigProfileByConfigId(configId);
|
|
|
|
|
if (deleteConfig == null) {
|
|
|
|
|
deviceConfigService.deleteConfigProfile(configId);
|
|
|
|
|
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
|
|
|
|