-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathtodo-list.controller.ts
177 lines (167 loc) · 4.08 KB
/
todo-list.controller.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
// Node module: @loopback/example-todo-list
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {
Count,
CountSchema,
Filter,
FilterExcludingWhere,
repository,
Where,
} from '@loopback/repository';
import {
del,
get,
getModelSchemaRef,
param,
patch,
post,
put,
requestBody,
} from '@loopback/rest';
import {TodoList} from '../models';
import {TodoListRepository} from '../repositories';
export class TodoListController {
constructor(
@repository(TodoListRepository)
public todoListRepository: TodoListRepository,
) {}
@post('/todo-lists', {
responses: {
'200': {
description: 'TodoList model instance',
content: {'application/json': {schema: getModelSchemaRef(TodoList)}},
},
},
})
async create(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {
title: 'NewTodoList',
exclude: ['id'],
}),
},
},
})
todoList: Omit<TodoList, 'id'>,
): Promise<TodoList> {
return this.todoListRepository.create(todoList);
}
@get('/todo-lists/count', {
responses: {
'200': {
description: 'TodoList model count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async count(@param.where(TodoList) where?: Where<TodoList>): Promise<Count> {
return this.todoListRepository.count(where);
}
@get('/todo-lists', {
responses: {
'200': {
description: 'Array of TodoList model instances',
content: {
'application/json': {
schema: {
type: 'array',
items: getModelSchemaRef(TodoList, {includeRelations: true}),
},
},
},
},
},
})
async find(
@param.filter(TodoList) filter?: Filter<TodoList>,
): Promise<TodoList[]> {
return this.todoListRepository.find(filter);
}
@patch('/todo-lists', {
responses: {
'200': {
description: 'TodoList PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async updateAll(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {partial: true}),
},
},
})
todoList: TodoList,
@param.where(TodoList) where?: Where<TodoList>,
): Promise<Count> {
return this.todoListRepository.updateAll(todoList, where);
}
@get('/todo-lists/{id}', {
responses: {
'200': {
description: 'TodoList model instance',
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {includeRelations: true}),
},
},
},
},
})
async findById(
@param.path.number('id') id: number,
@param.filter(TodoList, {exclude: 'where'})
filter?: FilterExcludingWhere<TodoList>,
): Promise<TodoList> {
return this.todoListRepository.findById(id, filter);
}
@patch('/todo-lists/{id}', {
responses: {
'204': {
description: 'TodoList PATCH success',
},
},
})
async updateById(
@param.path.number('id') id: number,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {partial: true}),
},
},
})
todoList: TodoList,
): Promise<void> {
await this.todoListRepository.updateById(id, todoList);
}
@del('/todo-lists/{id}', {
responses: {
'204': {
description: 'TodoList DELETE success',
},
},
})
async deleteById(@param.path.number('id') id: number): Promise<void> {
await this.todoListRepository.deleteById(id);
}
@put('/todo-lists/{id}', {
responses: {
'204': {
description: 'TodoList PUT success',
},
},
})
async replaceById(
@param.path.number('id') id: number,
@requestBody() todoList: TodoList,
): Promise<void> {
await this.todoListRepository.replaceById(id, todoList);
}
}