Skip to content

Commit

Permalink
new: for register and RegistrationResponseDto
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladik-gif committed Oct 17, 2024
1 parent 8eca381 commit 10ba572
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,18 +41,19 @@ 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,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
}
)
@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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,14 +39,16 @@ 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);

log.info("Saved registered contact {} to repository", contact.getEmail());

activateAccountService.sendVerifyEmail(contact, clientHost);
return status;
}

@Transactional
Expand Down

0 comments on commit 10ba572

Please sign in to comment.