2013-05-14 08:33:31 -04:00
|
|
|
module API
|
2012-08-16 14:51:31 -04:00
|
|
|
# Milestones API
|
|
|
|
class Milestones < Grape::API
|
|
|
|
before { authenticate! }
|
|
|
|
|
|
|
|
resource :projects do
|
|
|
|
# Get a list of project milestones
|
|
|
|
#
|
|
|
|
# Parameters:
|
2012-12-21 12:47:04 -05:00
|
|
|
# id (required) - The ID of a project
|
2012-08-16 14:51:31 -04:00
|
|
|
# Example Request:
|
|
|
|
# GET /projects/:id/milestones
|
|
|
|
get ":id/milestones" do
|
2012-09-21 06:22:30 -04:00
|
|
|
authorize! :read_milestone, user_project
|
|
|
|
|
2012-09-03 07:46:29 -04:00
|
|
|
present paginate(user_project.milestones), with: Entities::Milestone
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Get a single project milestone
|
|
|
|
#
|
|
|
|
# Parameters:
|
2012-12-21 12:47:04 -05:00
|
|
|
# id (required) - The ID of a project
|
2012-08-16 14:51:31 -04:00
|
|
|
# milestone_id (required) - The ID of a project milestone
|
|
|
|
# Example Request:
|
|
|
|
# GET /projects/:id/milestones/:milestone_id
|
|
|
|
get ":id/milestones/:milestone_id" do
|
2012-09-21 06:22:30 -04:00
|
|
|
authorize! :read_milestone, user_project
|
|
|
|
|
2012-08-16 14:51:31 -04:00
|
|
|
@milestone = user_project.milestones.find(params[:milestone_id])
|
|
|
|
present @milestone, with: Entities::Milestone
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create a new project milestone
|
|
|
|
#
|
|
|
|
# Parameters:
|
2012-12-21 12:47:04 -05:00
|
|
|
# id (required) - The ID of the project
|
2012-08-16 14:51:31 -04:00
|
|
|
# title (required) - The title of the milestone
|
|
|
|
# description (optional) - The description of the milestone
|
|
|
|
# due_date (optional) - The due date of the milestone
|
|
|
|
# Example Request:
|
|
|
|
# POST /projects/:id/milestones
|
|
|
|
post ":id/milestones" do
|
2012-09-21 06:22:30 -04:00
|
|
|
authorize! :admin_milestone, user_project
|
2013-02-27 11:50:30 -05:00
|
|
|
required_attributes! [:title]
|
2013-02-20 16:51:59 -05:00
|
|
|
|
2012-09-16 13:08:57 -04:00
|
|
|
attrs = attributes_for_keys [:title, :description, :due_date]
|
2012-09-16 12:51:04 -04:00
|
|
|
@milestone = user_project.milestones.new attrs
|
2012-08-16 14:51:31 -04:00
|
|
|
if @milestone.save
|
|
|
|
present @milestone, with: Entities::Milestone
|
|
|
|
else
|
2012-09-10 03:41:46 -04:00
|
|
|
not_found!
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Update an existing project milestone
|
|
|
|
#
|
|
|
|
# Parameters:
|
2012-12-21 12:47:04 -05:00
|
|
|
# id (required) - The ID of a project
|
2012-08-29 08:45:00 -04:00
|
|
|
# milestone_id (required) - The ID of a project milestone
|
2012-08-16 14:51:31 -04:00
|
|
|
# title (optional) - The title of a milestone
|
|
|
|
# description (optional) - The description of a milestone
|
|
|
|
# due_date (optional) - The due date of a milestone
|
2013-02-18 04:10:09 -05:00
|
|
|
# state (optional) - The status of the milestone (close|activate)
|
2012-08-16 14:51:31 -04:00
|
|
|
# Example Request:
|
|
|
|
# PUT /projects/:id/milestones/:milestone_id
|
|
|
|
put ":id/milestones/:milestone_id" do
|
2012-09-10 02:06:11 -04:00
|
|
|
authorize! :admin_milestone, user_project
|
|
|
|
|
2012-08-16 14:51:31 -04:00
|
|
|
@milestone = user_project.milestones.find(params[:milestone_id])
|
2013-02-18 04:10:09 -05:00
|
|
|
attrs = attributes_for_keys [:title, :description, :due_date, :state_event]
|
2012-09-16 12:51:04 -04:00
|
|
|
if @milestone.update_attributes attrs
|
2012-08-16 14:51:31 -04:00
|
|
|
present @milestone, with: Entities::Milestone
|
|
|
|
else
|
2012-09-10 03:41:46 -04:00
|
|
|
not_found!
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|