Skip to content

Commit

Permalink
Add Tasks and Milestones: Graphiti API
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Richmond committed Mar 31, 2019
1 parent 904d7fe commit e2eb4eb
Show file tree
Hide file tree
Showing 25 changed files with 1,173 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/controllers/milestones_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class MilestonesController < ApplicationController
def index
milestones = MilestoneResource.all(params)
respond_with(milestones)
end

def show
milestone = MilestoneResource.find(params)
respond_with(milestone)
end

def create
milestone = MilestoneResource.build(params)

if milestone.save
render jsonapi: milestone, status: 201
else
render jsonapi_errors: milestone
end
end

def update
milestone = MilestoneResource.find(params)

if milestone.update_attributes
render jsonapi: milestone
else
render jsonapi_errors: milestone
end
end

def destroy
milestone = MilestoneResource.find(params)

if milestone.destroy
render jsonapi: { meta: {} }, status: 200
else
render jsonapi_errors: milestone
end
end
end
41 changes: 41 additions & 0 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class TasksController < ApplicationController
def index
tasks = TaskResource.all(params)
respond_with(tasks)
end

def show
task = TaskResource.find(params)
respond_with(task)
end

def create
task = TaskResource.build(params)

if task.save
render jsonapi: task, status: 201
else
render jsonapi_errors: task
end
end

def update
task = TaskResource.find(params)

if task.update_attributes
render jsonapi: task
else
render jsonapi_errors: task
end
end

def destroy
task = TaskResource.find(params)

if task.destroy
render jsonapi: { meta: {} }, status: 200
else
render jsonapi_errors: task
end
end
end
2 changes: 2 additions & 0 deletions app/resources/bug_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class BugResource < TaskResource
end
1 change: 1 addition & 0 deletions app/resources/employee_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class EmployeeResource < ApplicationResource
attribute :title, :string, only: [:filterable, :sortable]

has_many :positions
has_many :tasks
many_to_many :teams
polymorphic_has_many :notes, as: :notable
has_one :current_position, resource: PositionResource do
Expand Down
3 changes: 3 additions & 0 deletions app/resources/epic_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class EpicResource < TaskResource
has_many :milestones
end
5 changes: 5 additions & 0 deletions app/resources/feature_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FeatureResource < TaskResource
attribute :points, :integer do
rand(20)
end
end
11 changes: 11 additions & 0 deletions app/resources/milestone_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class MilestoneResource < ApplicationResource
attribute :epic_id, :integer, only: [:filterable]
attribute :name, :string

belongs_to :epic do
link do |milestone|
helpers = Rails.application.routes.url_helpers
helpers.task_url(milestone.epic_id)
end
end
end
10 changes: 10 additions & 0 deletions app/resources/task_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class TaskResource < ApplicationResource
self.polymorphic = %w(FeatureResource BugResource EpicResource)

attribute :employee_id, :integer, only: [:filterable]
attribute :team_id, :integer, only: [:filterable]
attribute :title, :string

belongs_to :employee
belongs_to :team
end
1 change: 1 addition & 0 deletions app/resources/team_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ class TeamResource < ApplicationResource

belongs_to :department
many_to_many :employees
has_many :tasks
polymorphic_has_many :notes, as: :notable
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Rails.application.routes.draw do
scope path: ApplicationResource.endpoint_namespace, defaults: { format: :jsonapi } do
resources :milestones
resources :tasks
resources :notes
resources :teams
resources :departments
Expand Down
Loading

0 comments on commit e2eb4eb

Please sign in to comment.