42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
package com.stktrk.auth.application;
|
|
|
|
import com.stktrk.auth.domain.account.types.Role;
|
|
import com.stktrk.auth.domain.account.AccountService;
|
|
import jakarta.annotation.Nonnull;
|
|
import jakarta.annotation.Nullable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.sql.SQLException;
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequestMapping("/test")
|
|
public class LocalSignupController {
|
|
|
|
@Nullable
|
|
private final AccountService accountService;
|
|
|
|
public LocalSignupController(@Nullable AccountService accountService) {
|
|
this.accountService = accountService;
|
|
}
|
|
|
|
|
|
@Nonnull
|
|
@PostMapping("/signup")
|
|
public String signUp(@Nonnull @RequestParam String email, @Nonnull @RequestParam String password, @Nonnull @RequestParam List<Role> roles) {
|
|
|
|
|
|
// Register the user
|
|
try {
|
|
accountService.registerUser(email, password, roles);
|
|
} catch (SQLException e) {
|
|
return e.getMessage();
|
|
}
|
|
return "User registered successfully!";
|
|
}
|
|
|
|
}
|