MCPcopy
hub / github.com/FoalTS/foal / Controller

Class Controller

packages/cli/templates/rest-api/controllers/controller.ts:20–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19@ApiUseTag('/* camelName */')
20export class /* upperFirstCamelName */Controller {
21
22 @Get()
23 @ApiOperationId('find/* upperFirstCamelName */s')
24 @ApiOperationSummary('Find /* camelName */s.')
25 @ApiOperationDescription(
26 'The query parameters "skip" and "take" can be used for pagination. The first ' +
27 'is the offset and the second is the number of elements to be returned.'
28 )
29 @ApiResponse(400, { description: 'Invalid query parameters.' })
30 @ApiResponse(200, { description: 'Returns a list of /* camelName */s.' })
31 @ValidateQueryParam('skip', { type: 'number' }, { required: false })
32 @ValidateQueryParam('take', { type: 'number' }, { required: false })
33 async find/* upperFirstCamelName */s(ctx: Context) {
34 const /* camelName */s = await /* upperFirstCamelName */.find({
35 skip: ctx.request.query.skip,
36 take: ctx.request.query.take,
37 where: {},
38 });
39 return new HttpResponseOK(/* camelName */s);
40 }
41
42 @Get('/:/* camelName */Id')
43 @ApiOperationId('find/* upperFirstCamelName */ById')
44 @ApiOperationSummary('Find a /* camelName */ by ID.')
45 @ApiResponse(404, { description: '/* upperFirstCamelName */ not found.' })
46 @ApiResponse(200, { description: 'Returns the /* camelName */.' })
47 @ValidatePathParam('/* camelName */Id', { type: 'number' })
48 async find/* upperFirstCamelName */ById(ctx: Context) {
49 const /* camelName */ = await /* upperFirstCamelName */.findOneBy({ id: ctx.request.params./* camelName */Id });
50
51 if (!/* camelName */) {
52 return new HttpResponseNotFound();
53 }
54
55 return new HttpResponseOK(/* camelName */);
56 }
57
58 @Post()
59 @ApiOperationId('create/* upperFirstCamelName */')
60 @ApiOperationSummary('Create a new /* camelName */.')
61 @ApiResponse(400, { description: 'Invalid /* camelName */.' })
62 @ApiResponse(201, { description: '/* upperFirstCamelName */ successfully created. Returns the /* camelName */.' })
63 @ValidateBody(/* camelName */Schema)
64 async create/* upperFirstCamelName */(ctx: Context) {
65 const /* camelName */ = await /* upperFirstCamelName */.save(ctx.request.body);
66 return new HttpResponseCreated(/* camelName */);
67 }
68
69 @Patch('/:/* camelName */Id')
70 @ApiOperationId('modify/* upperFirstCamelName */')
71 @ApiOperationSummary('Update/modify an existing /* camelName */.')
72 @ApiResponse(400, { description: 'Invalid /* camelName */.' })
73 @ApiResponse(404, { description: '/* upperFirstCamelName */ not found.' })
74 @ApiResponse(200, { description: '/* upperFirstCamelName */ successfully updated. Returns the /* camelName */.' })
75 @ValidatePathParam('/* camelName */Id', { type: 'number' })
76 @ValidateBody({ .../* camelName */Schema, required: [] })
77 async modify/* upperFirstCamelName */(ctx: Context) {

Callers

nothing calls this directly

Calls 12

GetFunction · 0.90
ApiOperationIdFunction · 0.90
ApiOperationSummaryFunction · 0.90
ApiOperationDescriptionFunction · 0.90
ApiResponseFunction · 0.90
ValidateQueryParamFunction · 0.90
ValidatePathParamFunction · 0.90
PostFunction · 0.90
ValidateBodyFunction · 0.90
PatchFunction · 0.90
PutFunction · 0.90
DeleteFunction · 0.90

Tested by

no test coverage detected