Search in sources :

Example 16 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AccountsRoute method patchAccount.

@Override
public void patchAccount(final Context context) {
    final String accountId = context.pathParam("id");
    final UpdateAccountRequestDTO request = updateAccountRequestBodyHandler.getValidated(context);
    final Optional<AccountDTO> account = accountsService.patch(accountId, restMapper.toBO(request)).map(restMapper::toDTO);
    if (account.isPresent()) {
        context.status(200).json(account.get());
    } else {
        context.status(404).json(new Error(ErrorCode.ACCOUNT_DOES_NOT_EXIST.getCode(), "Account not found"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO)

Example 17 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AccountsRoute method getByIdentifier.

@Override
public void getByIdentifier(final Context context) {
    final String identifier = context.pathParam("identifier");
    final String domain = context.pathParam("domain");
    final Optional<AccountBO> account = credentialsService.getByUsername(identifier, domain).map(CredentialsBO::getAccountId).filter(Objects::nonNull).flatMap(accountsService::getById);
    if (account.isPresent()) {
        context.status(200).json(account.get());
    } else {
        context.status(404).json(new Error(ErrorCode.ACCOUNT_DOES_NOT_EXIST.getCode(), "Account not found"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 18 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AccountsRoute method activate.

public void activate(final Context context) {
    final String accountId = context.pathParam("id");
    final Optional<AccountDTO> account = accountsService.activate(accountId).map(restMapper::toDTO);
    if (account.isPresent()) {
        context.status(200).json(account.get());
    } else {
        context.status(404).json(new Error("404", "No account with ID " + accountId + " exists"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO)

Example 19 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AccountsRoute method deleteAccount.

public void deleteAccount(final Context context) {
    final String accountId = context.pathParam("id");
    final Optional<AccountDTO> account = accountsService.delete(accountId).map(restMapper::toDTO);
    if (account.isPresent()) {
        context.status(200).json(account.get());
    } else {
        context.status(404).json(new Error(ErrorCode.ACCOUNT_DOES_NOT_EXIST.getCode(), "Account not found"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO)

Example 20 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class ApplicationsRoute method create.

public void create(final Context context) {
    final String idempotentKey = IdempotencyHeader.getKeyOrFail(context);
    final CreateAppRequestDTO request = appRequestRequestBodyHandler.getValidated(context);
    final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).source(context.ip()).build();
    final Optional<Object> created = Optional.of(restMapper.toBO(request)).map(appBO -> applicationsService.create(appBO, requestContext)).map(restMapper::toDTO);
    if (created.isPresent()) {
        context.status(201).json(created.get());
    } else {
        context.status(400).json(new Error("400", "Failed to create application"));
    }
}
Also used : ApiKeysService(com.nexblocks.authguard.service.ApiKeysService) AppDTO(com.nexblocks.authguard.api.dto.entities.AppDTO) ApplicationsApi(com.nexblocks.authguard.api.routes.ApplicationsApi) ApiKeyDTO(com.nexblocks.authguard.api.dto.entities.ApiKeyDTO) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) Inject(com.google.inject.Inject) Collectors(java.util.stream.Collectors) List(java.util.List) BodyHandler(com.nexblocks.authguard.rest.util.BodyHandler) Error(com.nexblocks.authguard.api.dto.entities.Error) RestJsonMapper(com.nexblocks.authguard.rest.mappers.RestJsonMapper) RestMapper(com.nexblocks.authguard.rest.mappers.RestMapper) Context(io.javalin.http.Context) Optional(java.util.Optional) CreateAppRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO) IdempotencyHeader(com.nexblocks.authguard.rest.util.IdempotencyHeader) ApplicationsService(com.nexblocks.authguard.service.ApplicationsService) CreateAppRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Aggregations

Error (com.nexblocks.authguard.api.dto.entities.Error)31 AccountDTO (com.nexblocks.authguard.api.dto.entities.AccountDTO)9 RequestValidationError (com.nexblocks.authguard.api.dto.entities.RequestValidationError)7 Inject (com.google.inject.Inject)4 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)4 RestMapper (com.nexblocks.authguard.rest.mappers.RestMapper)4 BodyHandler (com.nexblocks.authguard.rest.util.BodyHandler)4 IdempotencyHeader (com.nexblocks.authguard.rest.util.IdempotencyHeader)4 Context (io.javalin.http.Context)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 AuthGuardRoles (com.nexblocks.authguard.api.access.AuthGuardRoles)3 ApiKeyDTO (com.nexblocks.authguard.api.dto.entities.ApiKeyDTO)3 AppDTO (com.nexblocks.authguard.api.dto.entities.AppDTO)3 ActorDomainVerifier (com.nexblocks.authguard.rest.access.ActorDomainVerifier)3 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)3 CredentialsService (com.nexblocks.authguard.service.CredentialsService)3 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)3 com.nexblocks.authguard.service.model (com.nexblocks.authguard.service.model)3