Skip to content

Commit

Permalink
chore: adding POST method for exchange continuation and marking PUT a…
Browse files Browse the repository at this point in the history
…s deprecated
  • Loading branch information
artursudnik committed Nov 3, 2023
1 parent fcbee66 commit 737b790
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
49 changes: 48 additions & 1 deletion apps/vc-api/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,54 @@
},
"/v1/vc-api/exchanges/{exchangeId}/{transactionId}": {
"put": {
"operationId": "VcApiController_continueExchange",
"operationId": "VcApiController_continueExchangePut",
"summary": "",
"description": "Receives information related to an existing exchange.\nhttps://w3c-ccg.github.io/vc-api/#continue-exchange",
"parameters": [
{ "name": "exchangeId", "required": true, "in": "path", "schema": { "type": "string" } },
{ "name": "transactionId", "required": true, "in": "path", "schema": { "type": "string" } }
],
"requestBody": {
"required": true,
"content": {
"application/json": { "schema": { "$ref": "#/components/schemas/VerifiablePresentationDto" } }
}
},
"responses": {
"200": {
"description": "Verifiable Presentation successfully submitted and verified",
"content": {
"application/json": { "schema": { "$ref": "#/components/schemas/ExchangeResponseDto" } }
}
},
"202": {
"description": "Verifiable Presentation successfully submitted. Further review in progress."
},
"400": {
"description": "",
"content": {
"application/json": { "schema": { "$ref": "#/components/schemas/BadRequestErrorResponseDto" } }
}
},
"404": {
"description": "",
"content": {
"application/json": { "schema": { "$ref": "#/components/schemas/NotFoundErrorResponseDto" } }
}
},
"500": {
"description": "",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/InternalServerErrorResponseDto" }
}
}
}
},
"tags": ["vc-api"]
},
"post": {
"operationId": "VcApiController_continueExchangePost",
"summary": "",
"description": "Receives information related to an existing exchange.\nhttps://w3c-ccg.github.io/vc-api/#continue-exchange",
"parameters": [
Expand Down
42 changes: 41 additions & 1 deletion apps/vc-api/src/vc-api/vc-api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Get,
HttpCode,
InternalServerErrorException,
Logger,
NotFoundException,
Param,
Post,
Expand Down Expand Up @@ -73,6 +74,8 @@ import { InternalServerErrorResponseDto } from '../dtos/internal-server-error-re
@ApiBadRequestResponse({ type: BadRequestErrorResponseDto })
@ApiInternalServerErrorResponse({ type: InternalServerErrorResponseDto })
export class VcApiController {
private readonly logger = new Logger(VcApiController.name, { timestamp: true });

constructor(private vcApiService: CredentialsService, private exchangeService: ExchangeService) {}

/**
Expand Down Expand Up @@ -248,12 +251,49 @@ export class VcApiController {
description: 'Verifiable Presentation successfully submitted. Further review in progress.'
})
@ApiNotFoundResponse({ type: NotFoundErrorResponseDto })
async continueExchange(
async continueExchangePut(
@Param('exchangeId') exchangeId: string,
@Param('transactionId') transactionId: string,
@Body() presentation: VerifiablePresentationDto,
@Res() res: Response
): Promise<ExchangeResponseDto | Response> {
this.logger.warn(`PUT method to be deprecated for exchange continuation`);

return this.continueExchange({ exchangeId, transactionId, presentation, res });
}

@Post('/exchanges/:exchangeId/:transactionId')
@ApiOperation({
description:
'Receives information related to an existing exchange.\n' +
'https://w3c-ccg.github.io/vc-api/#continue-exchange'
})
@ApiBody({ type: VerifiablePresentationDto })
@ApiOkResponse({
description: 'Verifiable Presentation successfully submitted and verified',
type: ExchangeResponseDto
})
@ApiAcceptedResponse({
description: 'Verifiable Presentation successfully submitted. Further review in progress.'
})
@ApiNotFoundResponse({ type: NotFoundErrorResponseDto })
async continueExchangePost(
@Param('exchangeId') exchangeId: string,
@Param('transactionId') transactionId: string,
@Body() presentation: VerifiablePresentationDto,
@Res() res: Response
): Promise<ExchangeResponseDto | Response> {
return this.continueExchange({ exchangeId, transactionId, presentation, res });
}

async continueExchange(options: {
exchangeId: string;
transactionId: string;
presentation: VerifiablePresentationDto;
res: Response;
}): Promise<ExchangeResponseDto | Response> {
const { exchangeId, transactionId, presentation, res } = options;

if (!(await this.exchangeService.getExchange(exchangeId))) {
throw new NotFoundException(`exchangeId=${exchangeId} does not exist`);
}
Expand Down

0 comments on commit 737b790

Please sign in to comment.