Skip to content

Commit

Permalink
feat: add api returning server time
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh committed Nov 26, 2023
1 parent 1e2416f commit 0eec33f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
49 changes: 49 additions & 0 deletions api/generate/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -126,6 +163,18 @@
},
"additionalProperties": false
},
"ServerTimeV1Response": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"message"
]
},
"LivenessResponse": {
"type": "object",
"properties": {
Expand Down
19 changes: 18 additions & 1 deletion api/src/controller/http/dev/dev.v1.controller.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,6 +17,11 @@ export class DevV1Controller {
.post(this.greeting)
.all(methodNotAllowed);

router
.route(`${prefix}/server-time`)
.get(this.serverTime)
.all(methodNotAllowed);

return router;
};

Expand All @@ -23,4 +31,13 @@ export class DevV1Controller {
) => {
res.send({ message: 'Hello World!' });
};

public serverTime = async (
req: Request,
res: Response<ServerTimeV1Response>
) => {
const now = new Date();

res.send({ message: now.toISOString() });
};
}
4 changes: 4 additions & 0 deletions api/src/controller/http/dev/response/dev.v1.response.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export interface GreetingV1Response {
message?: string;
}

export interface ServerTimeV1Response {
message: string;
}
14 changes: 13 additions & 1 deletion api/src/controller/http/dev/schema/dev.v1.schema.ts
Original file line number Diff line number Diff line change
@@ -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<{
Expand All @@ -19,5 +22,14 @@ export type DevApiSpec = Tspec.DefineApiSpec<{
};
};
};
'/server-time': {
get: {
summary: 'Server Time';
responses: {
200: ServerTimeV1Response;
default: HttpErrorResponse;
};
};
};
};
}>;

0 comments on commit 0eec33f

Please sign in to comment.