Search in sources :

Example 6 with AccountDTO

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

the class AccountsRoute method getByExternalId.

public void getByExternalId(final Context context) {
    final String accountId = context.pathParam("id");
    final Optional<AccountDTO> account = accountsService.getByExternalId(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 7 with AccountDTO

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

the class AccountsRoute method updatePermissions.

public void updatePermissions(final Context context) {
    final String accountId = context.pathParam("id");
    final PermissionsRequestDTO request = permissionsRequestBodyHandler.getValidated(context);
    final List<PermissionBO> permissions = request.getPermissions().stream().map(restMapper::toBO).collect(Collectors.toList());
    final AccountDTO updatedAccount;
    if (request.getAction() == PermissionsRequest.Action.GRANT) {
        updatedAccount = restMapper.toDTO(accountsService.grantPermissions(accountId, permissions));
    } else {
        updatedAccount = restMapper.toDTO(accountsService.revokePermissions(accountId, permissions));
    }
    context.json(updatedAccount);
}
Also used : AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO)

Example 8 with AccountDTO

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

the class AccountsRoute method deactivate.

public void deactivate(final Context context) {
    final String accountId = context.pathParam("id");
    final Optional<AccountDTO> account = accountsService.deactivate(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 9 with AccountDTO

use of com.nexblocks.authguard.api.dto.entities.AccountDTO 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 10 with AccountDTO

use of com.nexblocks.authguard.api.dto.entities.AccountDTO 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)

Aggregations

AccountDTO (com.nexblocks.authguard.api.dto.entities.AccountDTO)11 Error (com.nexblocks.authguard.api.dto.entities.Error)8 Inject (com.google.inject.Inject)1 AuthGuardRoles (com.nexblocks.authguard.api.access.AuthGuardRoles)1 AccountLockDTO (com.nexblocks.authguard.api.dto.entities.AccountLockDTO)1 AppDTO (com.nexblocks.authguard.api.dto.entities.AppDTO)1 com.nexblocks.authguard.api.dto.requests (com.nexblocks.authguard.api.dto.requests)1 CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)1 AccountsApi (com.nexblocks.authguard.api.routes.AccountsApi)1 ActorDomainVerifier (com.nexblocks.authguard.rest.access.ActorDomainVerifier)1 RestMapper (com.nexblocks.authguard.rest.mappers.RestMapper)1 BodyHandler (com.nexblocks.authguard.rest.util.BodyHandler)1 IdempotencyHeader (com.nexblocks.authguard.rest.util.IdempotencyHeader)1 AccountLocksService (com.nexblocks.authguard.service.AccountLocksService)1 AccountsService (com.nexblocks.authguard.service.AccountsService)1 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)1 CredentialsService (com.nexblocks.authguard.service.CredentialsService)1 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)1 ErrorCode (com.nexblocks.authguard.service.exceptions.codes.ErrorCode)1 com.nexblocks.authguard.service.model (com.nexblocks.authguard.service.model)1