ohctechv3/.svn/pristine/75/753c90973ea8054810df0ecebca11a8210454c8b.svn-base
2024-10-28 15:03:36 +05:30

65 lines
2.7 KiB
Plaintext

package com.healthcare.ohctech.controller;
import com.healthcare.ohctech.dto.InjuryTypeDto;
import com.healthcare.ohctech.entity.InjuryType;
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
import com.healthcare.ohctech.service.impl.InjuryTypeServiceImpl;
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("/injury-types")
public class InjuryTypeController {
@Autowired
private InjuryTypeServiceImpl injuryTypeServiceImpl;
@Autowired
private AuthServiceImpl authServiceImpl;
@GetMapping("/{injuryTypeId}")
public ResponseEntity<?> getInjuryTypeById(@PathVariable Long injuryTypeId) {
InjuryType injuryType = injuryTypeServiceImpl.getInjuryTypeById(injuryTypeId);
return new ResponseEntity<>(injuryType, HttpStatus.OK);
}
@GetMapping
public ResponseEntity<?> getAllInjuryTypes(@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<InjuryType> injuryTypePage = injuryTypeServiceImpl.getAllInjuryTypes(pageable);
Map<String, Object> response = PaginationUtil.getPageResponse(injuryTypePage);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@PostMapping
public ResponseEntity<?> addInjuryType(@Valid @RequestBody InjuryTypeDto injuryTypeDto) {
Long userId = authServiceImpl.getCurrentUserId();
injuryTypeServiceImpl.addInjuryType(injuryTypeDto,userId);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping("/{injuryTypeId}")
public ResponseEntity<?> updateInjuryType(@Valid @RequestBody InjuryTypeDto injuryTypeDto) {
Long userId = authServiceImpl.getCurrentUserId();
injuryTypeServiceImpl.updateInjuryType(injuryTypeDto,userId);
return new ResponseEntity<>(HttpStatus.OK);
}
@DeleteMapping("/{injuryTypeId}")
public ResponseEntity<?> deleteInjuryType(@PathVariable Long injuryTypeId) {
injuryTypeServiceImpl.deleteInjuryType(injuryTypeId);
return new ResponseEntity<>(HttpStatus.OK);
}
}