62 lines
2.6 KiB
Plaintext
62 lines
2.6 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.MedicineFormDto;
|
|
import com.healthcare.ohctech.entity.MedicineForm;
|
|
import com.healthcare.ohctech.service.impl.MedicineFormServiceImpl;
|
|
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("/medicine-forms")
|
|
public class MedicineFormController {
|
|
|
|
@Autowired
|
|
private MedicineFormServiceImpl medicineFormServiceImpl;
|
|
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<?> getMedicineFormById(@PathVariable Long id) {
|
|
MedicineForm medicineForm = medicineFormServiceImpl.getMedicineFormById(id);
|
|
if (medicineForm != null) {
|
|
return new ResponseEntity<>(medicineForm, HttpStatus.OK);
|
|
}
|
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllMedicineForms(@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<MedicineForm> medicineFormPage = medicineFormServiceImpl.getAllMedicineForms(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(medicineFormPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addMedicineForm(@Valid @RequestBody MedicineFormDto medicineFormDto) {
|
|
medicineFormServiceImpl.addMedicineForm(medicineFormDto);
|
|
return new ResponseEntity<>("Saved Successfully", HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ResponseEntity<?> updateMedicineForm(@Valid @RequestBody MedicineFormDto medicineFormDto) {
|
|
medicineFormServiceImpl.updateMedicineForm(medicineFormDto);
|
|
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<?> deleteMedicineForm(@PathVariable Long id) {
|
|
medicineFormServiceImpl.deleteMedicineForm(id);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
}
|