Browse Source

#2 完了

#23
みてるぞ 2 months ago
parent
commit
4cf3fc4d8c
12 changed files with 124 additions and 57 deletions
  1. +1
    -1
      backend/Gemfile
  2. +54
    -54
      backend/Gemfile.lock
  3. +1
    -1
      backend/app/models/nico_tag_relation.rb
  4. +3
    -0
      backend/app/models/post.rb
  5. +7
    -0
      backend/app/models/post_tag.rb
  6. +7
    -0
      backend/app/models/setting.rb
  7. +6
    -1
      backend/app/models/tag.rb
  8. +6
    -0
      backend/app/models/tag_alias.rb
  9. +14
    -0
      backend/app/models/user.rb
  10. +7
    -0
      backend/app/models/user_ips.rb
  11. +7
    -0
      backend/app/models/user_post_view.rb
  12. +11
    -0
      backend/app/models/wiki_page.rb

+ 1
- 1
backend/Gemfile View File

@@ -1,7 +1,7 @@
source "https://rubygems.org" source "https://rubygems.org"


# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 8.0.1"
gem "rails", "~> 8.0.2"
# Use sqlite3 as the database for Active Record # Use sqlite3 as the database for Active Record
gem "sqlite3", ">= 2.1" gem "sqlite3", ">= 2.1"
# Use the Puma web server [https://github.com/puma/puma] # Use the Puma web server [https://github.com/puma/puma]


+ 54
- 54
backend/Gemfile.lock View File

@@ -1,29 +1,29 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actioncable (8.0.1)
actionpack (= 8.0.1)
activesupport (= 8.0.1)
actioncable (8.0.2)
actionpack (= 8.0.2)
activesupport (= 8.0.2)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (>= 0.6.1) websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6) zeitwerk (~> 2.6)
actionmailbox (8.0.1)
actionpack (= 8.0.1)
activejob (= 8.0.1)
activerecord (= 8.0.1)
activestorage (= 8.0.1)
activesupport (= 8.0.1)
actionmailbox (8.0.2)
actionpack (= 8.0.2)
activejob (= 8.0.2)
activerecord (= 8.0.2)
activestorage (= 8.0.2)
activesupport (= 8.0.2)
mail (>= 2.8.0) mail (>= 2.8.0)
actionmailer (8.0.1)
actionpack (= 8.0.1)
actionview (= 8.0.1)
activejob (= 8.0.1)
activesupport (= 8.0.1)
actionmailer (8.0.2)
actionpack (= 8.0.2)
actionview (= 8.0.2)
activejob (= 8.0.2)
activesupport (= 8.0.2)
mail (>= 2.8.0) mail (>= 2.8.0)
rails-dom-testing (~> 2.2) rails-dom-testing (~> 2.2)
actionpack (8.0.1)
actionview (= 8.0.1)
activesupport (= 8.0.1)
actionpack (8.0.2)
actionview (= 8.0.2)
activesupport (= 8.0.2)
nokogiri (>= 1.8.5) nokogiri (>= 1.8.5)
rack (>= 2.2.4) rack (>= 2.2.4)
rack-session (>= 1.0.1) rack-session (>= 1.0.1)
@@ -31,35 +31,35 @@ GEM
rails-dom-testing (~> 2.2) rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6) rails-html-sanitizer (~> 1.6)
useragent (~> 0.16) useragent (~> 0.16)
actiontext (8.0.1)
actionpack (= 8.0.1)
activerecord (= 8.0.1)
activestorage (= 8.0.1)
activesupport (= 8.0.1)
actiontext (8.0.2)
actionpack (= 8.0.2)
activerecord (= 8.0.2)
activestorage (= 8.0.2)
activesupport (= 8.0.2)
globalid (>= 0.6.0) globalid (>= 0.6.0)
nokogiri (>= 1.8.5) nokogiri (>= 1.8.5)
actionview (8.0.1)
activesupport (= 8.0.1)
actionview (8.0.2)
activesupport (= 8.0.2)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.11) erubi (~> 1.11)
rails-dom-testing (~> 2.2) rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6) rails-html-sanitizer (~> 1.6)
activejob (8.0.1)
activesupport (= 8.0.1)
activejob (8.0.2)
activesupport (= 8.0.2)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (8.0.1)
activesupport (= 8.0.1)
activerecord (8.0.1)
activemodel (= 8.0.1)
activesupport (= 8.0.1)
activemodel (8.0.2)
activesupport (= 8.0.2)
activerecord (8.0.2)
activemodel (= 8.0.2)
activesupport (= 8.0.2)
timeout (>= 0.4.0) timeout (>= 0.4.0)
activestorage (8.0.1)
actionpack (= 8.0.1)
activejob (= 8.0.1)
activerecord (= 8.0.1)
activesupport (= 8.0.1)
activestorage (8.0.2)
actionpack (= 8.0.2)
activejob (= 8.0.2)
activerecord (= 8.0.2)
activesupport (= 8.0.2)
marcel (~> 1.0) marcel (~> 1.0)
activesupport (8.0.1)
activesupport (8.0.2)
base64 base64
benchmark (>= 0.3) benchmark (>= 0.3)
bigdecimal bigdecimal
@@ -195,20 +195,20 @@ GEM
rack (>= 1.3) rack (>= 1.3)
rackup (2.2.1) rackup (2.2.1)
rack (>= 3) rack (>= 3)
rails (8.0.1)
actioncable (= 8.0.1)
actionmailbox (= 8.0.1)
actionmailer (= 8.0.1)
actionpack (= 8.0.1)
actiontext (= 8.0.1)
actionview (= 8.0.1)
activejob (= 8.0.1)
activemodel (= 8.0.1)
activerecord (= 8.0.1)
activestorage (= 8.0.1)
activesupport (= 8.0.1)
rails (8.0.2)
actioncable (= 8.0.2)
actionmailbox (= 8.0.2)
actionmailer (= 8.0.2)
actionpack (= 8.0.2)
actiontext (= 8.0.2)
actionview (= 8.0.2)
activejob (= 8.0.2)
activemodel (= 8.0.2)
activerecord (= 8.0.2)
activestorage (= 8.0.2)
activesupport (= 8.0.2)
bundler (>= 1.15.0) bundler (>= 1.15.0)
railties (= 8.0.1)
railties (= 8.0.2)
rails-dom-testing (2.2.0) rails-dom-testing (2.2.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
minitest minitest
@@ -216,9 +216,9 @@ GEM
rails-html-sanitizer (1.6.2) rails-html-sanitizer (1.6.2)
loofah (~> 2.21) loofah (~> 2.21)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
railties (8.0.1)
actionpack (= 8.0.1)
activesupport (= 8.0.1)
railties (8.0.2)
actionpack (= 8.0.2)
activesupport (= 8.0.2)
irb (~> 1.13) irb (~> 1.13)
rackup (>= 1.0.0) rackup (>= 1.0.0)
rake (>= 12.2) rake (>= 12.2)
@@ -340,7 +340,7 @@ DEPENDENCIES
mysql2 (~> 0.5.6) mysql2 (~> 0.5.6)
puma (>= 5.0) puma (>= 5.0)
rack-cors rack-cors
rails (~> 8.0.1)
rails (~> 8.0.2)
rubocop-rails-omakase rubocop-rails-omakase
solid_cable solid_cable
solid_cache solid_cache


+ 1
- 1
backend/app/models/nico_tag_relation.rb View File

@@ -3,7 +3,7 @@ class NicoTagRelation < ApplicationRecord
belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id' belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id'


validates :nico_tag_id, presence: true validates :nico_tag_id, presence: true
validates :tag_id, prosence: true
validates :tag_id, presence: true


validate :nico_tag_must_be_nico validate :nico_tag_must_be_nico




+ 3
- 0
backend/app/models/post.rb View File

@@ -1,4 +1,7 @@
class Post < ApplicationRecord class Post < ApplicationRecord
belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id' belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id'
belongs_to :user, foreign_key: '' belongs_to :user, foreign_key: ''
has_many :post_tags, dependent: :destroy
has_many :tags, through: :post_tags
has_many :user_post_views, dependent: :destroy
end end

+ 7
- 0
backend/app/models/post_tag.rb View File

@@ -0,0 +1,7 @@
class PostTag < ApplicationRecord
belongs_to :post
belongs_to :tag

validates :post_id, presence: true
validates :tag_id, presence: true
end

+ 7
- 0
backend/app/models/setting.rb View File

@@ -0,0 +1,7 @@
class Setting < ApplicationRecord
belongs_to :user

validates :user_id, presence: true
validates :key, presence: true, length: { maximum: 255 }
validates :value, presence: true
end

+ 6
- 1
backend/app/models/tag.rb View File

@@ -1,4 +1,9 @@
class Tag < ApplicationRecord class Tag < ApplicationRecord
has_many :post_tags, dependent: :destroy
has_many :posts, through: :post_tags
has_many :tag_aliases, dependent: :destroy
has_many :wiki_pages, dependent: :nullify

validates :name, presence: true, length: { maximum: 255 } validates :name, presence: true, length: { maximum: 255 }
validates :category, presence: true, inclusion: { in: categories.keys } validates :category, presence: true, inclusion: { in: categories.keys }


@@ -10,5 +15,5 @@ class Tag < ApplicationRecord
nico: 'nico', nico: 'nico',
meta: 'meta' } meta: 'meta' }


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

+ 6
- 0
backend/app/models/tag_alias.rb View File

@@ -0,0 +1,6 @@
class TagAlias < ApplicationRecord
belongs_to :tag

validates :tag_id, presence: true
validates :name, presence: true, length: { maximum: 255 }, uniqueness: true
end

+ 14
- 0
backend/app/models/user.rb View File

@@ -9,4 +9,18 @@ class User < ApplicationRecord
has_many :posts has_many :posts
has_many :settings has_many :settings
has_many :ip_addresses has_many :ip_addresses
has_many :user_ips, dependent: :destroy
has_many :ip_addresses, through: :user_ips
has_many :user_post_views, dependent: :destroy
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 }

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

+ 7
- 0
backend/app/models/user_ips.rb View File

@@ -0,0 +1,7 @@
class UserIp < ApplicationRecord
belongs_to :user
belongs_to :ip_address

validates :user_id, presence: true
validates :ip_address_id, presence: true
end

+ 7
- 0
backend/app/models/user_post_view.rb View File

@@ -0,0 +1,7 @@
class UserPostView < ApplicationRecord
belongs_to :user
belongs_to :post

validates :user_id, presence: true
validates :post_id, presence: true
end

+ 11
- 0
backend/app/models/wiki_page.rb View File

@@ -0,0 +1,11 @@
class WikiPage < ApplicationRecord
belongs_to :tag, optional: true
belongs_to :created_user, class_name: 'User', foreign_key: 'created_user_id'
belongs_to :updated_user, class_name: 'User', foreign_key: 'updated_user_id'

validates :title, presence: true, length: { maximum: 255 }, uniqueness: true

def gollum_path
"wiki/#{ title.parameterize }.md"
end
end

Loading…
Cancel
Save