diff --git a/app/blueprints/api/v1/party_share_blueprint.rb b/app/blueprints/api/v1/party_share_blueprint.rb new file mode 100644 index 0000000..4bbc73d --- /dev/null +++ b/app/blueprints/api/v1/party_share_blueprint.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Api + module V1 + class PartyShareBlueprint < ApiBlueprint + identifier :id + + fields :created_at + + field :shareable_type do |share| + share.shareable_type.downcase + end + + field :shareable_id do |share| + share.shareable_id + end + + view :with_shareable do + fields :created_at + + field :shareable_type do |share| + share.shareable_type.downcase + end + + field :shareable do |share| + case share.shareable_type + when 'Crew' + CrewBlueprint.render_as_hash(share.shareable, view: :minimal) + end + end + + field :shared_by do |share| + UserBlueprint.render_as_hash(share.shared_by, view: :minimal) + end + end + + view :with_party do + fields :created_at + + field :shareable_type do |share| + share.shareable_type.downcase + end + + field :party do |share| + PartyBlueprint.render_as_hash(share.party, view: :preview) + end + + field :shareable do |share| + case share.shareable_type + when 'Crew' + CrewBlueprint.render_as_hash(share.shareable, view: :minimal) + end + end + end + end + end +end diff --git a/app/errors/party_share_errors.rb b/app/errors/party_share_errors.rb new file mode 100644 index 0000000..a2f591c --- /dev/null +++ b/app/errors/party_share_errors.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +module PartyShareErrors + # Base class for all party share-related errors + class PartyShareError < StandardError + def http_status + :unprocessable_entity + end + + def code + self.class.name.demodulize.underscore + end + + def to_hash + { + message: message, + code: code + } + end + end + + class NotInCrewError < PartyShareError + def http_status + :unprocessable_entity + end + + def code + 'not_in_crew' + end + + def message + 'You must be in a crew to share parties' + end + end + + class NotPartyOwnerError < PartyShareError + def http_status + :forbidden + end + + def code + 'not_party_owner' + end + + def message + 'Only the party owner can share this party' + end + end + + class AlreadySharedError < PartyShareError + def http_status + :conflict + end + + def code + 'already_shared' + end + + def message + 'This party is already shared with this crew' + end + end + + class CanOnlyShareToOwnCrewError < PartyShareError + def http_status + :forbidden + end + + def code + 'can_only_share_to_own_crew' + end + + def message + 'You can only share parties with your own crew' + end + end +end