Skip to content

Commit 6542cb0

Browse files
committed
feat: register CreateOrder routes and fix plop template
ADDED: - Import and register createOrderRoutes in src/app.ts - Added 'CreateOrders' tag to Swagger configuration - Fixed generated route to use 'CreateOrders' tag (plural, matches convention) - Fixed security scheme from 'Bearer' to 'bearerAuth' (OpenAPI 3.0 format) FIXED PLOP TEMPLATE: - Updated plop-templates/service/route.hbs to use 'bearerAuth' instead of 'Bearer' - Future generated services will have correct security scheme Now CreateOrder endpoints appear in Swagger UI under "CreateOrders" section. The dev server auto-restarts when files change, so Swagger updates immediately!
1 parent 3f1ecca commit 6542cb0

4 files changed

Lines changed: 144 additions & 2 deletions

File tree

plop-templates/service/route.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const {{camelCase name}}Routes: FastifyPluginAsyncTypebox = async (fastify) => {
1919
schema: {
2020
description: 'Create a new {{camelCase name}}',
2121
tags: ['{{pascalCase name}}'],
22-
security: [{ Bearer: [] }],
22+
security: [{ bearerAuth: [] }],
2323
body: Type.Object({
2424
// TODO: Define your request body schema
2525
name: Type.String({ minLength: 1 }),
@@ -109,7 +109,7 @@ const {{camelCase name}}Routes: FastifyPluginAsyncTypebox = async (fastify) => {
109109
schema: {
110110
description: 'Get all {{camelCase name}}s',
111111
tags: ['{{pascalCase name}}'],
112-
security: [{ Bearer: [] }],
112+
security: [{ bearerAuth: [] }],
113113
response: {
114114
200: Type.Object({
115115
success: Type.Literal(true),

src/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import authRoutes from './routes/auth/index';
1717
import userRoutes from './routes/users/index';
1818
import exampleRoutes from './routes/example/index';
1919
import todoRoutes from './routes/todos/index';
20+
import createOrderRoutes from './routes/create-order/index';
2021

2122
export async function buildApp() {
2223
const app = Fastify({
@@ -73,6 +74,9 @@ export async function buildApp() {
7374

7475
// Todo routes (demonstrates Golden Orchestrator pattern)
7576
await fastify.register(todoRoutes, { prefix: '/todos' });
77+
78+
// CreateOrder routes (demonstrates Golden Orchestrator pattern)
79+
await fastify.register(createOrderRoutes, { prefix: '/create-orders' });
7680
},
7781
{ prefix: `${app.config.API_PREFIX}/${app.config.API_VERSION}` }
7882
);

src/plugins/swagger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const swaggerPlugin: FastifyPluginAsync = async (fastify) => {
1919
{ name: 'Auth', description: 'Authentication endpoints' },
2020
{ name: 'Users', description: 'User management endpoints' },
2121
{ name: 'Todos', description: 'Todo management (demonstrates Golden Orchestrator pattern)' },
22+
{ name: 'CreateOrders', description: 'CreateOrder management (demonstrates Golden Orchestrator pattern)' },
2223
{ name: 'Example', description: 'Example CRUD endpoints (demonstrates direct Prisma access)' },
2324
],
2425
components: {

src/routes/create-order/index.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import { Type } from '@sinclair/typebox';
2+
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
3+
import { createOrderService } from '@services/create-order/index.js';
4+
5+
/**
6+
* CreateOrder Routes
7+
*
8+
* Demonstrates the Golden Orchestrator pattern.
9+
* Uses CreateOrderService which implements the pipeline pattern.
10+
*
11+
* Generated by: npm run generate
12+
*/
13+
const createOrderRoutes: FastifyPluginAsyncTypebox = async (fastify) => {
14+
// Create CreateOrder - Uses Golden Orchestrator Pattern
15+
fastify.post(
16+
'/',
17+
{
18+
preValidation: [fastify.authenticate],
19+
schema: {
20+
description: 'Create a new createOrder',
21+
tags: ['CreateOrders'],
22+
security: [{ bearerAuth: [] }],
23+
body: Type.Object({
24+
// TODO: Define your request body schema
25+
name: Type.String({ minLength: 1 }),
26+
}),
27+
response: {
28+
201: Type.Object({
29+
success: Type.Literal(true),
30+
data: Type.Object({
31+
id: Type.String(),
32+
createdAt: Type.String({ format: 'date-time' }),
33+
updatedAt: Type.String({ format: 'date-time' }),
34+
// TODO: Add your fields
35+
}),
36+
metadata: Type.Optional(Type.Object({
37+
duration: Type.Number({ description: 'Total execution time in ms' }),
38+
metrics: Type.Optional(Type.Record(Type.String(), Type.Number())),
39+
})),
40+
}),
41+
400: Type.Object({
42+
success: Type.Literal(false),
43+
error: Type.Object({
44+
message: Type.String(),
45+
statusCode: Type.Number(),
46+
}),
47+
}),
48+
},
49+
},
50+
},
51+
async (request, reply) => {
52+
// Call the service - it uses the orchestrator internally
53+
const result = await createOrderService.createCreateOrder({
54+
// TODO: Map request body to input
55+
...request.body,
56+
});
57+
58+
if (!result.success) {
59+
return reply.status(400).send({
60+
success: false,
61+
error: {
62+
message: result.error?.message || 'Failed to create createOrder',
63+
statusCode: 400,
64+
},
65+
});
66+
}
67+
68+
return reply.status(201).send({
69+
success: true,
70+
data: {
71+
...result.data!,
72+
createdAt: result.data!.createdAt.toISOString(),
73+
updatedAt: result.data!.updatedAt.toISOString(),
74+
},
75+
metadata: {
76+
duration: result.duration,
77+
metrics: result.metrics,
78+
},
79+
});
80+
}
81+
);
82+
83+
// Health check
84+
fastify.get(
85+
'/health',
86+
{
87+
schema: {
88+
description: 'Check if CreateOrder service is healthy',
89+
tags: ['CreateOrders'],
90+
response: {
91+
200: Type.Object({
92+
status: Type.String(),
93+
service: Type.String(),
94+
}),
95+
},
96+
},
97+
},
98+
async (_request, reply) => {
99+
const health = await createOrderService.healthCheck();
100+
return reply.send(health);
101+
}
102+
);
103+
104+
// Get all createOrders (simple example)
105+
fastify.get(
106+
'/',
107+
{
108+
preValidation: [fastify.authenticate],
109+
schema: {
110+
description: 'Get all createOrders',
111+
tags: ['CreateOrders'],
112+
security: [{ bearerAuth: [] }],
113+
response: {
114+
200: Type.Object({
115+
success: Type.Literal(true),
116+
data: Type.Array(
117+
Type.Object({
118+
id: Type.String(),
119+
// TODO: Add your fields
120+
})
121+
),
122+
}),
123+
},
124+
},
125+
},
126+
async (_request, reply) => {
127+
// TODO: Implement list logic (could create a ListOrchestrator)
128+
// For now, returning empty array
129+
return reply.send({
130+
success: true,
131+
data: [],
132+
});
133+
}
134+
);
135+
};
136+
137+
export default createOrderRoutes;

0 commit comments

Comments
 (0)