use of io.javalin.http.Context in project AuthGuard by AuthGuard.
the class CredentialsRoute method create.
public void create(final Context context) {
final String idempotentKey = IdempotencyHeader.getKeyOrFail(context);
final CreateCredentialsRequestDTO request = credentialsRequestBodyHandler.getValidated(context);
if (!ActorDomainVerifier.verifyActorDomain(context, request.getDomain())) {
return;
}
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).source(context.ip()).build();
final CredentialsBO credentials = restMapper.toBO(request);
final List<UserIdentifierBO> identifiers = credentials.getIdentifiers().stream().map(identifier -> identifier.withDomain(request.getDomain())).collect(Collectors.toList());
final Optional<CredentialsDTO> created = Optional.of(credentials.withIdentifiers(identifiers)).map(credentialsBO -> credentialsService.create(credentialsBO, requestContext)).map(restMapper::toDTO);
if (created.isPresent()) {
context.status(201).json(created.get());
} else {
context.status(400).json(new Error("400", "Failed to create credentials"));
}
}
Aggregations