Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Service api integration #8

Merged
merged 6 commits into from
This page is out of date. Refresh to see the latest.
View
66 README.md
@@ -9,34 +9,44 @@ Panex Web API
``` bash
- patients GET /patients(.:format) patients#index
- POST /patients(.:format) patients#create
- new_patient GET /patients/new(.:format) patients#new
- edit_patient GET /patients/:id/edit(.:format) patients#edit
- patient GET /patients/:id(.:format) patients#show
- PUT /patients/:id(.:format) patients#update
- DELETE /patients/:id(.:format) patients#destroy
- new_user_session GET /users/sign_in(.:format) sessions#new
- user_session POST /users/sign_in(.:format) sessions#create
- destroy_user_session DELETE /users/sign_out(.:format) sessions#destroy
- user_password POST /users/password(.:format) devise/passwords#create
- new_user_password GET /users/password/new(.:format) devise/passwords#new
- edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
- PUT /users/password(.:format) devise/passwords#update
-cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
- user_registration POST /users(.:format) devise/registrations#create
- new_user_registration GET /users/sign_up(.:format) devise/registrations#new
- edit_user_registration GET /users/edit(.:format) devise/registrations#edit
- PUT /users(.:format) devise/registrations#update
- DELETE /users(.:format) devise/registrations#destroy
- users GET /users(.:format) users#index
- POST /users(.:format) users#create
- new_user GET /users/new(.:format) users#new
- edit_user GET /users/:id/edit(.:format) users#edit
- user GET /users/:id(.:format) users#show
- PUT /users/:id(.:format) users#update
- DELETE /users/:id(.:format) users#destroy
- root / home#index
+ patients GET /patients(.:format) patients#index
+ POST /patients(.:format) patients#create
+ new_patient GET /patients/new(.:format) patients#new
+ edit_patient GET /patients/:id/edit(.:format) patients#edit
+ patient GET /patients/:id(.:format) patients#show
+ PUT /patients/:id(.:format) patients#update
+ DELETE /patients/:id(.:format) patients#destroy
+ apps GET /apps(.:format) apps#index
+ app GET /apps/:id(.:format) apps#show
+ services GET /services(.:format) services#index
+ service GET /services/:id(.:format) services#show
+ new_user_session GET /users/sign_in(.:format) sessions#new
+ user_session POST /users/sign_in(.:format) sessions#create
+ destroy_user_session DELETE /users/sign_out(.:format) sessions#destroy
+ user_password POST /users/password(.:format) devise/passwords#create
+ new_user_password GET /users/password/new(.:format) devise/passwords#new
+ edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
+ PUT /users/password(.:format) devise/passwords#update
+cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
+ user_registration POST /users(.:format) devise/registrations#create
+ new_user_registration GET /users/sign_up(.:format) devise/registrations#new
+ edit_user_registration GET /users/edit(.:format) devise/registrations#edit
+ PUT /users(.:format) devise/registrations#update
+ DELETE /users(.:format) devise/registrations#destroy
+ user_apps POST /users/:user_id/apps(.:format) apps#create
+ user_app PUT /users/:user_id/apps/:id(.:format) apps#update
+ DELETE /users/:user_id/apps/:id(.:format) apps#destroy
+ user_services POST /users/:user_id/services(.:format) services#create
+ user_service PUT /users/:user_id/services/:id(.:format) services#update
+ DELETE /users/:user_id/services/:id(.:format) services#destroy
+ users GET /users(.:format) users#index
+ POST /users(.:format) users#create
+ new_user GET /users/new(.:format) users#new
+ edit_user GET /users/:id/edit(.:format) users#edit
+ user GET /users/:id(.:format) users#show
+ PUT /users/:id(.:format) users#update
+ DELETE /users/:id(.:format) users#destroy
+ root / home#index
```
View
94 app/controllers/services_controller.rb
@@ -0,0 +1,94 @@
+class ServicesController < ApplicationController
+ include ServicesHelper
+ # GET /services
+ # GET /services.json
+ def index
+ @services = Service.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @services }
+ end
+ end
+
+ # GET /services/1
+ # GET /services/1.json
+ def show
+ @service = Service.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @service }
+ end
+ end
+
+ # GET /services/new
+ # GET /services/new.json
+ def new
+ @service = Service.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @service }
+ end
+ end
+
+ # GET /services/1/edit
+ def edit
+ @service = Service.find(params[:id])
+ end
+
+ # POST /services
+ # POST /services.json
+ def create
+ service_data = {
+ :name => params[:name],
+ :description => params[:description],
+ :thumbnail => params[:thumbnail],
+ :helpLink => params[:helpLink],
+ :version => params[:version],
+ :creator_id => params[:user_id],
+ :serviceFile => params[:serviceFile],
+ :commandLine => params[:commandLine]
+ }
+ @service = Service.new(service_data)
+
+ respond_to do |format|
+ if @service.save
+ format.html { redirect_to @service, notice: 'Service was successfully created.' }
+ format.json { render json: @service, status: :created, location: @service }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @service.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /services/1
+ # PUT /services/1.json
+ def update
+ @service = Service.find(params[:id])
+
+ respond_to do |format|
+ if @service.update_attributes(params[:service])
+ format.html { redirect_to @service, notice: 'Service was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @service.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /services/1
+ # DELETE /services/1.json
+ def destroy
+ @service = Service.find(params[:id])
+ @service.destroy
+
+ respond_to do |format|
+ format.html { redirect_to services_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2  app/helpers/services_helper.rb
@@ -0,0 +1,2 @@
+module ServicesHelper
+end
View
10 app/models/service.rb
@@ -0,0 +1,10 @@
+class Service < ActiveRecord::Base
+ belongs_to :creator, :class_name => "User"
+ attr_accessible :creator_id, :description, :helpLink, :name, :version, :thumbnail, :serviceFile, :commandLine
+
+ has_attached_file :thumbnail,
+ :styles => { :medium => "300x300>", :thumb => "100x100>" },
+ :default_url => "/images/:style/missing.png"
+
+ has_attached_file :serviceFile
+end
View
4 app/models/user.rb
@@ -14,5 +14,7 @@ class User < ActiveRecord::Base
VALID_EMAIL_REGEX = /\A[A-Z0-9._%+\-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,6}\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }
- has_many :apps #, :foreign_key => "user_id" #used when wanting to a diff foriegn_key
+ has_many :apps #, :foreign_key => "user_id" #used when wanting to a diff foreign_key
+
+ has_many :services , :foreign_key => "creator_id"
end
View
17 app/views/services/_form.html.erb
@@ -0,0 +1,17 @@
+<%= form_for(@service) do |f| %>
+ <% if @service.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@service.errors.count, "error") %> prohibited this service from being saved:</h2>
+
+ <ul>
+ <% @service.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/services/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing service</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @service %> |
+<%= link_to 'Back', services_path %>
View
21 app/views/services/index.html.erb
@@ -0,0 +1,21 @@
+<h1>Listing services</h1>
+
+<table>
+ <tr>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @services.each do |service| %>
+ <tr>
+ <td><%= link_to 'Show', service %></td>
+ <td><%= link_to 'Edit', edit_service_path(service) %></td>
+ <td><%= link_to 'Destroy', service, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Service', new_service_path %>
View
5 app/views/services/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New service</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', services_path %>
View
5 app/views/services/show.html.erb
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_service_path(@service) %> |
+<%= link_to 'Back', services_path %>
View
2  config/routes.rb
@@ -3,12 +3,14 @@
resources :patients
resources :apps, :only => [:index, :show]
+ resources :services, :only => [:index, :show]
devise_for(:users, :controllers => { :sessions => "sessions" })
resources :users do
resources :apps, :only => [:create, :update, :destroy]
+ resources :services, :only => [:create, :update, :destroy]
end
root :to => "home#index"
View
13 db/migrate/20130320182036_create_services.rb
@@ -0,0 +1,13 @@
+class CreateServices < ActiveRecord::Migration
+ def change
+ create_table :services do |t|
+ t.string :name
+ t.string :description
+ t.integer :creator_id
+ t.string :version
+ t.string :helpLink
+
+ t.timestamps
+ end
+ end
+end
View
6 db/migrate/20130320182146_add_thumbnail_and_service_file_to_service.rb
@@ -0,0 +1,6 @@
+class AddThumbnailAndServiceFileToService < ActiveRecord::Migration
+ def change
+ add_attachment :services, :serviceFile
+ add_attachment :services, :thumbnail
+ end
+end
View
7 db/migrate/20130320184516_add_command_line_to_service.rb
@@ -0,0 +1,7 @@
+class AddCommandLineToService < ActiveRecord::Migration
+ def change
+ change_table :services do |t|
+ t.string :commandLine, :null => false, :default => ""
+ end
+ end
+end
View
21 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130319152734) do
+ActiveRecord::Schema.define(:version => 20130320184516) do
create_table "apps", :force => true do |t|
t.string "name"
@@ -51,6 +51,25 @@
add_index "patients", ["identificationNumber"], :name => "index_patients_on_identificationNumber", :unique => true
add_index "patients", ["lastName"], :name => "index_patients_on_lastName"
+ create_table "services", :force => true do |t|
+ t.string "name"
+ t.string "description"
+ t.integer "creator_id"
+ t.string "version"
+ t.string "helpLink"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "serviceFile_file_name"
+ t.string "serviceFile_content_type"
+ t.integer "serviceFile_file_size"
+ t.datetime "serviceFile_updated_at"
+ t.string "thumbnail_file_name"
+ t.string "thumbnail_content_type"
+ t.integer "thumbnail_file_size"
+ t.datetime "thumbnail_updated_at"
+ t.string "commandLine", :default => "", :null => false
+ end
+
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
View
15 test/fixtures/services.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ description: MyString
+ creator_id: 1
+ version: MyString
+ helpLink: MyString
+
+two:
+ name: MyString
+ description: MyString
+ creator_id: 1
+ version: MyString
+ helpLink: MyString
View
49 test/functional/services_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ServicesControllerTest < ActionController::TestCase
+ setup do
+ @service = services(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:services)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create service" do
+ assert_difference('Service.count') do
+ post :create, service: { }
+ end
+
+ assert_redirected_to service_path(assigns(:service))
+ end
+
+ test "should show service" do
+ get :show, id: @service
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @service
+ assert_response :success
+ end
+
+ test "should update service" do
+ put :update, id: @service, service: { }
+ assert_redirected_to service_path(assigns(:service))
+ end
+
+ test "should destroy service" do
+ assert_difference('Service.count', -1) do
+ delete :destroy, id: @service
+ end
+
+ assert_redirected_to services_path
+ end
+end
View
4 test/unit/helpers/services_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ServicesHelperTest < ActionView::TestCase
+end
View
7 test/unit/service_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ServiceTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Something went wrong with that request. Please try again.