Last change
on this file was 9868304, checked in by ste08 <sjovanoska@…>, 4 months ago |
Frontend + some backend changes
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[57e58a3] | 1 | package com.example.skychasemk.controller;
|
---|
| 2 |
|
---|
| 3 | import com.example.skychasemk.dto.ApplicationUserDTO;
|
---|
[9868304] | 4 | import com.example.skychasemk.dto.ApplicationUserLoginDTO;
|
---|
[57e58a3] | 5 | import com.example.skychasemk.model.ApplicationUser;
|
---|
| 6 | import com.example.skychasemk.services.ApplicationUserService;
|
---|
| 7 | import jakarta.validation.Valid;
|
---|
| 8 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 9 | import org.springframework.http.ResponseEntity;
|
---|
| 10 | import org.springframework.web.bind.annotation.*;
|
---|
| 11 |
|
---|
[9868304] | 12 | import java.util.HashMap;
|
---|
| 13 | import java.util.Map;
|
---|
| 14 |
|
---|
[57e58a3] | 15 | @RestController
|
---|
| 16 | @RequestMapping("/api/user")
|
---|
| 17 | @CrossOrigin(origins = "http://localhost:5173") // Allow frontend access
|
---|
| 18 | public class ApplicationUserController {
|
---|
| 19 |
|
---|
| 20 | @Autowired
|
---|
| 21 | private ApplicationUserService userService;
|
---|
| 22 |
|
---|
| 23 | @PostMapping("/signup")
|
---|
| 24 | public ResponseEntity<String> registerUser(@Valid @RequestBody ApplicationUserDTO userDTO) {
|
---|
| 25 | ApplicationUser savedUser = userService.registerUser(userDTO);
|
---|
| 26 | return ResponseEntity.ok("User saved successfully");
|
---|
| 27 | }
|
---|
[9868304] | 28 | @PostMapping("/login")
|
---|
| 29 | public ResponseEntity<Map<String,Long>> loginUser(@Valid @RequestBody ApplicationUserLoginDTO userDTO) {
|
---|
| 30 | ApplicationUser loginUser = userService.findByEmail(userDTO);
|
---|
| 31 | Map<String,Long> response = new HashMap<>();
|
---|
| 32 | response.put("userId",loginUser.getUserid());
|
---|
| 33 | return ResponseEntity.ok(response);
|
---|
| 34 | }
|
---|
[57e58a3] | 35 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.