source: backend/src/main/java/com/finki/icare/controller/ConsultationController.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: 3.4 KB
RevLine 
[700e2f9]1package com.finki.icare.controller;
2
3import com.finki.icare.dto.ConsultationDTO;
4import com.finki.icare.dto.CreateConsultationRequest;
5import com.finki.icare.dto.UpdateConsultationRequest;
6import com.finki.icare.service.ConsultationService;
7import com.finki.icare.utils.AuthUtils;
8import lombok.RequiredArgsConstructor;
9import org.springframework.http.HttpStatus;
10import org.springframework.http.ResponseEntity;
11import org.springframework.security.core.Authentication;
12import org.springframework.web.bind.annotation.*;
13
14import java.util.List;
15
16@RestController
17@RequestMapping("/api/consultations")
18@CrossOrigin(origins = "http://localhost:3000")
19@RequiredArgsConstructor
20public class ConsultationController {
21
22 private final ConsultationService consultationService;
23
24 @GetMapping("/therapist/{therapistId}")
25 public ResponseEntity<List<ConsultationDTO>> getTherapistConsultations(
26 @PathVariable Integer therapistId,
27 Authentication authentication
28 ) {
29 Integer currentUserId = AuthUtils.getUserId(authentication);
30 String userType = AuthUtils.getUserType(authentication);
31
32 List<ConsultationDTO> consultations = consultationService.getTherapistConsultations(
33 therapistId, currentUserId, userType
34 );
35 return ResponseEntity.ok(consultations);
36 }
37
38 @GetMapping("/patient/{patientId}")
39 public ResponseEntity<List<ConsultationDTO>> getPatientConsultations(
40 @PathVariable Integer patientId,
41 Authentication authentication
42 ) {
43 Integer currentUserId = AuthUtils.getUserId(authentication);
44 String userType = AuthUtils.getUserType(authentication);
45
46 List<ConsultationDTO> consultations = consultationService.getPatientConsultations(
47 patientId, currentUserId, userType
48 );
49 return ResponseEntity.ok(consultations);
50 }
51
52 @PostMapping
53 public ResponseEntity<ConsultationDTO> createConsultation(
54 @RequestBody CreateConsultationRequest request,
55 Authentication authentication
56 ) {
57 Integer currentUserId = AuthUtils.getUserId(authentication);
58 String userType = AuthUtils.getUserType(authentication);
59
60 ConsultationDTO consultation = consultationService.createConsultation(
61 request, currentUserId, userType
62 );
63 return ResponseEntity.status(HttpStatus.CREATED).body(consultation);
64 }
65
66 @PutMapping("/{consultationId}")
67 public ResponseEntity<ConsultationDTO> updateConsultation(
68 @PathVariable Integer consultationId,
69 @RequestBody UpdateConsultationRequest request,
70 Authentication authentication
71 ) {
72 Integer currentUserId = AuthUtils.getUserId(authentication);
73 String userType = AuthUtils.getUserType(authentication);
74
75 ConsultationDTO consultation = consultationService.updateConsultation(
76 consultationId, request, currentUserId, userType
77 );
78 return ResponseEntity.ok(consultation);
79 }
80
81 @DeleteMapping("/{consultationId}")
82 public ResponseEntity<Void> deleteConsultation(
83 @PathVariable Integer consultationId,
84 Authentication authentication
85 ) {
86 Integer currentUserId = AuthUtils.getUserId(authentication);
87 String userType = AuthUtils.getUserType(authentication);
88
89 consultationService.deleteConsultation(consultationId, currentUserId, userType);
90 return ResponseEntity.noContent().build();
91 }
92}
Note: See TracBrowser for help on using the repository browser.