68 lines
2.9 KiB
Plaintext
68 lines
2.9 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.DisposalAgencyDto;
|
|
import com.healthcare.ohctech.entity.DisposalAgency;
|
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
|
import com.healthcare.ohctech.service.impl.DisposalAgencyServiceImpl;
|
|
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("/disposal-agencies")
|
|
public class DisposalAgencyController {
|
|
|
|
@Autowired
|
|
private DisposalAgencyServiceImpl disposalAgencyServiceImpl;
|
|
|
|
@Autowired
|
|
private AuthServiceImpl authServiceImpl;
|
|
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<?> getDisposalAgencyById(@PathVariable Long id) {
|
|
DisposalAgency agency = disposalAgencyServiceImpl.getDisposalAgencyById(id);
|
|
if (agency != null) {
|
|
return new ResponseEntity<>(agency, HttpStatus.OK);
|
|
}
|
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllDisposalAgencies(@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<DisposalAgency> agencyPage = disposalAgencyServiceImpl.getAllDisposalAgencies(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(agencyPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addDisposalAgency(@Valid @RequestBody DisposalAgencyDto disposalAgencyDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
disposalAgencyServiceImpl.addDisposalAgency(disposalAgencyDto,userId);
|
|
return new ResponseEntity<>("Saved Successfully", HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ResponseEntity<?> updateDisposalAgency(@Valid @RequestBody DisposalAgencyDto disposalAgencyDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
disposalAgencyServiceImpl.updateDisposalAgency(disposalAgencyDto,userId);
|
|
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<?> deleteDisposalAgency(@PathVariable Long id) {
|
|
disposalAgencyServiceImpl.deleteDisposalAgency(id);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
}
|