From 10ba5720116c15cf14eb7c7455b81cf70052ae15 Mon Sep 17 00:00:00 2001 From: Vladik-gif Date: Thu, 17 Oct 2024 09:58:05 +0300 Subject: [PATCH] new: for register and RegistrationResponseDto --- .../controller/rest/AuthenticationController.java | 12 +++++++----- .../chat/yourway/service/AuthenticationService.java | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java b/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java index 58dcd4a..d6e5cc7 100644 --- a/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java +++ b/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java @@ -4,6 +4,7 @@ import com.chat.yourway.dto.request.ContactRequestDto; import com.chat.yourway.dto.request.EmailRequestDto; import com.chat.yourway.dto.response.AuthResponseDto; +import com.chat.yourway.dto.response.RegistrationResponseDto; import com.chat.yourway.dto.response.error.ApiErrorResponseDto; import com.chat.yourway.service.AuthenticationService; import io.swagger.v3.oas.annotations.Operation; @@ -40,7 +41,8 @@ public class AuthenticationController { private static final String LOGOUT = "/logout"; @Operation(summary = "Registration a new contact", responses = { - @ApiResponse(responseCode = "201", description = SUCCESSFULLY_REGISTERED), + @ApiResponse(responseCode = "201", description = SUCCESSFULLY_REGISTERED, + content = @Content(schema = @Schema(implementation = RegistrationResponseDto.class))), @ApiResponse(responseCode = "409", description = VALUE_NOT_UNIQUE, content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class))), @ApiResponse(responseCode = "400", description = ERR_SENDING_EMAIL, @@ -48,10 +50,10 @@ public class AuthenticationController { } ) @ResponseStatus(HttpStatus.CREATED) - @PostMapping(path = REGISTER, consumes = APPLICATION_JSON_VALUE) - public void register(@Valid @RequestBody ContactRequestDto request, - @RequestHeader(HttpHeaders.REFERER) String clientHost) { - authService.register(request, clientHost); + @PostMapping(path = REGISTER, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public RegistrationResponseDto register(@Valid @RequestBody ContactRequestDto request, + @RequestHeader(HttpHeaders.REFERER) String clientHost) { + return authService.register(request, clientHost); } @Operation(summary = "Authorization", responses = { diff --git a/src/main/java/com/chat/yourway/service/AuthenticationService.java b/src/main/java/com/chat/yourway/service/AuthenticationService.java index 908486b..dc339b9 100644 --- a/src/main/java/com/chat/yourway/service/AuthenticationService.java +++ b/src/main/java/com/chat/yourway/service/AuthenticationService.java @@ -6,6 +6,7 @@ import com.chat.yourway.dto.request.ContactRequestDto; import com.chat.yourway.dto.request.EmailRequestDto; import com.chat.yourway.dto.response.AuthResponseDto; +import com.chat.yourway.dto.response.RegistrationResponseDto; import com.chat.yourway.exception.InvalidCredentialsException; import com.chat.yourway.exception.InvalidTokenException; import com.chat.yourway.model.token.Token; @@ -38,7 +39,8 @@ public class AuthenticationService { private final JwtService jwtService; @Transactional - public void register(ContactRequestDto contactRequestDto, String clientHost) { + public RegistrationResponseDto register(ContactRequestDto contactRequestDto, String clientHost) { + final var status = RegistrationResponseDto.builder().registerStatus("success full").build(); log.trace("Started registration contact email: {}", contactRequestDto.getEmail()); var contact = contactService.create(contactRequestDto); @@ -46,6 +48,7 @@ public void register(ContactRequestDto contactRequestDto, String clientHost) { log.info("Saved registered contact {} to repository", contact.getEmail()); activateAccountService.sendVerifyEmail(contact, clientHost); + return status; } @Transactional