summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api/companies_controller.rb18
-rw-r--r--app/controllers/application_controller.rb4
-rw-r--r--app/controllers/authenticated_controller.rb2
-rw-r--r--app/controllers/serializers/company_serializer.rb4
-rw-r--r--config/routes.rb2
-rw-r--r--config/storage.yml4
6 files changed, 28 insertions, 6 deletions
diff --git a/app/controllers/api/companies_controller.rb b/app/controllers/api/companies_controller.rb
index 4317682..9d6cb1c 100644
--- a/app/controllers/api/companies_controller.rb
+++ b/app/controllers/api/companies_controller.rb
@@ -17,7 +17,7 @@ module Api
render json: serialized_object.serializable_hash, status: :ok and return if @company
- render json: { error_message: "No se encontró la compañía #{params[:short_name]}" }, status: :not_found
+ render json: not_found_error_message, status: :not_found
end
def create
@@ -28,6 +28,18 @@ module Api
render json: { error_messages: @company.errors.full_messages }, status: :unprocessable_entity
end
+ def update
+ @company = Company.find_by(short_name: params[:id])
+
+ render json: not_found_error_message, status: :not_found and return if @company.nil?
+
+ if @company.update(permitted_params)
+ render json: serialized_object.serializable_hash, status: :ok
+ else
+ render json: { error_messages: @company.errors.full_messages }, status: :unprocessable_entity
+ end
+ end
+
private
def serialized_object
@@ -41,5 +53,9 @@ module Api
def permitted_params
params.permit(:name, :country, :short_name, :logo)
end
+
+ def not_found_error_message
+ { error_message: "No se encontró la compañía #{params[:short_name]}"}
+ end
end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7f803c8..4fc614c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,6 +2,10 @@
# The father class of all controllers.
class ApplicationController < ActionController::API
+ before_action do
+ ActiveStorage::Current.url_options = { protocol: request.protocol, host: request.host, port: request.port }
+ end
+
def logic(permitted_params)
@logic = Object.const_get("#{self.class}::#{action_name.camelize}Logic").new(permitted_params)
end
diff --git a/app/controllers/authenticated_controller.rb b/app/controllers/authenticated_controller.rb
index 7098202..de02cab 100644
--- a/app/controllers/authenticated_controller.rb
+++ b/app/controllers/authenticated_controller.rb
@@ -19,7 +19,7 @@ class AuthenticatedController < ApplicationController
def decoded_token
@decoded_token ||= JWT.decode(authentication_token, ENV['HMAC_SECRET_KEY'], true, { algorithm: 'HS512' })
- rescue JWT::ExpiredSignature
+ rescue JWT::ExpiredSignature, JWT::DecodeError
@decoded_token = nil
end
diff --git a/app/controllers/serializers/company_serializer.rb b/app/controllers/serializers/company_serializer.rb
index ec3f200..d211e9e 100644
--- a/app/controllers/serializers/company_serializer.rb
+++ b/app/controllers/serializers/company_serializer.rb
@@ -3,10 +3,12 @@
module Serializers
# CompanySerializer
class CompanySerializer < BaseSerializer
+ extend ActionView::RoutingUrlFor
+
attributes :id, :name, :country, :short_name
attribute :logo do |object|
- url_for(object.logo)
+ object.logo.url
end
end
end
diff --git a/config/routes.rb b/config/routes.rb
index b74623a..0237992 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -9,7 +9,7 @@ Rails.application.routes.draw do
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
get '/account', to: 'user_accounts#show'
- resources :companies, only: %i[index show create]
+ resources :companies, only: %i[index show create update]
resources :user_accounts, only: %i[create]
resources :refresh_tokens, only: %i[create]
end
diff --git a/config/storage.yml b/config/storage.yml
index 077b15d..4df6bf7 100644
--- a/config/storage.yml
+++ b/config/storage.yml
@@ -1,7 +1,7 @@
local:
service: Disk
- #root: <%= Rails.root.join("storage") %>
+ root: ./storage
test:
service: Disk
- root: <%= Rails.root.join("tmp/storage") %> \ No newline at end of file
+ root: ./tmp/storage \ No newline at end of file