59 lines
2.5 KiB
Plaintext
59 lines
2.5 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.AbnormalityDto;
|
|
import com.healthcare.ohctech.entity.Abnormality;
|
|
import com.healthcare.ohctech.service.impl.AbnormalityServiceImpl;
|
|
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("/abnormalities")
|
|
public class AbnormalityController {
|
|
|
|
@Autowired
|
|
private AbnormalityServiceImpl abnormalityServiceImpl;
|
|
|
|
@GetMapping("/{abnormalityId}")
|
|
public ResponseEntity<?> getAbnormalityById(@PathVariable Long abnormalityId) {
|
|
Abnormality abnormality = abnormalityServiceImpl.getAbnormalityById(abnormalityId);
|
|
return new ResponseEntity<>(abnormality, HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllAbnormalities(@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<Abnormality> abnormalityPage = abnormalityServiceImpl.getAllAbnormalities(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(abnormalityPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addAbnormality(@Valid @RequestBody AbnormalityDto abnormalityDto) {
|
|
abnormalityServiceImpl.addAbnormality(abnormalityDto);
|
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{abnormalityId}")
|
|
public ResponseEntity<?> updateAbnormality(@Valid @RequestBody AbnormalityDto abnormalityDto) {
|
|
abnormalityServiceImpl.updateAbnormality(abnormalityDto);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{abnormalityId}")
|
|
public ResponseEntity<?> deleteAbnormality(@PathVariable Long abnormalityId) {
|
|
abnormalityServiceImpl.deleteAbnormality(abnormalityId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
}
|