-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create, read, update, delete paths for paperworks and separate API namespace
- Loading branch information
Showing
25 changed files
with
475 additions
and
10 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 @@ | ||
--require spec_helper |
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
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
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,3 @@ | ||
// Place all the styles related to the Paperworks controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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,58 @@ | ||
class Api::PaperworksController < ApplicationController | ||
before_action :set_paperwork, only: [:show, :update, :complete, :destroy] | ||
respond_to :json | ||
|
||
def show | ||
render json: @paperwork | ||
end | ||
|
||
def create | ||
@paperwork = Paperwork.new(paperwork_params) | ||
if @paperwork.save | ||
render json: @paperwork, status: :created | ||
else | ||
render json: { error: 'Could not create paperwork' }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @paperwork.update(paperwork_params) | ||
render json: @paperwork, status: :ok | ||
else | ||
render json: { error: 'Could not update paperwork' }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def complete | ||
if @paperwork.update(agree: true) | ||
render json: @paperwork, status: :ok | ||
else | ||
render json: { error: 'Failed to mark as agreed' }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
if @paperwork.destroy | ||
render json: @paperwork, status: :ok | ||
else | ||
render json: { error: 'Failed to delete paperwork' }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_paperwork | ||
@paperwork = Paperwork.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
render json: { error: 'Could not find paperwork' }, status: :not_found | ||
end | ||
|
||
def paperwork_params | ||
paperwork_param = params.require(:paperwork).permit(:title, | ||
:link, | ||
:agree, | ||
:participant_id) | ||
# TODO: Replace staff_id with current_omniuser | ||
paperwork_param.merge(staff_id: 1) | ||
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,19 @@ | ||
class PaperworksController < ApplicationController | ||
def index | ||
@paperworks = Paperwork.all | ||
end | ||
|
||
def show | ||
@paperwork = Paperwork.find(params[:id]) | ||
end | ||
|
||
def new | ||
@paperwork = Paperwork.new | ||
@participants = Participant.all | ||
end | ||
|
||
def edit | ||
@paperwork = Paperwork.find(params[:id]) | ||
@participants = Participant.all | ||
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,2 @@ | ||
module Api::PaperworksHelper | ||
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,2 @@ | ||
module PaperworksHelper | ||
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
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
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,6 @@ | ||
class PaperworkSerializer < ActiveModel::Serializer | ||
attributes :id, :title, :link, :agree, :staff, :participant | ||
|
||
belongs_to :staff, serializer: SimpleStaffSerializer | ||
belongs_to :participant, serializer: SimpleParticipantSerializer | ||
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,17 @@ | ||
class ParticipantSerializer < ActiveModel::Serializer | ||
attributes :id, :email, :name, :status | ||
|
||
has_many :casenotes | ||
has_many :paperworks | ||
|
||
has_one :personal_questionnaire | ||
has_one :professional_questionnaire | ||
|
||
def email | ||
object.omniuser.email | ||
end | ||
|
||
def name | ||
object.omniuser.name | ||
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,11 @@ | ||
class SimpleParticipantSerializer < ActiveModel::Serializer | ||
attributes :id, :email, :name, :status | ||
|
||
def email | ||
object.omniuser.email | ||
end | ||
|
||
def name | ||
object.omniuser.name | ||
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,11 @@ | ||
class SimpleStaffSerializer < ActiveModel::Serializer | ||
attributes :id, :email, :name | ||
|
||
def email | ||
object.omniuser.email | ||
end | ||
|
||
def name | ||
object.omniuser.name | ||
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,14 @@ | ||
class StaffSerializer < ActiveModel::Serializer | ||
attributes :id, :email, :name | ||
|
||
has_many :casenotes | ||
has_many :paperworks | ||
|
||
def email | ||
object.omniuser.email | ||
end | ||
|
||
def name | ||
object.omniuser.name | ||
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,23 @@ | ||
<h1>Edit Paperwork</h1> | ||
<%= form_with(model: @paperwork, url: api_paperwork_path, local: true) do |form| %> | ||
<p> | ||
<%= form.label :title %><br> | ||
<%= form.text_field :title %> | ||
</p> | ||
<p> | ||
<%= form.label :link %><br> | ||
<%= form.text_field :link %> | ||
</p> | ||
<p> | ||
Participant: <br> | ||
<%= form.collection_select :participant_id, @participants, :id, :name, prompt: true %> | ||
</p> | ||
<p> | ||
<%= form.label :agree %><br> | ||
<%= form.check_box :agree %> | ||
</p> | ||
<p> | ||
<%= form.submit %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Back', paperworks_path %> |
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,25 @@ | ||
<h1>All Paperworks</h1> | ||
<table> | ||
<tr> | ||
<th>Title</th> | ||
<th>Link</th> | ||
<th>Participant</th> | ||
<th>Agree</th> | ||
<th colspan="3"></th> | ||
</tr> | ||
|
||
<% @paperworks.each do |paperwork| %> | ||
<tr> | ||
<td><%= paperwork.title %></td> | ||
<td><%= paperwork.link %></td> | ||
<td><%= paperwork.participant.name %></td> | ||
<td><%= paperwork.agree %></td> | ||
<td><%= link_to 'Show', paperwork_path(paperwork) %></td> | ||
<td><%= link_to 'Edit', edit_paperwork_path(paperwork) %></td> | ||
<td><%= link_to 'Delete', api_paperwork_path(paperwork), | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
<%= link_to 'New Paperwork', new_paperwork_path %> |
Oops, something went wrong.