diff options
author | HombreLaser <sebastian-440@live.com> | 2023-03-24 20:58:33 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-03-24 20:58:33 -0600 |
commit | ecdae3e01695e92e54d640911c5164f882ec3cf7 (patch) | |
tree | 9650dfe62fedef21ade32f83782094c25ef07b51 /app | |
parent | 1e0f07669f6bb1b6f93fb98fc0b3b7d3e2d62520 (diff) |
Arregla método update de AddressesController
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api/addresses_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/serializers/address_serializer.rb | 2 |
2 files changed, 14 insertions, 9 deletions
diff --git a/app/controllers/api/addresses_controller.rb b/app/controllers/api/addresses_controller.rb index ebe129b..110596c 100644 --- a/app/controllers/api/addresses_controller.rb +++ b/app/controllers/api/addresses_controller.rb @@ -29,14 +29,19 @@ module Api def update @service = Services::UpdateAddressService.new(current_user_account, params[:id], service_params) - case @service.call - when :not_found - render json: { error_message: 'Not found' }, status: :not_found - when :unprocessable_entity - render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity - else - @address = @service.address - render json: serialized_object.serializable_hash, status: :ok + begin + case @service.call + when :not_found + render json: { error_message: 'Not found' }, status: :not_found + when :unprocessable_entity + render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity + else + @address = @service.address + render json: serialized_object.serializable_hash, status: :ok + end + rescue ActiveRecord::RecordNotUnique + render json: { error_message: 'Ya cuenta con esta dirección' }, status: :unprocessable_entity + return end end diff --git a/app/controllers/serializers/address_serializer.rb b/app/controllers/serializers/address_serializer.rb index 0956719..d86b134 100644 --- a/app/controllers/serializers/address_serializer.rb +++ b/app/controllers/serializers/address_serializer.rb @@ -3,6 +3,6 @@ module Serializers # AddressSerializer class AddressSerializer < BaseSerializer - attributes :id, :number, :zip_code, :country, :city + attributes :id, :number, :street, :zip_code, :country, :city end end |