62 lines
2.6 KiB
Plaintext
62 lines
2.6 KiB
Plaintext
|
package com.healthcare.ohctech.controller;
|
||
|
|
||
|
import com.healthcare.ohctech.dto.HealthRiskDto;
|
||
|
import com.healthcare.ohctech.entity.HealthRisk;
|
||
|
import com.healthcare.ohctech.service.impl.HealthRiskServiceImpl;
|
||
|
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("/health-risks")
|
||
|
public class HealthRiskController {
|
||
|
|
||
|
@Autowired
|
||
|
private HealthRiskServiceImpl healthRiskServiceImpl;
|
||
|
|
||
|
@GetMapping("/{healthRiskId}")
|
||
|
public ResponseEntity<?> getHealthRiskById(@PathVariable Long healthRiskId) {
|
||
|
HealthRisk healthRisk = healthRiskServiceImpl.getHealthRiskById(healthRiskId);
|
||
|
if (healthRisk != null) {
|
||
|
return new ResponseEntity<>(healthRisk, HttpStatus.OK);
|
||
|
}
|
||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||
|
}
|
||
|
|
||
|
@GetMapping
|
||
|
public ResponseEntity<?> getAllHealthRisks(@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<HealthRisk> healthRiskPage = healthRiskServiceImpl.getAllHealthRisks(pageable);
|
||
|
Map<String, Object> response = PaginationUtil.getPageResponse(healthRiskPage);
|
||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@PostMapping
|
||
|
public ResponseEntity<?> addHealthRisk(@Valid @RequestBody HealthRiskDto healthRiskDto) {
|
||
|
healthRiskServiceImpl.addHealthRisk(healthRiskDto);
|
||
|
return new ResponseEntity<>("Saved Successfully", HttpStatus.CREATED);
|
||
|
}
|
||
|
|
||
|
@PutMapping("/{healthRiskId}")
|
||
|
public ResponseEntity<?> updateHealthRisk(@Valid @RequestBody HealthRiskDto healthRiskDto) {
|
||
|
healthRiskServiceImpl.updateHealthRisk(healthRiskDto);
|
||
|
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@DeleteMapping("/{healthRiskId}")
|
||
|
public ResponseEntity<?> deleteHealthRisk(@PathVariable Long healthRiskId) {
|
||
|
healthRiskServiceImpl.deleteHealthRisk(healthRiskId);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
}
|