package com.healthcare.ohctech.controller; import com.healthcare.ohctech.dto.ShiftStatusDetailsDto; import com.healthcare.ohctech.entity.ShiftStatusDetails; import com.healthcare.ohctech.service.impl.AuthServiceImpl; import com.healthcare.ohctech.service.impl.ShiftStatusDetailsServiceImpl; 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("/shift-status-details") public class ShiftStatusDetailsController { @Autowired private ShiftStatusDetailsServiceImpl shiftStatusDetailsServiceImpl; @Autowired private AuthServiceImpl authServiceImpl; @GetMapping("/{shiftDetailsId}") public ResponseEntity getShiftStatusDetailsById(@PathVariable Long shiftDetailsId) { ShiftStatusDetails shiftStatusDetails = shiftStatusDetailsServiceImpl.getShiftStatusDetailsById(shiftDetailsId); ShiftStatusDetailsDto shiftStatusDetailsDto = new ShiftStatusDetailsDto( shiftStatusDetails.getId(), shiftStatusDetails.getRecordDate(), shiftStatusDetails.getShiftDetails().getId(), shiftStatusDetails.getStartDateTime(), shiftStatusDetails.getEndDateTime(), shiftStatusDetails.getCurrentStatus(), shiftStatusDetails.getOhcType().getId(), shiftStatusDetails.getModifiedBy(), shiftStatusDetails.getLastModified() ); return new ResponseEntity<>(shiftStatusDetailsDto, HttpStatus.OK); } @GetMapping public ResponseEntity getAllShiftStatusDetails(@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 shiftStatusDetailsPage = shiftStatusDetailsServiceImpl.getAllShiftStatusDetails(pageable); Page shiftStatusDetailsDtoPage = shiftStatusDetailsPage.map(shiftStatusDetails -> new ShiftStatusDetailsDto( shiftStatusDetails.getId(), shiftStatusDetails.getRecordDate(), shiftStatusDetails.getShiftDetails().getId(), shiftStatusDetails.getStartDateTime(), shiftStatusDetails.getEndDateTime(), shiftStatusDetails.getCurrentStatus(), shiftStatusDetails.getOhcType().getId(), shiftStatusDetails.getModifiedBy(), shiftStatusDetails.getLastModified() )); Map response = PaginationUtil.getPageResponse(shiftStatusDetailsDtoPage); return new ResponseEntity<>(response, HttpStatus.OK); } @PostMapping public ResponseEntity addShiftStatusDetails(@Valid @RequestBody ShiftStatusDetailsDto shiftStatusDetailsDto) { Long userId = authServiceImpl.getCurrentUserId(); shiftStatusDetailsServiceImpl.addShiftStatusDetails(shiftStatusDetailsDto, userId); return new ResponseEntity<>(HttpStatus.CREATED); } @PutMapping("/{shiftDetailsId}") public ResponseEntity updateShiftStatusDetails(@Valid @RequestBody ShiftStatusDetailsDto shiftStatusDetailsDto) { Long userId = authServiceImpl.getCurrentUserId(); shiftStatusDetailsServiceImpl.updateShiftStatusDetails(shiftStatusDetailsDto, userId); return new ResponseEntity<>(HttpStatus.OK); } @DeleteMapping("/{shiftDetailsId}") public ResponseEntity deleteShiftStatusDetails(@PathVariable Long shiftDetailsId) { shiftStatusDetailsServiceImpl.deleteShiftStatusDetails(shiftDetailsId); return new ResponseEntity<>(HttpStatus.OK); } }