Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Endpioint reordering & Dev Controller (#132)
Browse files Browse the repository at this point in the history
- Reorder endpoints to the new standard
- Add the dev controller into the swagger docs when generated from the
build command
  • Loading branch information
wilwade authored Jun 28, 2024
1 parent 6e8a0e8 commit c40f369
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 22 deletions.
6 changes: 4 additions & 2 deletions apps/api/src/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ import { ProfileController } from './profile.controller';
}),
],
providers: [ConfigService, ApiService, IpfsService],
// Controller order determines the order of display for docs
// v[Desc first][ABC Second], Health, and then Dev only last
controllers:
process.env?.ENVIRONMENT === 'dev'
? [DevelopmentController, AssetController, ContentController, HealthController, ProfileController]
: [AssetController, ContentController, HealthController, ProfileController],
? [AssetController, ContentController, ProfileController, HealthController, DevelopmentController]
: [AssetController, ContentController, ProfileController, HealthController],
exports: [],
})
export class ApiModule {}
3 changes: 3 additions & 0 deletions apps/api/src/build-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import '@frequency-chain/api-augment';
import * as fs from 'fs';
import { NestFactory } from '@nestjs/core';

// Ensure that the dev controller is included
process.env.ENVIRONMENT = 'dev';

// Mock out required env vars before the module loads
process.env.REDIS_URL = 'http://127.0.0.1';
process.env.FREQUENCY_URL = 'http://127.0.0.1';
Expand Down
9 changes: 5 additions & 4 deletions apps/api/src/development.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import * as QueueConstants from '../../../libs/common/src';
import { IpfsService } from '../../../libs/common/src/utils/ipfs.client';
import { AnnouncementType, createBroadcast, createProfile, createReaction, createReply, createTombstone, createUpdate } from '../../../libs/common/src/interfaces/dsnp';
import { calculateDsnpHash } from '../../../libs/common/src/utils/ipfs';
import { ApiOperation } from '@nestjs/swagger';
import { ApiOperation, ApiTags } from '@nestjs/swagger';

@Controller('dev')
@ApiTags('dev')
export class DevelopmentController {
private readonly logger: Logger;

Expand Down Expand Up @@ -41,7 +42,7 @@ export class DevelopmentController {
}

@Get('/request/:jobId')
@ApiOperation({ summary: 'Get a Job given a jobId' })
@ApiOperation({ summary: 'Get a Job given a jobId', description: 'ONLY enabled when ENVIRONMENT="dev".' })
async requestJob(@Param('jobId') jobId: string) {
this.logger.log(jobId);
const job = await this.requestQueue.getJob(jobId);
Expand All @@ -50,7 +51,7 @@ export class DevelopmentController {
}

@Get('/asset/:assetId')
@ApiOperation({ summary: 'Get an Asset given an assetId' })
@ApiOperation({ summary: 'Get an Asset given an assetId', description: 'ONLY enabled when ENVIRONMENT="dev".' })
// eslint-disable-next-line consistent-return
async getAsset(@Param('assetId') assetId: string) {
if (await this.ipfsService.isPinned(assetId)) {
Expand All @@ -60,7 +61,7 @@ export class DevelopmentController {
}

@Post('/dummy/announcement/:queueType/:count')
@ApiOperation({ summary: 'Create dummy announcement data' })
@ApiOperation({ summary: 'Create dummy announcement data', description: 'ONLY enabled when ENVIRONMENT="dev".' })
async populate(@Param('queueType') queueType: QueueConstants.AnnouncementTypeDto, @Param('count') count: number) {
const promises: Promise<Job>[] = [];
// eslint-disable-next-line no-plusplus
Expand Down
122 changes: 106 additions & 16 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,47 @@
]
}
},
"/v1/profile/{userDsnpId}": {
"put": {
"operationId": "ProfileController_profile",
"summary": "Update a user's Profile",
"parameters": [
{
"name": "userDsnpId",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProfileDto"
}
}
}
},
"responses": {
"202": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AnnouncementResponseDto"
}
}
}
}
},
"tags": [
"v1/profile"
]
}
},
"/healthz": {
"get": {
"operationId": "HealthController_healthz",
Expand Down Expand Up @@ -282,44 +323,93 @@
]
}
},
"/v1/profile/{userDsnpId}": {
"put": {
"operationId": "ProfileController_profile",
"summary": "Update a user's Profile",
"/dev/request/{jobId}": {
"get": {
"operationId": "DevelopmentController_requestJob",
"summary": "Get a Job given a jobId",
"description": "ONLY enabled when ENVIRONMENT=\"dev\".",
"parameters": [
{
"name": "userDsnpId",
"name": "jobId",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProfileDto"
}
}
"responses": {
"200": {
"description": ""
}
},
"tags": [
"dev"
]
}
},
"/dev/asset/{assetId}": {
"get": {
"operationId": "DevelopmentController_getAsset",
"summary": "Get an Asset given an assetId",
"description": "ONLY enabled when ENVIRONMENT=\"dev\".",
"parameters": [
{
"name": "assetId",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
}
],
"responses": {
"202": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AnnouncementResponseDto"
"type": "object"
}
}
}
}
},
"tags": [
"v1/profile"
"dev"
]
}
},
"/dev/dummy/announcement/{queueType}/{count}": {
"post": {
"operationId": "DevelopmentController_populate",
"summary": "Create dummy announcement data",
"description": "ONLY enabled when ENVIRONMENT=\"dev\".",
"parameters": [
{
"name": "queueType",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
},
{
"name": "count",
"required": true,
"in": "path",
"schema": {
"type": "number"
}
}
],
"responses": {
"201": {
"description": ""
}
},
"tags": [
"dev"
]
}
}
Expand Down

0 comments on commit c40f369

Please sign in to comment.