source: backend/src/main/java/com/finki/icare/controller/ConsultationSlotController.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: 2.2 KB
RevLine 
[700e2f9]1package com.finki.icare.controller;
2
3import com.finki.icare.dto.AddSlotRequest;
4import com.finki.icare.dto.ConsultationSlotsDTO;
5import com.finki.icare.service.ConsultationSlotService;
6import com.finki.icare.utils.AuthUtils;
7import lombok.RequiredArgsConstructor;
8import org.springframework.format.annotation.DateTimeFormat;
9import org.springframework.http.ResponseEntity;
10import org.springframework.security.core.Authentication;
11import org.springframework.web.bind.annotation.*;
12
13import java.time.LocalDate;
14
15@RestController
16@RequestMapping("/api/consultation-slots")
17@CrossOrigin(origins = "http://localhost:3000")
18@RequiredArgsConstructor
19public class ConsultationSlotController {
20
21 private final ConsultationSlotService consultationSlotService;
22
23 @GetMapping("/{therapistId}")
24 public ResponseEntity<ConsultationSlotsDTO> getSlots(
25 @PathVariable Integer therapistId,
26 Authentication authentication
27 ) {
28 String userType = AuthUtils.getUserType(authentication);
29 ConsultationSlotsDTO slots = consultationSlotService.getTherapistSlots(therapistId, userType);
30 return ResponseEntity.ok(slots);
31 }
32
33 @PostMapping("/{therapistId}")
34 public ResponseEntity<ConsultationSlotsDTO> addSlot(
35 @PathVariable Integer therapistId,
36 @RequestBody AddSlotRequest request,
37 Authentication authentication
38 ) {
39 Integer currentUserId = AuthUtils.getUserId(authentication);
40 String userType = AuthUtils.getUserType(authentication);
41 ConsultationSlotsDTO slots = consultationSlotService.addSlot(therapistId, request, currentUserId, userType);
42 return ResponseEntity.ok(slots);
43 }
44
45 @DeleteMapping("/{therapistId}/{date}")
46 public ResponseEntity<ConsultationSlotsDTO> removeSlot(
47 @PathVariable Integer therapistId,
48 @PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
49 Authentication authentication
50 ) {
51 Integer currentUserId = AuthUtils.getUserId(authentication);
52 String userType = AuthUtils.getUserType(authentication);
53 ConsultationSlotsDTO slots = consultationSlotService.removeSlot(therapistId, date, currentUserId, userType);
54 return ResponseEntity.ok(slots);
55 }
56}
57
Note: See TracBrowser for help on using the repository browser.