Skip to content

Commit

Permalink
fix(example-todo-list): add responses to controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
virkt25 committed Sep 13, 2018
1 parent acdd55c commit eda80ca
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 21 deletions.
51 changes: 43 additions & 8 deletions examples/todo-list/src/controllers/todo-list-todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,68 @@ export class TodoListTodoController {
@repository(TodoListRepository) protected todoListRepo: TodoListRepository,
) {}

@post('/todo-lists/{id}/todos')
async create(@param.path.number('id') id: number, @requestBody() todo: Todo) {
@post('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo model instance',
content: {'application/json': {'x-ts-type': Todo}},
},
},
})
async create(
@param.path.number('id') id: number,
@requestBody() todo: Todo,
): Promise<Todo> {
return await this.todoListRepo.todos(id).create(todo);
}

@get('/todo-lists/{id}/todos')
@get('/todo-lists/{id}/todos', {
responses: {
'200': {
description: "Array of Todo's belonging to TodoList",
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Todo}},
},
},
},
},
})
async find(
@param.path.number('id') id: number,
@param.query.string('filter') filter?: Filter,
) {
): Promise<Todo[]> {
return await this.todoListRepo.todos(id).find(filter);
}

@patch('/todo-lists/{id}/todos')
@patch('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo PATCH success count',
content: {'application/json': {'x-ts-type': Number}},
},
},
})
async patch(
@param.path.number('id') id: number,
@requestBody() todo: Partial<Todo>,
@param.query.string('where') where?: Where,
) {
): Promise<number> {
return await this.todoListRepo.todos(id).patch(todo, where);
}

@del('/todo-lists/{id}/todos')
@del('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo DELETE success count',
content: {'application/json': {'x-ts-type': Number}},
},
},
})
async delete(
@param.path.number('id') id: number,
@param.query.string('where') where?: Where,
) {
): Promise<number> {
return await this.todoListRepo.todos(id).delete(where);
}
}
63 changes: 56 additions & 7 deletions examples/todo-list/src/controllers/todo-list.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,94 @@ export class TodoListController {
public todoListRepository: TodoListRepository,
) {}

@post('/todo-lists')
@post('/todo-lists', {
responses: {
'200': {
description: 'TodoList model instance',
content: {'application/json': {'x-ts-type': TodoList}},
},
},
})
async create(@requestBody() obj: TodoList): Promise<TodoList> {
return await this.todoListRepository.create(obj);
}

@get('/todo-lists/count')
@get('/todo-lists/count', {
responses: {
'200': {
description: 'TodoList model count',
content: {'application/json': {'x-ts-type': Number}},
},
},
})
async count(@param.query.string('where') where?: Where): Promise<number> {
return await this.todoListRepository.count(where);
}

@get('/todo-lists')
@get('/todo-lists', {
responses: {
'200': {
description: 'Array of TodoList model instances',
content: {'application/json': {'x-ts-type': TodoList}},
},
},
})
async find(
@param.query.string('filter') filter?: Filter,
): Promise<TodoList[]> {
return await this.todoListRepository.find(filter);
}

@patch('/todo-lists')
@patch('/todo-lists', {
responses: {
'200': {
description: 'TodoList PATCH success count',
content: {'application/json': {'x-ts-type': Number}},
},
},
})
async updateAll(
@requestBody() obj: Partial<TodoList>,
@param.query.string('where') where?: Where,
): Promise<number> {
return await this.todoListRepository.updateAll(obj, where);
}

@get('/todo-lists/{id}')
@get('/todo-lists/{id}', {
responses: {
'200': {
description: 'TodoList model instance',
content: {'application/json': {'x-ts-type': TodoList}},
},
},
})
async findById(@param.path.number('id') id: number): Promise<TodoList> {
return await this.todoListRepository.findById(id);
}

@patch('/todo-lists/{id}')
@patch('/todo-lists/{id}', {
responses: {
'200': {
description: 'TodoList PATCH success',
content: {'application/json': {'x-ts-type': Boolean}},
},
},
})
async updateById(
@param.path.number('id') id: number,
@requestBody() obj: TodoList,
): Promise<boolean> {
return await this.todoListRepository.updateById(id, obj);
}

@del('/todo-lists/{id}')
@del('/todo-lists/{id}', {
responses: {
'200': {
description: 'TodoList DELETE success',
content: {'application/json': {'x-ts-type': Boolean}},
},
},
})
async deleteById(@param.path.number('id') id: number): Promise<boolean> {
return await this.todoListRepository.deleteById(id);
}
Expand Down
58 changes: 52 additions & 6 deletions examples/todo-list/src/controllers/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,87 @@ import {TodoRepository} from '../repositories';
export class TodoController {
constructor(@repository(TodoRepository) protected todoRepo: TodoRepository) {}

@post('/todos')
@post('/todos', {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {'x-ts-type': Todo}},
},
},
})
async createTodo(@requestBody() todo: Todo) {
return await this.todoRepo.create(todo);
}

@get('/todos/{id}')
@get('/todos/{id}', {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {'x-ts-type': Todo}},
},
},
})
async findTodoById(
@param.path.number('id') id: number,
@param.query.boolean('items') items?: boolean,
): Promise<Todo> {
return await this.todoRepo.findById(id);
}

@get('/todos')
@get('/todos', {
responses: {
'200': {
description: 'Array of Todo model instances',
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Todo}},
},
},
},
},
})
async findTodos(): Promise<Todo[]> {
return await this.todoRepo.find();
}

@put('/todos/{id}')
@put('/todos/{id}', {
responses: {
'200': {
description: 'Todo PUT success',
content: {'application/json': {'x-ts-type': Boolean}},
},
},
})
async replaceTodo(
@param.path.number('id') id: number,
@requestBody() todo: Todo,
): Promise<boolean> {
return await this.todoRepo.replaceById(id, todo);
}

@patch('/todos/{id}')
@patch('/todos/{id}', {
responses: {
'200': {
description: 'Todo PATCH success',
content: {'application/json': {'x-ts-type': Boolean}},
},
},
})
async updateTodo(
@param.path.number('id') id: number,
@requestBody() todo: Todo,
): Promise<boolean> {
return await this.todoRepo.updateById(id, todo);
}

@del('/todos/{id}')
@del('/todos/{id}', {
responses: {
'200': {
description: 'Todo DELETE success',
content: {'application/json': {'x-ts-type': Boolean}},
},
},
})
async deleteTodo(@param.path.number('id') id: number): Promise<boolean> {
return await this.todoRepo.deleteById(id);
}
Expand Down

0 comments on commit eda80ca

Please sign in to comment.