summaryrefslogtreecommitdiff
path: root/app/serializers
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-01 12:00:33 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-01 12:00:33 -0600
commit753bf8499ba5d8815db8d08a1dcf69caa20660cf (patch)
treec758e18e3009f9c6da002164686e88956430847b /app/serializers
parent64214e370778dc3efdaca85acd0cd7a569a79b81 (diff)
Mejora estructura del proyecto
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/address_serializer.rb6
-rw-r--r--app/serializers/base_serializer.rb6
-rw-r--r--app/serializers/card_serializer.rb6
-rw-r--r--app/serializers/company_serializer.rb12
-rw-r--r--app/serializers/product_serializer.rb17
-rw-r--r--app/serializers/user_account_serializer.rb6
6 files changed, 53 insertions, 0 deletions
diff --git a/app/serializers/address_serializer.rb b/app/serializers/address_serializer.rb
new file mode 100644
index 0000000..3d51613
--- /dev/null
+++ b/app/serializers/address_serializer.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+# AddressSerializer
+class AddressSerializer < BaseSerializer
+ attributes :id, :number, :street, :zip_code, :country, :city
+end
diff --git a/app/serializers/base_serializer.rb b/app/serializers/base_serializer.rb
new file mode 100644
index 0000000..856e5b4
--- /dev/null
+++ b/app/serializers/base_serializer.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+# The father class of all serializers.
+class BaseSerializer
+ include JSONAPI::Serializer
+end
diff --git a/app/serializers/card_serializer.rb b/app/serializers/card_serializer.rb
new file mode 100644
index 0000000..3925b94
--- /dev/null
+++ b/app/serializers/card_serializer.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+# CardSerializer
+class CardSerializer < BaseSerializer
+ attributes :id, :number, :expiration_year, :expiration_month, :expiration_day, :security_code
+end
diff --git a/app/serializers/company_serializer.rb b/app/serializers/company_serializer.rb
new file mode 100644
index 0000000..1c754ee
--- /dev/null
+++ b/app/serializers/company_serializer.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+# CompanySerializer
+class CompanySerializer < BaseSerializer
+ extend ActionView::RoutingUrlFor
+
+ attributes :id, :name, :country, :short_name
+
+ attribute :logo do |object|
+ object.logo.url
+ end
+end
diff --git a/app/serializers/product_serializer.rb b/app/serializers/product_serializer.rb
new file mode 100644
index 0000000..ab23d01
--- /dev/null
+++ b/app/serializers/product_serializer.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+# ProductSerializer
+class ProductSerializer < BaseSerializer
+ include Rails.application.routes.url_helpers
+ extend ActionView::RoutingUrlFor
+
+ attributes :name, :public_id, :unitary_price, :bulk_price, :available_quantity, :categories
+
+ attribute :picture do |object|
+ object.picture.url
+ end
+
+ attribute :company do |object|
+ { name: object.company_name, short_name: object.company_short_name }
+ end
+end
diff --git a/app/serializers/user_account_serializer.rb b/app/serializers/user_account_serializer.rb
new file mode 100644
index 0000000..aae0594
--- /dev/null
+++ b/app/serializers/user_account_serializer.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+# The serializer for the user account model.
+class UserAccountSerializer < BaseSerializer
+ attributes :email, :first_name, :last_name, :role
+end