use of com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO in project AuthGuard by AuthGuard.
the class CredentialsRoute method addIdentifiers.
public void addIdentifiers(final Context context) {
final String credentialsId = context.pathParam("id");
final UserIdentifiersRequestDTO request = userIdentifiersRequestBodyHandler.getValidated(context);
if (request.getOldIdentifier() != null && request.getIdentifiers().size() != 1) {
throw new RequestValidationException(Collections.singletonList(new Violation("identifier", ViolationType.EXCEEDS_LENGTH_BOUNDARIES)));
}
final List<UserIdentifierBO> identifiers = request.getIdentifiers().stream().map(restMapper::toBO).collect(Collectors.toList());
if (request.getOldIdentifier() != null) {
credentialsService.replaceIdentifier(credentialsId, request.getOldIdentifier(), identifiers.get(0)).map(restMapper::toDTO).ifPresentOrElse(context::json, () -> context.status(404));
} else {
credentialsService.addIdentifiers(credentialsId, identifiers).map(restMapper::toDTO).ifPresentOrElse(context::json, () -> context.status(404));
}
}
use of com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO in project AuthGuard by AuthGuard.
the class CredentialsRoute method removeIdentifiers.
public void removeIdentifiers(final Context context) {
final String credentialsId = context.pathParam("id");
final UserIdentifiersRequestDTO request = userIdentifiersRequestBodyHandler.getValidated(context);
final List<String> identifiers = request.getIdentifiers().stream().map(UserIdentifierDTO::getIdentifier).collect(Collectors.toList());
credentialsService.removeIdentifiers(credentialsId, identifiers).map(restMapper::toDTO).ifPresentOrElse(context::json, () -> context.status(404));
}
Aggregations