| [700e2f9] | 1 | package com.finki.icare.controller;
|
|---|
| 2 |
|
|---|
| 3 | import com.finki.icare.dto.LoginRequest;
|
|---|
| 4 | import com.finki.icare.dto.LoginResponse;
|
|---|
| 5 | import com.finki.icare.dto.RegisterPatientRequest;
|
|---|
| 6 | import com.finki.icare.dto.RegisterTherapistRequest;
|
|---|
| 7 | import com.finki.icare.service.AuthService;
|
|---|
| 8 | import org.springframework.http.HttpStatus;
|
|---|
| 9 | import org.springframework.http.ResponseEntity;
|
|---|
| 10 | import org.springframework.web.bind.annotation.*;
|
|---|
| 11 |
|
|---|
| 12 | @RestController
|
|---|
| 13 | @RequestMapping("/api/auth")
|
|---|
| 14 | @CrossOrigin(origins = "http://localhost:3000")
|
|---|
| 15 | public class AuthController {
|
|---|
| 16 |
|
|---|
| 17 | private final AuthService authService;
|
|---|
| 18 |
|
|---|
| 19 | public AuthController(AuthService authService) {
|
|---|
| 20 | this.authService = authService;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | @PostMapping("/login")
|
|---|
| 24 | public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest request) {
|
|---|
| 25 | LoginResponse response = authService.login(request);
|
|---|
| 26 | return ResponseEntity.ok(response);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | @PostMapping("/register/patient")
|
|---|
| 30 | public ResponseEntity<LoginResponse> registerPatient(@RequestBody RegisterPatientRequest request) {
|
|---|
| 31 | LoginResponse response = authService.registerPatient(request);
|
|---|
| 32 | return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | @PostMapping("/register/therapist")
|
|---|
| 36 | public ResponseEntity<LoginResponse> registerTherapist(@RequestBody RegisterTherapistRequest request) {
|
|---|
| 37 | LoginResponse response = authService.registerTherapist(request);
|
|---|
| 38 | return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|