From 0eec33fee4dde5aa7412cf4b61d5b43aa8f14f1e Mon Sep 17 00:00:00 2001 From: wnhlee <2wheeh@gmail.com> Date: Sun, 26 Nov 2023 15:31:53 +0900 Subject: [PATCH] feat: add api returning server time --- api/generate/openapi.json | 49 +++++++++++++++++++ .../controller/http/dev/dev.v1.controller.ts | 19 ++++++- .../http/dev/response/dev.v1.response.ts | 4 ++ .../http/dev/schema/dev.v1.schema.ts | 14 +++++- 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/api/generate/openapi.json b/api/generate/openapi.json index e062caf06..d7e78f685 100644 --- a/api/generate/openapi.json +++ b/api/generate/openapi.json @@ -58,6 +58,43 @@ } } }, + "/api/v1/dev/server-time": { + "get": { + "operationId": "DevApiSpec_get_/server-time", + "tags": [ + "Development" + ], + "summary": "Server Time", + "security": [ + { + "jwt": [] + } + ], + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ServerTimeV1Response" + } + } + } + }, + "default": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HttpErrorResponse" + } + } + } + } + } + } + }, "/healthz/liveness": { "get": { "operationId": "HealthApiSpec_get_/liveness", @@ -126,6 +163,18 @@ }, "additionalProperties": false }, + "ServerTimeV1Response": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "message" + ] + }, "LivenessResponse": { "type": "object", "properties": { diff --git a/api/src/controller/http/dev/dev.v1.controller.ts b/api/src/controller/http/dev/dev.v1.controller.ts index 49a31d470..c78cc116a 100644 --- a/api/src/controller/http/dev/dev.v1.controller.ts +++ b/api/src/controller/http/dev/dev.v1.controller.ts @@ -1,7 +1,10 @@ import { Request, Response, Router } from 'express'; import { GreetingV1Request } from '@controller/http/dev/request/dev.v1.request'; -import { GreetingV1Response } from '@controller/http/dev/response/dev.v1.response'; +import { + GreetingV1Response, + ServerTimeV1Response +} from '@controller/http/dev/response/dev.v1.response'; import { methodNotAllowed } from '@controller/http/handler'; export class DevV1Controller { @@ -14,6 +17,11 @@ export class DevV1Controller { .post(this.greeting) .all(methodNotAllowed); + router + .route(`${prefix}/server-time`) + .get(this.serverTime) + .all(methodNotAllowed); + return router; }; @@ -23,4 +31,13 @@ export class DevV1Controller { ) => { res.send({ message: 'Hello World!' }); }; + + public serverTime = async ( + req: Request, + res: Response + ) => { + const now = new Date(); + + res.send({ message: now.toISOString() }); + }; } diff --git a/api/src/controller/http/dev/response/dev.v1.response.ts b/api/src/controller/http/dev/response/dev.v1.response.ts index 693e298cc..a2aa85385 100644 --- a/api/src/controller/http/dev/response/dev.v1.response.ts +++ b/api/src/controller/http/dev/response/dev.v1.response.ts @@ -1,3 +1,7 @@ export interface GreetingV1Response { message?: string; } + +export interface ServerTimeV1Response { + message: string; +} diff --git a/api/src/controller/http/dev/schema/dev.v1.schema.ts b/api/src/controller/http/dev/schema/dev.v1.schema.ts index 1324e3209..3319b1263 100644 --- a/api/src/controller/http/dev/schema/dev.v1.schema.ts +++ b/api/src/controller/http/dev/schema/dev.v1.schema.ts @@ -1,7 +1,10 @@ import { Tspec } from 'tspec'; import { GreetingV1Request } from '@controller/http/dev/request/dev.v1.request'; -import { GreetingV1Response } from '@controller/http/dev/response/dev.v1.response'; +import { + GreetingV1Response, + ServerTimeV1Response +} from '@controller/http/dev/response/dev.v1.response'; import { HttpErrorResponse } from '@controller/http/response'; export type DevApiSpec = Tspec.DefineApiSpec<{ @@ -19,5 +22,14 @@ export type DevApiSpec = Tspec.DefineApiSpec<{ }; }; }; + '/server-time': { + get: { + summary: 'Server Time'; + responses: { + 200: ServerTimeV1Response; + default: HttpErrorResponse; + }; + }; + }; }; }>;