Browse Source

#2 修正

#23
みてるぞ 2 months ago
parent
commit
2fb2daa3ff
3 changed files with 13 additions and 17 deletions
  1. +9
    -9
      backend/app/models/tag.rb
  2. +4
    -8
      backend/app/models/user.rb
  3. +0
    -0
      backend/app/models/user_ip.rb

+ 9
- 9
backend/app/models/tag.rb View File

@@ -4,16 +4,16 @@ class Tag < ApplicationRecord
has_many :tag_aliases, dependent: :destroy has_many :tag_aliases, dependent: :destroy
has_many :wiki_pages, dependent: :nullify has_many :wiki_pages, dependent: :nullify


validates :name, presence: true, length: { maximum: 255 }
validates :category, presence: true, inclusion: { in: categories.keys }
enum :category, { deerjikist: 'deerjikist',
meme: 'meme',
character: 'character',
general: 'general',
material: 'material',
nico: 'nico',
meta: 'meta' }


enum category: { deerjikist: 'deerjikist',
meme: 'meme',
character: 'character',
general: 'general',
material: 'material',
nico: 'nico',
meta: 'meta' }
validates :name, presence: true, length: { maximum: 255 }
validates :category, presence: true, inclusion: { in: Tag.categories.keys }


scope :nico_tags, -> { where category: :nico } scope :nico_tags, -> { where category: :nico }
end end

+ 4
- 8
backend/app/models/user.rb View File

@@ -1,11 +1,11 @@
class User < ApplicationRecord class User < ApplicationRecord
enum :role, { guest: 'guest', member: 'member', admin: 'admin' }

validates :name, length: { maximum: 255 } validates :name, length: { maximum: 255 }
validates :inheritance_code, presence: true, length: { maximum: 64 } validates :inheritance_code, presence: true, length: { maximum: 64 }
validates :role, presence: true, inclusion: { in: roles.keys } validates :role, presence: true, inclusion: { in: roles.keys }
validates :banned, inclusion: { in: [true, false] } validates :banned, inclusion: { in: [true, false] }


enum role: { guest: 'guest', member: 'member', admin: 'admin' }

has_many :posts has_many :posts
has_many :settings has_many :settings
has_many :ip_addresses has_many :ip_addresses
@@ -13,12 +13,8 @@ class User < ApplicationRecord
has_many :ip_addresses, through: :user_ips has_many :ip_addresses, through: :user_ips
has_many :user_post_views, dependent: :destroy has_many :user_post_views, dependent: :destroy
has_many :viewed_posts, through: :user_post_views, source: :post has_many :viewed_posts, through: :user_post_views, source: :post
has_many :created_wiki_pages, { class_name: 'WikiPage',
foreign_key: 'created_user_id',
dependent: :nullify }
has_many :updated_wiki_pages, { class_name: 'WikiPage',
foreign_key: 'updated_user_id',
dependent: :nullify }
has_many :created_wiki_pages, class_name: 'WikiPage', foreign_key: 'created_user_id', dependent: :nullify
has_many :updated_wiki_pages, class_name: 'WikiPage', foreign_key: 'updated_user_id', dependent: :nullify


def viewed? post def viewed? post
user_post_views.exists? post_id: post.id, viewed: true user_post_views.exists? post_id: post.id, viewed: true


backend/app/models/user_ips.rb → backend/app/models/user_ip.rb View File


Loading…
Cancel
Save