diff --git a/app/controllers/api/projects_controller.rb b/app/controllers/api/projects_controller.rb index 023f303b..6f3a30c0 100644 --- a/app/controllers/api/projects_controller.rb +++ b/app/controllers/api/projects_controller.rb @@ -3,16 +3,19 @@ class ProjectsController < BaseController before_action :authenticate_user! before_action :find_project, only: [:show, :update, :destroy] + # GET /api/projects def index @projects = current_user.projects.order_by([[:created_at, :desc], [:_id, :desc]]).page params[:page] render json: Presenter::Projects.new(@projects) end + # GET /api/projects/1 def show render json: Presenter::Project.new(@project) end + # POST /api/projects def create @project = current_user.projects.build(resource_params) @@ -23,6 +26,7 @@ def create end end + # POST /api/projects def update if @project.update_attributes(resource_params) render json: Presenter::Project.new(@project), location: api_project_url(@project) @@ -31,6 +35,7 @@ def update end end + # DELETE /api/projects/1 def destroy @project.destroy diff --git a/app/controllers/api/sessions_controller.rb b/app/controllers/api/sessions_controller.rb index 91f4bcea..028c51ad 100644 --- a/app/controllers/api/sessions_controller.rb +++ b/app/controllers/api/sessions_controller.rb @@ -2,7 +2,7 @@ module Api class SessionsController < BaseController before_action :authenticate_user!, only: :destroy - # POST /session + # POST /api/session def create auth_provider = AuthFactory.build(params) user = auth_provider.find_user @@ -19,7 +19,7 @@ def create unauthorized 'authentication failed' end - # DELETE /session + # DELETE /api/session def destroy @current_user.authorizations.where(provider: 'tomatoes').destroy_all diff --git a/app/controllers/api/tomatoes_controller.rb b/app/controllers/api/tomatoes_controller.rb index 62295612..09128953 100644 --- a/app/controllers/api/tomatoes_controller.rb +++ b/app/controllers/api/tomatoes_controller.rb @@ -3,16 +3,19 @@ class TomatoesController < BaseController before_action :authenticate_user! before_action :find_tomato, only: [:show, :update, :destroy] + # GET /api/tomatoes def index @tomatoes = current_user.tomatoes.order_by([[:created_at, :desc], [:_id, :desc]]).page params[:page] render json: Presenter::Tomatoes.new(@tomatoes) end + # GET /api/tomatoes/1 def show render json: Presenter::Tomato.new(@tomato) end + # POST /api/tomatoes def create @tomato = current_user.tomatoes.build(resource_params) @@ -23,6 +26,7 @@ def create end end + # PUT /api/tomatoes/1 def update if @tomato.update_attributes(resource_params) render json: Presenter::Tomato.new(@tomato), location: api_tomato_url(@tomato) @@ -31,6 +35,7 @@ def update end end + # DELETE /api/tomatoes/1 def destroy @tomato.destroy diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index f3e4c3ba..1577d187 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -2,10 +2,12 @@ module Api class UsersController < BaseController before_action :authenticate_user! + # GET /api/user def show render json: Presenter::User.new(current_user) end + # PUT /api/user def update if current_user.update_attributes(resource_params) render json: Presenter::User.new(current_user), location: api_user_url diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dfaac844..d8edc017 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,10 +13,6 @@ def respond_with_json end end - def not_found - raise ActionController::RoutingError.new('Not found') - end - private def set_time_zone diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index eac07d58..60482545 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -3,14 +3,8 @@ class ProjectsController < ApplicationController before_action :find_project, only: [:show, :edit, :update, :destroy] # GET /projects - # GET /projects.json def index @projects = current_user.projects.order_by([[:created_at, :desc]]).page params[:page] - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @projects } - end end # GET /projects/1 @@ -27,18 +21,13 @@ def edit end # POST /projects - # POST /projects.json def create @project = current_user.projects.build(resource_params) - respond_to do |format| - if @project.save - format.html { redirect_to @project, notice: 'Project was successfully created.' } - format.json { render json: @project, status: :created, location: @project } - else - format.html { render action: 'new' } - format.json { render json: @project.errors, status: :unprocessable_entity } - end + if @project.save + redirect_to @project, notice: 'Project was successfully created.' + else + render action: 'new' end end diff --git a/app/controllers/tomatoes_controller.rb b/app/controllers/tomatoes_controller.rb index 02fa2319..ecd500b5 100644 --- a/app/controllers/tomatoes_controller.rb +++ b/app/controllers/tomatoes_controller.rb @@ -4,18 +4,13 @@ class TomatoesController < ApplicationController before_action :find_tomato, only: [:show, :edit, :update, :destroy] # GET /tomatoes - # GET /tomatoes.xml # GET /tomatoes.csv - # GET /users/1/tomatoes - # GET /users/1/tomatoes.xml - # GET /users/1/tomatoes.csv def index @tomatoes = current_user.tomatoes.order_by([[:created_at, :desc]]).page params[:page] respond_to do |format| format.html # index.html.erb - format.xml { render xml: @tomatoes } - format.csv { export_csv(current_user.tomatoes.order_by([[:created_at, :desc]])) } + format.csv { export_csv(current_user.tomatoes.order_by([[:created_at, :desc]])) } end end @@ -42,23 +37,12 @@ def by_hour end # GET /tomatoes/1 - # GET /tomatoes/1.json def show - respond_to do |format| - format.html # show.html.erb - format.json { render json: @tomato } - end end # GET /tomatoes/new - # GET /tomatoes/new.json def new @tomato = current_user.tomatoes.build - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @tomato } - end end # GET /tomatoes/1/edit @@ -67,7 +51,6 @@ def edit # POST /tomatoes # POST /tomatoes.js - # POST /tomatoes.xml def create @tomato = current_user.tomatoes.build(resource_params) @@ -83,11 +66,9 @@ def create flash.now[:notice] = notice_message end format.html { redirect_to(root_url, notice: 'Tomato created, now it\'s time for a break.') } - format.xml { render xml: @tomato, status: :created, location: @tomato } else # TODO: error format.js format.html { render action: 'new' } - format.xml { render xml: @tomato.errors, status: :unprocessable_entity } end end end diff --git a/config/routes.rb b/config/routes.rb index c55e17e1..266acd0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,11 +36,7 @@ resource :overall, only: :show end - resources :tomatoes do - member do - post 'track' - end - end + resources :tomatoes resources :users, only: [:show, :edit, :update, :destroy] do resources :tomatoes, only: [] do