package com.healthcare.ohctech.controller; import com.healthcare.ohctech.dto.TaskFrequencyMasterDto; import com.healthcare.ohctech.entity.TaskFrequencyMaster; import com.healthcare.ohctech.service.impl.TaskFrequencyMasterServiceImpl; 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("/task-frequencies") public class TaskFrequencyMasterController { @Autowired private TaskFrequencyMasterServiceImpl taskFrequencyMasterServiceImpl; @GetMapping("/{frequencyId}") public ResponseEntity getTaskFrequencyMasterById(@PathVariable Long frequencyId) { TaskFrequencyMaster taskFrequencyMaster = taskFrequencyMasterServiceImpl.getTaskFrequencyMasterById(frequencyId); return new ResponseEntity<>(taskFrequencyMaster, HttpStatus.OK); } @GetMapping public ResponseEntity> getAllTaskFrequencyMasters(@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 taskFrequencyMasterPage = taskFrequencyMasterServiceImpl.getAllTaskFrequencyMasters(pageable); Map response = PaginationUtil.getPageResponse(taskFrequencyMasterPage); return new ResponseEntity<>(response, HttpStatus.OK); } @PostMapping public ResponseEntity addTaskFrequencyMaster(@Valid @RequestBody TaskFrequencyMasterDto taskFrequencyMasterDto) { taskFrequencyMasterServiceImpl.addTaskFrequencyMaster(taskFrequencyMasterDto); return new ResponseEntity<>( HttpStatus.CREATED); } @PutMapping("/{frequencyId}") public ResponseEntity updateTaskFrequencyMaster(@Valid @RequestBody TaskFrequencyMasterDto taskFrequencyMasterDto) { taskFrequencyMasterServiceImpl.updateTaskFrequencyMaster(taskFrequencyMasterDto); return new ResponseEntity<>( HttpStatus.OK); } @DeleteMapping("/{frequencyId}") public ResponseEntity deleteTaskFrequencyMaster(@PathVariable Long frequencyId) { taskFrequencyMasterServiceImpl.deleteTaskFrequencyMaster(frequencyId); return new ResponseEntity<>( HttpStatus.OK); } }