Skip to content

Commit

Permalink
Merge pull request #252 from tomatoes-app/remove-useless-formats
Browse files Browse the repository at this point in the history
Winter cleaning
  • Loading branch information
potomak authored Feb 4, 2017
2 parents df97812 + c06ea47 commit 062143f
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 46 deletions.
5 changes: 5 additions & 0 deletions app/controllers/api/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -31,6 +35,7 @@ def update
end
end

# DELETE /api/projects/1
def destroy
@project.destroy

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/api/tomatoes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -31,6 +35,7 @@ def update
end
end

# DELETE /api/tomatoes/1
def destroy
@tomato.destroy

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 4 additions & 15 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
21 changes: 1 addition & 20 deletions app/controllers/tomatoes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -67,7 +51,6 @@ def edit

# POST /tomatoes
# POST /tomatoes.js
# POST /tomatoes.xml
def create
@tomato = current_user.tomatoes.build(resource_params)

Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 062143f

Please sign in to comment.