-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
712 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.