Search in sources :

Example 6 with ApiResponse

use of com.formkiq.lambda.apigateway.ApiResponse in project formkiq-core by formkiq.

the class DocumentTagRequestHandler method delete.

@Override
public ApiRequestHandlerResponse delete(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
    String siteId = authorizer.getSiteId();
    Map<String, String> map = event.getPathParameters();
    String documentId = map.get("documentId");
    String tagKey = map.get("tagKey");
    DocumentService documentService = awsservice.documentService();
    DocumentTag docTag = documentService.findDocumentTag(siteId, documentId, tagKey);
    if (docTag == null) {
        throw new NotFoundException("Tag '" + tagKey + "' not found.");
    }
    documentService.removeTags(siteId, documentId, Arrays.asList(tagKey));
    ApiResponse resp = new ApiMessageResponse("Removed '" + tagKey + "' from document '" + documentId + "'.");
    return new ApiRequestHandlerResponse(SC_OK, resp);
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiMessageResponse(com.formkiq.lambda.apigateway.ApiMessageResponse) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) DocumentService(com.formkiq.stacks.dynamodb.DocumentService) ApiResponse(com.formkiq.lambda.apigateway.ApiResponse)

Example 7 with ApiResponse

use of com.formkiq.lambda.apigateway.ApiResponse in project formkiq-core by formkiq.

the class DocumentTagValueRequestHandler method delete.

@Override
public ApiRequestHandlerResponse delete(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
    String siteId = authorizer.getSiteId();
    Map<String, String> map = event.getPathParameters();
    String documentId = map.get("documentId");
    String tagKey = map.get("tagKey");
    String tagValue = map.get("tagValue");
    DocumentService documentService = awsservice.documentService();
    boolean removed = documentService.removeTag(siteId, documentId, tagKey, tagValue);
    if (!removed) {
        throw new NotFoundException("Tag/Value combination not found.");
    }
    ApiResponse resp = new ApiMessageResponse("Removed Tag from document '" + documentId + "'.");
    return new ApiRequestHandlerResponse(SC_OK, resp);
}
Also used : ApiMessageResponse(com.formkiq.lambda.apigateway.ApiMessageResponse) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) DocumentService(com.formkiq.stacks.dynamodb.DocumentService) ApiResponse(com.formkiq.lambda.apigateway.ApiResponse)

Aggregations

ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)7 ApiResponse (com.formkiq.lambda.apigateway.ApiResponse)7 ApiMessageResponse (com.formkiq.lambda.apigateway.ApiMessageResponse)6 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)6 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)4 BadException (com.formkiq.lambda.apigateway.exception.BadException)3 DocumentService (com.formkiq.stacks.dynamodb.DocumentService)3 Date (java.util.Date)3 S3Client (software.amazon.awssdk.services.s3.S3Client)2 S3ObjectMetadata (com.formkiq.aws.s3.S3ObjectMetadata)1 S3Service (com.formkiq.aws.s3.S3Service)1 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)1 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)1 DocumentItem (com.formkiq.stacks.dynamodb.DocumentItem)1 DocumentTags (com.formkiq.stacks.dynamodb.DocumentTags)1 URL (java.net.URL)1 Duration (java.time.Duration)1 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)1