-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrud-controller.edge
More file actions
52 lines (39 loc) · 1.55 KB
/
crud-controller.edge
File metadata and controls
52 lines (39 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Inject } from '@athenna/ioc'
import type { PaginationOptions } from '@athenna/common'
import { Controller, type Context } from '@athenna/http'
import { {{ crudNamePascal }}Service } from '{{ serviceImportPath }}'
@Controller()
export class {{ namePascal }} {
@Inject()
public {{ crudNameLower }}Service: {{ crudNamePascal }}Service
public async index({ request, response }: Context) {
const options: PaginationOptions = {
page: parseInt(request.query('page', 0)),
limit: parseInt(request.query('limit', 10)),
resourceUrl: request.baseHostUrl
}
const data = await this.{{ crudNameLower }}Service.paginate(options)
return response.status(200).send(data)
}
public async store({ request, response }: Context) {
const body = request.only([{{{ properties }}}])
const data = await this.{{ crudNameLower }}Service.create(body)
return response.status(201).send(data)
}
public async show({ request, response }: Context) {
const id = request.param('id')
const data = await this.{{ crudNameLower }}Service.findById(id)
return response.status(200).send(data)
}
public async update({ request, response }: Context) {
const id = request.param('id')
const body = request.only([{{{ properties }}}])
const data = await this.{{ crudNameLower }}Service.update(id, body)
return response.status(200).send(data)
}
public async delete({ request, response }: Context) {
const id = request.param('id')
await this.{{crudNameLower }}Service.delete(id)
return response.status(204)
}
}