Skip to content

Commit

Permalink
#100 - Add DELETE /documents/{documentId}/versions/{versionKey}
Browse files Browse the repository at this point in the history
  • Loading branch information
formkiqMike committed Feb 1, 2023
1 parent babbde6 commit 24481ee
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.formkiq.stacks.api.handler.DocumentTagRequestHandler;
import com.formkiq.stacks.api.handler.DocumentTagValueRequestHandler;
import com.formkiq.stacks.api.handler.DocumentTagsRequestHandler;
import com.formkiq.stacks.api.handler.DocumentVersionsKeyRequestHandler;
import com.formkiq.stacks.api.handler.DocumentVersionsRequestHandler;
import com.formkiq.stacks.api.handler.DocumentsActionsRequestHandler;
import com.formkiq.stacks.api.handler.DocumentsFulltextRequestHandler;
Expand Down Expand Up @@ -135,6 +136,7 @@ public static void buildUrlMap() {
addRequestHandler(new VersionRequestHandler());
addRequestHandler(new SitesRequestHandler());
addRequestHandler(new DocumentVersionsRequestHandler());
addRequestHandler(new DocumentVersionsKeyRequestHandler());
addRequestHandler(new DocumentTagsRequestHandler());
addRequestHandler(new DocumentsActionsRequestHandler());
addRequestHandler(new DocumentTagValueRequestHandler());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* MIT License
*
* Copyright (c) 2018 - 2020 FormKiQ
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.api.handler;

import com.formkiq.aws.services.lambda.ApiGatewayRequestHandler;

/** {@link ApiGatewayRequestHandler} for "/documents/{documentId}/versions/{versionKey}". */
public class DocumentVersionsKeyRequestHandler extends AbstractPaymentRequiredRequestHandler {
@Override
public String getRequestUrl() {
return "/documents/{documentId}/versions/{versionKey}";
}
}
23 changes: 23 additions & 0 deletions lambda-api/src/main/resources/cloudformation/api-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@ Resources:
- sigv4: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/documents/{documentId}/versions/{versionKey}:
delete:
operationId: DeleteDocumentVersion
description: Delete a specific previous document version; ONLY available with FormKiQ Pro and Enterprise
tags:
- Document Versions
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/versionKeyPath'
responses:
'200':
$ref: '#/components/responses/200Cors'
security:
- sigv4: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/documents/{documentId}/content:
get:
operationId: GetDocumentContent
Expand Down Expand Up @@ -1989,6 +2005,13 @@ Resources:
type: string
content: {}
parameters:
versionKeyPath:
name: versionKey
in: path
description: Version Key
required: true
schema:
type: string
versionKeyParam:
name: versionKey
in: query
Expand Down
23 changes: 23 additions & 0 deletions lambda-api/src/main/resources/cloudformation/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@ Resources:
- AuthorizationCognito: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/documents/{documentId}/versions/{versionKey}:
delete:
operationId: DeleteDocumentVersion
description: Delete a specific previous document version; ONLY available with FormKiQ Pro and Enterprise
tags:
- Document Versions
parameters:
- $ref: '#/components/parameters/documentIdParam'
- $ref: '#/components/parameters/versionKeyPath'
responses:
'200':
$ref: '#/components/responses/200Cors'
security:
- AuthorizationCognito: []
x-amazon-apigateway-integration:
$ref: "#/components/x-amazon-apigateway-integrations/lambdaApi200"
/documents/{documentId}/content:
get:
operationId: GetDocumentContent
Expand Down Expand Up @@ -1989,6 +2005,13 @@ Resources:
type: string
content: {}
parameters:
versionKeyPath:
name: versionKey
in: path
description: Version Key
required: true
schema:
type: string
versionKeyParam:
name: versionKey
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import com.formkiq.aws.services.lambda.ApiGatewayRequestEvent;
import com.formkiq.aws.services.lambda.ApiGatewayRequestEventBuilder;
import com.formkiq.lambda.apigateway.util.GsonUtil;
import com.formkiq.testutils.aws.DynamoDbExtension;
import com.formkiq.testutils.aws.LocalStackExtension;
Expand Down Expand Up @@ -79,4 +80,51 @@ public void testHandleGetDocumentVersions01() throws Exception {
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
}
}

/**
* Delete /documents/{documentId}/versions/{versionKey} request.
*
* @param siteId {@link String}
* @param documentId {@link String}
* @param versionKey {@link String}
* @return {@link ApiGatewayRequestEvent}
*/
private ApiGatewayRequestEvent deleteVersionsRequest(final String siteId, final String documentId,
final String versionKey) {
ApiGatewayRequestEvent event = new ApiGatewayRequestEventBuilder().method("delete")
.resource("/documents/{documentId}/versions/{versionKey}")
.path("/documents/" + documentId + "/versions/" + versionKey).user("joesmith")
.group(siteId != null ? siteId : "default")
.pathParameters(Map.of("documentId", documentId, "versionKey", versionKey))
.queryParameters(siteId != null ? Map.of("siteId", siteId) : null).build();
return event;
}

/**
* Delete /documents/{documentId}/versions/{versionKey} request.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleDeleteDocumentVersions01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();

ApiGatewayRequestEvent event =
deleteVersionsRequest(siteId, documentId, UUID.randomUUID().toString());

// when
String response = handleRequest(event);

// then
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);

final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("402.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
}
}
}

0 comments on commit 24481ee

Please sign in to comment.