-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathtodo-list-todo.controller.ts
113 lines (108 loc) · 2.84 KB
/
todo-list-todo.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
// 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,
repository,
Where,
} from '@loopback/repository';
import {
del,
get,
getModelSchemaRef,
getWhereSchemaFor,
param,
patch,
post,
requestBody,
} from '@loopback/rest';
import {Todo, TodoList} from '../models';
import {TodoListRepository} from '../repositories';
export class TodoListTodoController {
constructor(
@repository(TodoListRepository)
protected todoListRepository: TodoListRepository,
) {}
@post('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList model instance',
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
async create(
@param.path.number('id') id: typeof TodoList.prototype.id,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {
title: 'NewTodoInTodoList',
exclude: ['id'],
optional: ['todoListId'],
}),
},
},
})
todo: Omit<Todo, 'id'>,
): Promise<Todo> {
return this.todoListRepository.todos(id).create(todo);
}
@get('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'Array of TodoList has many Todo',
content: {
'application/json': {
schema: {type: 'array', items: getModelSchemaRef(Todo)},
},
},
},
},
})
async find(
@param.path.number('id') id: number,
@param.query.object('filter') filter?: Filter<Todo>,
): Promise<Todo[]> {
return this.todoListRepository.todos(id).find(filter);
}
@patch('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo PATCH success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async patch(
@param.path.number('id') id: number,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {partial: true}),
},
},
})
todo: Partial<Todo>,
@param.query.object('where', getWhereSchemaFor(Todo)) where?: Where<Todo>,
): Promise<Count> {
return this.todoListRepository.todos(id).patch(todo, where);
}
@del('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo DELETE success count',
content: {'application/json': {schema: CountSchema}},
},
},
})
async delete(
@param.path.number('id') id: number,
@param.query.object('where', getWhereSchemaFor(Todo)) where?: Where<Todo>,
): Promise<Count> {
return this.todoListRepository.todos(id).delete(where);
}
}