Skip to content

Commit

Permalink
send voting percentage to serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed Oct 12, 2024
1 parent f44cf42 commit f77f1df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/shrimpos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create

def show
shrimpo = Shrimpo.friendly.find params[:id]
render json: shrimpo, include: ['shrimpo_entries', 'posts', 'shrimpo_entries.trophy_awards', 'shrimpo_voting_categories']
render json: shrimpo, serializer: ShrimpoSerializer, current_user: current_user, include: ['shrimpo_entries', 'posts', 'shrimpo_entries.trophy_awards', 'shrimpo_voting_categories']
end

private
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/shrimpo_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
class ShrimpoSerializer < ActiveModel::Serializer
attributes :title, :rule_pack, :start_at, :end_at, :status, :zip_file_url, :shrimpo_entries, :slug, :emoji, :cover_art_url, :ended_at, :duration, :username, :user_avatar, :entries_count, :entries_zip_file_url, :shrimpo_type
attributes :title, :rule_pack, :start_at, :end_at, :status, :zip_file_url, :shrimpo_entries, :slug, :emoji, :cover_art_url, :ended_at, :duration, :username, :user_avatar, :entries_count, :entries_zip_file_url, :shrimpo_type, :voting_completion_percentage
has_many :shrimpo_entries, embed: :ids, key: :shrimpo_entries, embed_in_root: true, each_serializer: ShrimpoEntrySerializer
has_many :posts, embed: :ids, key: :posts, embed_in_root: true, each_serializer: PostSerializer
has_many :shrimpo_voting_categories, embed: :ids, key: :shrimpo_voting_categories, embed_in_root: true, each_serializer: ShrimpoVotingCategorySerializer

def voting_completion_percentage
object.voting_completion instance_options[:current_user]
end

def entries_count
object.shrimpo_entries.count
end
Expand Down

0 comments on commit f77f1df

Please sign in to comment.