64 lines
2.5 KiB
Plaintext
64 lines
2.5 KiB
Plaintext
|
package com.healthcare.ohctech.controller;
|
||
|
|
||
|
import com.healthcare.ohctech.dto.DutyMasterDto;
|
||
|
import com.healthcare.ohctech.entity.DutyMaster;
|
||
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
||
|
import com.healthcare.ohctech.service.impl.DutyMasterServiceImpl;
|
||
|
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("/duties")
|
||
|
public class DutyMasterController {
|
||
|
|
||
|
@Autowired
|
||
|
private DutyMasterServiceImpl dutyMasterServiceImpl;
|
||
|
|
||
|
@Autowired
|
||
|
private AuthServiceImpl authServiceImpl;
|
||
|
|
||
|
@GetMapping("/{dutyId}")
|
||
|
public ResponseEntity<?> getDutyById(@PathVariable Long dutyId) {
|
||
|
DutyMaster dutyMaster = dutyMasterServiceImpl.getDutyById(dutyId);
|
||
|
return new ResponseEntity<>(dutyMaster, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@GetMapping
|
||
|
public ResponseEntity<?> getAllDuties(@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<DutyMaster> dutyMasterPage = dutyMasterServiceImpl.getAllDuties(pageable);
|
||
|
Map<String, Object> response = PaginationUtil.getPageResponse(dutyMasterPage);
|
||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@PostMapping
|
||
|
public ResponseEntity<?> addDuty(@RequestBody DutyMasterDto dutyMasterDto) {
|
||
|
Long userId = authServiceImpl.getCurrentUserId();
|
||
|
dutyMasterServiceImpl.addDuty(dutyMasterDto, userId);
|
||
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||
|
}
|
||
|
|
||
|
@PutMapping("/{dutyId}")
|
||
|
public ResponseEntity<?> updateDuty(@RequestBody DutyMasterDto dutyMasterDto) {
|
||
|
Long userId = authServiceImpl.getCurrentUserId();
|
||
|
dutyMasterServiceImpl.updateDuty(dutyMasterDto, userId);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@DeleteMapping("/{dutyId}")
|
||
|
public ResponseEntity<?> deleteDuty(@PathVariable Long dutyId) {
|
||
|
dutyMasterServiceImpl.deleteDuty(dutyId);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
}
|