61 lines
2.5 KiB
Plaintext
61 lines
2.5 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.GradeMasterDto;
|
|
import com.healthcare.ohctech.entity.GradeMaster;
|
|
import com.healthcare.ohctech.service.impl.GradeMasterServiceImpl;
|
|
import com.healthcare.ohctech.util.PaginationUtil;
|
|
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("/grades")
|
|
public class GradeMasterController {
|
|
|
|
@Autowired
|
|
private GradeMasterServiceImpl gradeMasterServiceImpl;
|
|
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<?> getGradeMasterById(@PathVariable Long id) {
|
|
GradeMaster gradeMaster = gradeMasterServiceImpl.getGradeMasterById(id);
|
|
if (gradeMaster != null) {
|
|
return new ResponseEntity<>(gradeMaster, HttpStatus.OK);
|
|
}
|
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllGradeMasters(@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<GradeMaster> gradeMasterPage = gradeMasterServiceImpl.getAllGradeMasters(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(gradeMasterPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addGradeMaster(@RequestBody GradeMasterDto gradeMasterDto) {
|
|
gradeMasterServiceImpl.addGradeMaster(gradeMasterDto);
|
|
return new ResponseEntity<>("Saved Successfully", HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ResponseEntity<?> updateGradeMaster(@RequestBody GradeMasterDto gradeMasterDto) {
|
|
gradeMasterServiceImpl.updateGradeMaster(gradeMasterDto);
|
|
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<?> deleteGradeMaster(@PathVariable Long id) {
|
|
gradeMasterServiceImpl.deleteGradeMaster(id);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
}
|