Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add platform API for digital_links

Matthew Kennedya97e1091105e
diff --git a/api/app/controllers/spree/api/v2/platform/digital_links_controller.rb b/api/app/controllers/spree/api/v2/platform/digital_links_controller.rb
new file mode 100644
index 0000000000..b370d4bab2
--- /dev/null
+++ b/api/app/controllers/spree/api/v2/platform/digital_links_controller.rb
@@ -0,0 +1,15 @@
+module Spree
+ module Api
+ module V2
+ module Platform
+ class DigitalLinksController < ResourceController
+ private
+
+ def model_class
+ Spree::DigitalLink
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/api/app/serializers/spree/api/v2/platform/digital_link_serializer.rb b/api/app/serializers/spree/api/v2/platform/digital_link_serializer.rb
index 5f7d615999..ed69223e0c 100644
--- a/api/app/serializers/spree/api/v2/platform/digital_link_serializer.rb
+++ b/api/app/serializers/spree/api/v2/platform/digital_link_serializer.rb
@@ -5,7 +5,7 @@ module Spree
class DigitalLinkSerializer < BaseSerializer
set_type :digital_link
- attributes :token
+ attributes :token, :access_counter
belongs_to :line_item
end
diff --git a/api/config/routes.rb b/api/config/routes.rb
index baed88f24b..1c44587253 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -297,6 +297,13 @@ Spree::Core::Engine.add_routes do
# Digitals
resources :digitals
+ # Digtal links
+ # TODO: digital_links are automaticly created, should never be deleted
+ # but should be able to be updated to reset the access_counter
+
+ # is this okay? or do you want full CRUD?
+ resources :digital_links, only: [:show, :index, :update]
+
# Store API
resources :stores
end
diff --git a/core/app/models/spree/digital_link.rb b/core/app/models/spree/digital_link.rb
index 61c12e41c9..41a84dd032 100644
--- a/core/app/models/spree/digital_link.rb
+++ b/core/app/models/spree/digital_link.rb
@@ -6,7 +6,7 @@ module Spree
belongs_to :line_item
before_validation :set_defaults, on: :create
- validates :digital, presence: true
+ validates :digital, :line_item, presence: true
def authorizable?
!(expired? || access_limit_exceeded?)
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index b37203ee78..3fb0de9dd0 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -8,6 +8,7 @@ module Spree
:cms_section_attributes,
:customer_return_attributes,
:digital_attributes,
+ :digital_link_attributes,
:image_attributes,
:inventory_unit_attributes,
:line_item_attributes,
@@ -66,6 +67,8 @@ module Spree
@@digital_attributes = [:attachment, :variant_id]
+ @@digital_link_attributes = [:access_counter]
+
@@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]
@@inventory_unit_attributes = [:shipment, :shipment_id, :variant_id]