Class: TaskManager::Api::V1::TasksController

Inherits:
TaskManager::ApplicationController show all
Defined in:
app/controllers/task_manager/api/v1/tasks_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject

删除任务

Examples:

# 请求
DELETE /api/tasks/... HTTP/1.1
Accept: application/vnd.menglifang.com.cn; version=1

# 响应
## 成功
HTTP/1.1 204 No Content


69
70
71
72
73
# File 'app/controllers/task_manager/api/v1/tasks_controller.rb', line 69

def destroy
  task.destroy

  head :no_content
end

#indexObject

查询任务

支持的查询属性有:

name                      任务名
task_type                 任务类型
deadline                  截止时间
status                    状态
updated_at                完成时间

支持的查询操作参见 github.com/ernie/ransack/wiki/Basic-Searching

分页查询参数:

page    请求的页码,缺省值1
limit   每页记录数,缺省值25

Examples:

# 请求
GET /api/tasks?q[name_cont]=... HTTP/1.1
Accept: application/vnd.menglifang.com.cn; version=1

# 响应
HTTP/1.1 200 OK
{
  "total": ...,
  "tasks": [{
    "id": ...,
    "name": ...,
    "data": ...,
    "task_type": ...,
    "deadline": ...,
    "status": ...,
    "created_at": ...,
    "updated_at": ...,
    "assignee": {
      "id": ...,
      "name": ...
    }
  }, ...]
}


47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/task_manager/api/v1/tasks_controller.rb', line 47

def index
  tasks = TaskManager::Task.search(params[:q]).result.order('id DESC')
  result = {
    total: tasks.count,
    tasks: ActiveModel::ArraySerializer.new(
      tasks.page(params[:page]).per(params[:limit])
    ).as_json
  }

  render json: result, status: :ok
end