62 lines
2.4 KiB
Plaintext
62 lines
2.4 KiB
Plaintext
|
package com.healthcare.ohctech.controller;
|
||
|
|
||
|
import com.healthcare.ohctech.dto.ConfigDto;
|
||
|
import com.healthcare.ohctech.entity.Config;
|
||
|
import com.healthcare.ohctech.service.impl.ConfigServiceImpl;
|
||
|
import com.healthcare.ohctech.util.PaginationUtil;
|
||
|
import jakarta.validation.Valid;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.data.domain.Page;
|
||
|
import org.springframework.data.domain.Pageable;
|
||
|
import org.springframework.http.HttpStatus;
|
||
|
import org.springframework.http.ResponseEntity;
|
||
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
||
|
import java.util.Map;
|
||
|
|
||
|
@RestController
|
||
|
@RequestMapping("/configs")
|
||
|
public class ConfigController {
|
||
|
|
||
|
@Autowired
|
||
|
private ConfigServiceImpl configServiceImpl;
|
||
|
|
||
|
@GetMapping("/{configId}")
|
||
|
public ResponseEntity<?> getConfigById(@PathVariable Long configId) {
|
||
|
Config config = configServiceImpl.getConfigById(configId);
|
||
|
if (config != null) {
|
||
|
return new ResponseEntity<>(config, HttpStatus.OK);
|
||
|
}
|
||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||
|
}
|
||
|
|
||
|
@GetMapping
|
||
|
public ResponseEntity<?> getAllConfigs(@RequestParam(required = false) Integer page,
|
||
|
@RequestParam(required = false) Integer size,
|
||
|
@RequestParam(required = false) String sortBy,
|
||
|
@RequestParam(required = false) String sortOrder) {
|
||
|
Pageable pageable = PaginationUtil.getPageableWithDefaults(page, size, sortBy, sortOrder);
|
||
|
Page<Config> configPage = configServiceImpl.getAllConfigs(pageable);
|
||
|
Map<String, Object> response = PaginationUtil.getPageResponse(configPage);
|
||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@PostMapping
|
||
|
public ResponseEntity<?> addConfig(@Valid @RequestBody ConfigDto configDto) {
|
||
|
configServiceImpl.addConfig(configDto);
|
||
|
return new ResponseEntity<>("Saved Successfully", HttpStatus.CREATED);
|
||
|
}
|
||
|
|
||
|
@PutMapping("/{configId}")
|
||
|
public ResponseEntity<?> updateConfig(@Valid @RequestBody ConfigDto configDto) {
|
||
|
configServiceImpl.updateConfig(configDto);
|
||
|
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@DeleteMapping("/{configId}")
|
||
|
public ResponseEntity<?> deleteConfig(@PathVariable Long configId) {
|
||
|
configServiceImpl.deleteConfig(configId);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
}
|