source: backend/src/main/java/com/finki/icare/controller/PatientController.java

main
Last change on this file was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago

Init

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[700e2f9]1package com.finki.icare.controller;
2
3import com.finki.icare.dto.PatientDTO;
4import com.finki.icare.service.PatientService;
5import com.finki.icare.utils.AuthUtils;
6import org.springframework.http.ResponseEntity;
7import org.springframework.security.core.Authentication;
8import org.springframework.web.bind.annotation.*;
9
10import java.util.List;
11
12@RestController
13@RequestMapping("/api/patients")
14@CrossOrigin(origins = "http://localhost:3000")
15public class PatientController {
16
17 private final PatientService patientService;
18
19 public PatientController(PatientService patientService) {
20 this.patientService = patientService;
21 }
22
23 @PutMapping("/therapist/{therapistId}")
24 public ResponseEntity<Void> setTherapist(
25 @PathVariable Integer therapistId,
26 Authentication authentication) {
27 Integer patientId = AuthUtils.getUserId(authentication);
28 patientService.setTherapist(patientId, therapistId);
29 return ResponseEntity.noContent().build();
30 }
31
32 @DeleteMapping("/therapist")
33 public ResponseEntity<Void> removeTherapist(Authentication authentication) {
34 Integer patientId = AuthUtils.getUserId(authentication);
35 patientService.removeTherapist(patientId);
36 return ResponseEntity.noContent().build();
37 }
38
39 @GetMapping("/therapist")
40 public ResponseEntity<Integer> getCurrentTherapist(Authentication authentication) {
41 Integer patientId = AuthUtils.getUserId(authentication);
42 Integer therapistId = patientService.getCurrentTherapistId(patientId);
43 if (therapistId == null) {
44 return ResponseEntity.noContent().build();
45 }
46 return ResponseEntity.ok(therapistId);
47 }
48
49 @GetMapping
50 public ResponseEntity<List<PatientDTO>> getAllPatients() {
51 List<PatientDTO> patients = patientService.getAllPatients();
52 return ResponseEntity.ok(patients);
53 }
54}
Note: See TracBrowser for help on using the repository browser.