add party share errors and blueprint

This commit is contained in:
Justin Edmund 2026-01-04 21:47:07 -08:00
parent 329f86df20
commit d09d370212
2 changed files with 134 additions and 0 deletions

View file

@ -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

View file

@ -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