2ff5930e86
Co-authored-by: Abed <alrbeei@yahoo.com> Reviewed-on: #21 Reviewed-by: Rui Hu <rui.hu@cleverthis.com> Co-authored-by: Abed Alrahman <abed.alrahman@cleverthis.com> Co-committed-by: Abed Alrahman <abed.alrahman@cleverthis.com>
57 lines
2.4 KiB
Java
57 lines
2.4 KiB
Java
package com.cleverthis.authservice.controller;
|
|
|
|
import com.cleverthis.authservice.dto.RegistrationRequest;
|
|
import com.cleverthis.authservice.service.IdentityManagerService;
|
|
import jakarta.validation.Valid;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
/**
|
|
* REST Controller for handling registration related requests.
|
|
* provider interaction to the IdentityManagerService.
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/users")
|
|
@Slf4j
|
|
public class UserRegistrationController {
|
|
|
|
private final IdentityManagerService identityManagerService;
|
|
|
|
@Autowired
|
|
public UserRegistrationController(IdentityManagerService identityManagerService) {
|
|
this.identityManagerService = identityManagerService;
|
|
}
|
|
|
|
/**
|
|
* Handles new user registration requests. The user will be created with emailVerified set to
|
|
* false. A conceptual verification email would be sent (implementation of email sending is
|
|
* TBD).
|
|
*
|
|
* @param registrationRequest DTO containing user registration details.
|
|
* @return ResponseEntity with 201 Created on success, or an error status.
|
|
*/
|
|
@PostMapping("/register")
|
|
public Mono<ResponseEntity<Void>> registerUser(
|
|
@Valid @RequestBody RegistrationRequest registrationRequest) {
|
|
log.info("Received registration request for email: {}", registrationRequest.getEmail());
|
|
return this.identityManagerService.registerUser(registrationRequest)
|
|
.then(Mono.fromCallable(
|
|
() -> ResponseEntity.status(HttpStatus.CREATED).<Void>build()))
|
|
.doOnError(e -> log.error("User registration failed for email {}: {}",
|
|
registrationRequest.getEmail(), e.getMessage()))
|
|
.onErrorResume(e -> {
|
|
log.error("Registration failed with an unexpected error: {}", e.getMessage());
|
|
return Mono
|
|
.just(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build());
|
|
});
|
|
}
|
|
}
|