Skip to content

Commit

Permalink
Merge fe0f745 into 63eb9aa
Browse files Browse the repository at this point in the history
  • Loading branch information
cesswairimu committed May 20, 2020
2 parents 63eb9aa + fe0f745 commit 24e8a24
Show file tree
Hide file tree
Showing 12 changed files with 712 additions and 9 deletions.
47 changes: 47 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

class ProjectsController < ApplicationController
before_action :find_project, only: %i[update destroy show]

def create
@project = Project.create(project_params)

if @project.save
render json: @project, status: :created
else
render json: @project.errors, status: :unprocessable_entity
end
end

def index
@projects = Project.all
render json: @projects, status: :ok
end

def update
if @project.update(project_params)
render json: @project, status: :ok
else
render json: @project.errors, status: :unprocessable_entity
end
end

def show
render json: @project
end

def destroy
@project.destroy
head 204
end

private

def find_project
@project = Project.find(params[:id])
end

def project_params
params.require(:project).permit(:title, :description, :image_url, :status, :github_url, :issue_tracker, :slack_channel_title)
end
end
7 changes: 7 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class Project < ApplicationRecord
validates_presence_of :status, presence: true
validates_presence_of :description, presence: true
validates_presence_of :title, presence: true
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

resources :events, only: %w[index create update show destroy]
resources :projects
end

0 comments on commit 24e8a24

Please sign in to comment.