76 lines
3.6 KiB
Plaintext
76 lines
3.6 KiB
Plaintext
|
package com.healthcare.ohctech.controller;
|
||
|
|
||
|
import com.healthcare.ohctech.dto.PatientDailyExerciseDto;
|
||
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
||
|
import com.healthcare.ohctech.service.impl.PatientDailyExerciseServiceImpl;
|
||
|
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 jakarta.validation.Valid;
|
||
|
|
||
|
import java.time.LocalDate;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
|
||
|
@RestController
|
||
|
@RequestMapping("/patient-daily-exercises")
|
||
|
public class PatientDailyExerciseController {
|
||
|
|
||
|
@Autowired
|
||
|
private PatientDailyExerciseServiceImpl patientDailyExerciseServiceImpl;
|
||
|
|
||
|
@Autowired
|
||
|
private AuthServiceImpl authServiceImpl;
|
||
|
|
||
|
@GetMapping("/empId/{empId}")
|
||
|
public ResponseEntity<?> getPatientExercisesByEmpId(@PathVariable Long empId) {
|
||
|
List<PatientDailyExerciseDto> dtos = patientDailyExerciseServiceImpl.getPatientExercisesByEmpId(empId);
|
||
|
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@GetMapping("/{empId}")
|
||
|
public ResponseEntity<?> getPatientExerciseByEmpIdAndDate(@PathVariable Long empId,
|
||
|
@RequestParam("date") LocalDate date) {
|
||
|
PatientDailyExerciseDto dto = patientDailyExerciseServiceImpl.getPatientExerciseByEmpIdAndDate(empId, date);
|
||
|
return dto != null ? ResponseEntity.ok(dto) : ResponseEntity.notFound().build();
|
||
|
}
|
||
|
|
||
|
@GetMapping
|
||
|
public ResponseEntity<?> getAllPatientExercises(@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);
|
||
|
List<PatientDailyExerciseDto> groupedExercises = patientDailyExerciseServiceImpl.getAllPatientExercises();
|
||
|
Page<PatientDailyExerciseDto> exerciseDtoPage = PaginationUtil.getPageFromList(groupedExercises, pageable);
|
||
|
|
||
|
Map<String, Object> response = PaginationUtil.getPageResponse(exerciseDtoPage);
|
||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@PostMapping
|
||
|
public ResponseEntity<?> addPatientExercise(@Valid @RequestBody PatientDailyExerciseDto patientDailyExerciseDto) {
|
||
|
Long userId = authServiceImpl.getCurrentUserId();
|
||
|
patientDailyExerciseServiceImpl.addPatientExercise(patientDailyExerciseDto, userId);
|
||
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||
|
}
|
||
|
|
||
|
@PutMapping("/{empId}")
|
||
|
public ResponseEntity<?> updatePatientExercise(@PathVariable Long empId,
|
||
|
@Valid @RequestBody PatientDailyExerciseDto patientDailyExerciseDto) {
|
||
|
Long userId = authServiceImpl.getCurrentUserId();
|
||
|
patientDailyExerciseServiceImpl.updatePatientExercise(empId, patientDailyExerciseDto, userId);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
|
||
|
@DeleteMapping("/{id}")
|
||
|
public ResponseEntity<?> deletePatientExercise(@PathVariable Long id, @RequestParam("date") LocalDate date) {
|
||
|
patientDailyExerciseServiceImpl.deletePatientExercise(id,date);
|
||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||
|
}
|
||
|
}
|