1 | package com.example.skychasemk.controller;
|
---|
2 |
|
---|
3 | import com.example.skychasemk.dto.ApplicationUserDTO;
|
---|
4 | import com.example.skychasemk.dto.ApplicationUserLoginDTO;
|
---|
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 |
|
---|
12 | import java.util.HashMap;
|
---|
13 | import java.util.Map;
|
---|
14 |
|
---|
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 | }
|
---|
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 | }
|
---|
35 | } |
---|