package com.healthcare.ohctech.controller; import com.healthcare.ohctech.dto.AddFilterMasterDto; import com.healthcare.ohctech.entity.AddFilterMaster; import com.healthcare.ohctech.service.impl.AddFilterMasterServiceImpl; 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("/filters") public class AddFilterMasterController { @Autowired private AddFilterMasterServiceImpl addFilterMasterServiceImpl; @GetMapping("/{filterId}") public ResponseEntity getFilterById(@PathVariable Long filterId) { AddFilterMaster filter = addFilterMasterServiceImpl.getFilterById(filterId); if (filter != null) { return new ResponseEntity<>(filter, HttpStatus.OK); } return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @GetMapping public ResponseEntity getAllFilters(@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 filterPage = addFilterMasterServiceImpl.getAllFilters(pageable); Map response = PaginationUtil.getPageResponse(filterPage); return new ResponseEntity<>(response, HttpStatus.OK); } @PostMapping public ResponseEntity addFilter(@Valid @RequestBody AddFilterMasterDto addFilterMasterDto) { addFilterMasterServiceImpl.addFilter(addFilterMasterDto); return new ResponseEntity<>("Saved Successfully", HttpStatus.CREATED); } @PutMapping("/{filterId}") public ResponseEntity updateFilter(@Valid @RequestBody AddFilterMasterDto addFilterMasterDto) { addFilterMasterServiceImpl.updateFilter(addFilterMasterDto); return new ResponseEntity<>("Updated Successfully", HttpStatus.OK); } @DeleteMapping("/{filterId}") public ResponseEntity deleteFilter(@PathVariable Long filterId) { addFilterMasterServiceImpl.deleteFilter(filterId); return new ResponseEntity<>(HttpStatus.OK); } }