62 lines
2.6 KiB
Plaintext
62 lines
2.6 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.CovidWahQuestionsDto;
|
|
import com.healthcare.ohctech.entity.CovidWahQuestions;
|
|
import com.healthcare.ohctech.service.impl.CovidWahQuestionsServiceImpl;
|
|
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("/covid-wah-questions")
|
|
public class CovidWahQuestionsController {
|
|
|
|
@Autowired
|
|
private CovidWahQuestionsServiceImpl covidWahQuestionsServiceImpl;
|
|
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<?> getQuestionById(@PathVariable Long id) {
|
|
CovidWahQuestions question = covidWahQuestionsServiceImpl.getQuestionById(id);
|
|
if (question != null) {
|
|
return new ResponseEntity<>(question, HttpStatus.OK);
|
|
}
|
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllQuestions(@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<CovidWahQuestions> questionsPage = covidWahQuestionsServiceImpl.getAllQuestions(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(questionsPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addQuestion(@Valid @RequestBody CovidWahQuestionsDto questionDto) {
|
|
covidWahQuestionsServiceImpl.addQuestion(questionDto);
|
|
return new ResponseEntity<>("Saved Successfully", HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public ResponseEntity<?> updateQuestion(@Valid @RequestBody CovidWahQuestionsDto questionDto) {
|
|
covidWahQuestionsServiceImpl.updateQuestion(questionDto);
|
|
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<?> deleteQuestion(@PathVariable Long id) {
|
|
covidWahQuestionsServiceImpl.deleteQuestion(id);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
}
|