diff --git a/apps/vc-api/docs/openapi.json b/apps/vc-api/docs/openapi.json index ccabd5b..235bca1 100644 --- a/apps/vc-api/docs/openapi.json +++ b/apps/vc-api/docs/openapi.json @@ -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": [ diff --git a/apps/vc-api/src/vc-api/vc-api.controller.ts b/apps/vc-api/src/vc-api/vc-api.controller.ts index e5be3dd..97b42d4 100644 --- a/apps/vc-api/src/vc-api/vc-api.controller.ts +++ b/apps/vc-api/src/vc-api/vc-api.controller.ts @@ -22,6 +22,7 @@ import { Get, HttpCode, InternalServerErrorException, + Logger, NotFoundException, Param, Post, @@ -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) {} /** @@ -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 { + 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 { + return this.continueExchange({ exchangeId, transactionId, presentation, res }); + } + + private async continueExchange(options: { + exchangeId: string; + transactionId: string; + presentation: VerifiablePresentationDto; + res: Response; + }): Promise { + const { exchangeId, transactionId, presentation, res } = options; + if (!(await this.exchangeService.getExchange(exchangeId))) { throw new NotFoundException(`exchangeId=${exchangeId} does not exist`); }