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"));
}
}
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"));
}
}
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"));
}
}
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"));
}
}
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"));
}
}
Aggregations