ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

21 lines
438 B

  1. # frozen_string_literal: true
  2. module PostRepr
  3. BASE = { include: { tags: TagRepr::BASE, uploaded_user: UserRepr::BASE } }.freeze
  4. module_function
  5. def base post, current_user = nil
  6. json = post.as_json(BASE)
  7. return json.merge(viewed: false) unless current_user
  8. viewed = current_user.viewed?(post)
  9. json.merge(viewed:)
  10. end
  11. def many posts, current_user = nil
  12. posts.map { |p| base(p, current_user) }
  13. end
  14. end