65 lines
2.8 KiB
Plaintext
65 lines
2.8 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.RuleConditionDto;
|
|
import com.healthcare.ohctech.entity.RuleCondition;
|
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
|
import com.healthcare.ohctech.service.impl.RuleConditionServiceImpl;
|
|
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.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/rule-conditions")
|
|
public class RuleConditionController {
|
|
|
|
@Autowired
|
|
private RuleConditionServiceImpl ruleConditionServiceImpl;
|
|
|
|
@Autowired
|
|
private AuthServiceImpl authServiceImpl;
|
|
|
|
@GetMapping("/{ruleConditionId}")
|
|
public ResponseEntity<?> getRuleConditionById(@PathVariable Long ruleConditionId) {
|
|
RuleCondition ruleCondition = ruleConditionServiceImpl.getRuleConditionById(ruleConditionId);
|
|
return new ResponseEntity<>(ruleCondition, HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllRuleConditions(@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<RuleCondition> ruleConditionPage = ruleConditionServiceImpl.getAllRuleConditions(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(ruleConditionPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addRuleCondition(@Valid @RequestBody RuleConditionDto ruleConditionDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
ruleConditionServiceImpl.addRuleCondition(ruleConditionDto, userId);
|
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{ruleConditionId}")
|
|
public ResponseEntity<?> updateRuleCondition(@Valid @RequestBody RuleConditionDto ruleConditionDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
ruleConditionServiceImpl.updateRuleCondition(ruleConditionDto, userId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{ruleConditionId}")
|
|
public ResponseEntity<?> deleteRuleCondition(@PathVariable Long ruleConditionId) {
|
|
ruleConditionServiceImpl.deleteRuleCondition(ruleConditionId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
}
|