77 lines
3.4 KiB
Plaintext
77 lines
3.4 KiB
Plaintext
|
package com.healthcare.ohctech.controller;
|
||
|
|
||
|
import com.healthcare.ohctech.dto.ExaminationFindingsDto;
|
||
|
import com.healthcare.ohctech.entity.ExaminationFindings;
|
||
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
||
|
import com.healthcare.ohctech.service.impl.ExaminationFindingsServiceImpl;
|
||
|
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("/examination-findings")
|
||
|
public class ExaminationFindingsController {
|
||
|
|
||
|
@Autowired
|
||
|
private ExaminationFindingsServiceImpl examinationFindingsServiceImpl;
|
||
|
|
||
|
@Autowired
|
||
|
private AuthServiceImpl authServiceImpl;
|
||
|
|
||
|
@GetMapping("/{id}")
|
||
|
public ResponseEntity<?> getExaminationFindingsById(@PathVariable Long id) {
|
||
|
ExaminationFindings findings = examinationFindingsServiceImpl.getExaminationFindingsById(id);
|
||
|
ExaminationFindingsDto findingsDto = new ExaminationFindingsDto(
|
||
|
findings.getId(),
|
||
|
findings.getExaminationFinding(),
|
||
|
findings.getModifiedBy(),
|
||
|
findings.getLastModified()
|
||
|
);
|
||
|
return new ResponseEntity<>(findingsDto, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@GetMapping
|
||
|
public ResponseEntity<?> getAllExaminationFindings(@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<ExaminationFindings> findingsPage = examinationFindingsServiceImpl.getAllExaminationFindings(pageable);
|
||
|
Page<ExaminationFindingsDto> findingsDtoPage = findingsPage.map(findings -> new ExaminationFindingsDto(
|
||
|
findings.getId(),
|
||
|
findings.getExaminationFinding(),
|
||
|
findings.getModifiedBy(),
|
||
|
findings.getLastModified()
|
||
|
));
|
||
|
Map<String, Object> response = PaginationUtil.getPageResponse(findingsDtoPage);
|
||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@PostMapping
|
||
|
public ResponseEntity<?> addExaminationFindings(@Valid @RequestBody ExaminationFindingsDto findingsDto) {
|
||
|
Long userId = authServiceImpl.getCurrentUserId();
|
||
|
examinationFindingsServiceImpl.addExaminationFindings(findingsDto, userId);
|
||
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||
|
}
|
||
|
|
||
|
@PutMapping("/{id}")
|
||
|
public ResponseEntity<?> updateExaminationFindings(@Valid @RequestBody ExaminationFindingsDto findingsDto) {
|
||
|
Long userId = authServiceImpl.getCurrentUserId();
|
||
|
examinationFindingsServiceImpl.updateExaminationFindings(findingsDto, userId);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@DeleteMapping("/{id}")
|
||
|
public ResponseEntity<?> deleteExaminationFindings(@PathVariable Long id) {
|
||
|
examinationFindingsServiceImpl.deleteExaminationFindings(id);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
}
|