From 4cf3fc4d8c5da02666b5c59c86f85b6a0a822a8b Mon Sep 17 00:00:00 2001 From: miteruzo Date: Thu, 15 May 2025 02:21:42 +0900 Subject: [PATCH] =?UTF-8?q?#2=20=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/Gemfile | 2 +- backend/Gemfile.lock | 108 ++++++++++++------------ backend/app/models/nico_tag_relation.rb | 2 +- backend/app/models/post.rb | 3 + backend/app/models/post_tag.rb | 7 ++ backend/app/models/setting.rb | 7 ++ backend/app/models/tag.rb | 7 +- backend/app/models/tag_alias.rb | 6 ++ backend/app/models/user.rb | 14 +++ backend/app/models/user_ips.rb | 7 ++ backend/app/models/user_post_view.rb | 7 ++ backend/app/models/wiki_page.rb | 11 +++ 12 files changed, 124 insertions(+), 57 deletions(-) create mode 100644 backend/app/models/post_tag.rb create mode 100644 backend/app/models/setting.rb create mode 100644 backend/app/models/tag_alias.rb create mode 100644 backend/app/models/user_ips.rb create mode 100644 backend/app/models/user_post_view.rb create mode 100644 backend/app/models/wiki_page.rb diff --git a/backend/Gemfile b/backend/Gemfile index 1c76afc..0a8bfd3 100644 --- a/backend/Gemfile +++ b/backend/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" # 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 gem "sqlite3", ">= 2.1" # Use the Puma web server [https://github.com/puma/puma] diff --git a/backend/Gemfile.lock b/backend/Gemfile.lock index 6ffef1d..7955da9 100644 --- a/backend/Gemfile.lock +++ b/backend/Gemfile.lock @@ -1,29 +1,29 @@ GEM remote: https://rubygems.org/ 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) websocket-driver (>= 0.6.1) 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) - 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) 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) rack (>= 2.2.4) rack-session (>= 1.0.1) @@ -31,35 +31,35 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) 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) nokogiri (>= 1.8.5) - actionview (8.0.1) - activesupport (= 8.0.1) + actionview (8.0.2) + activesupport (= 8.0.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) 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) - 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) - 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) - activesupport (8.0.1) + activesupport (8.0.2) base64 benchmark (>= 0.3) bigdecimal @@ -195,20 +195,20 @@ GEM rack (>= 1.3) rackup (2.2.1) 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) - railties (= 8.0.1) + railties (= 8.0.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -216,9 +216,9 @@ GEM rails-html-sanitizer (1.6.2) 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) - 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) rackup (>= 1.0.0) rake (>= 12.2) @@ -340,7 +340,7 @@ DEPENDENCIES mysql2 (~> 0.5.6) puma (>= 5.0) rack-cors - rails (~> 8.0.1) + rails (~> 8.0.2) rubocop-rails-omakase solid_cable solid_cache diff --git a/backend/app/models/nico_tag_relation.rb b/backend/app/models/nico_tag_relation.rb index 63ab362..239047c 100644 --- a/backend/app/models/nico_tag_relation.rb +++ b/backend/app/models/nico_tag_relation.rb @@ -3,7 +3,7 @@ class NicoTagRelation < ApplicationRecord belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id' validates :nico_tag_id, presence: true - validates :tag_id, prosence: true + validates :tag_id, presence: true validate :nico_tag_must_be_nico diff --git a/backend/app/models/post.rb b/backend/app/models/post.rb index 11adf44..605f627 100644 --- a/backend/app/models/post.rb +++ b/backend/app/models/post.rb @@ -1,4 +1,7 @@ class Post < ApplicationRecord belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id' 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 diff --git a/backend/app/models/post_tag.rb b/backend/app/models/post_tag.rb new file mode 100644 index 0000000..04b4f28 --- /dev/null +++ b/backend/app/models/post_tag.rb @@ -0,0 +1,7 @@ +class PostTag < ApplicationRecord + belongs_to :post + belongs_to :tag + + validates :post_id, presence: true + validates :tag_id, presence: true +end diff --git a/backend/app/models/setting.rb b/backend/app/models/setting.rb new file mode 100644 index 0000000..c9e195d --- /dev/null +++ b/backend/app/models/setting.rb @@ -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 diff --git a/backend/app/models/tag.rb b/backend/app/models/tag.rb index 6560449..adc6021 100644 --- a/backend/app/models/tag.rb +++ b/backend/app/models/tag.rb @@ -1,4 +1,9 @@ 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 :category, presence: true, inclusion: { in: categories.keys } @@ -10,5 +15,5 @@ class Tag < ApplicationRecord nico: 'nico', meta: 'meta' } - scope :nico_tags, -> { where(category: :nico) } + scope :nico_tags, -> { where category: :nico } end diff --git a/backend/app/models/tag_alias.rb b/backend/app/models/tag_alias.rb new file mode 100644 index 0000000..f695886 --- /dev/null +++ b/backend/app/models/tag_alias.rb @@ -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 diff --git a/backend/app/models/user.rb b/backend/app/models/user.rb index 97d8f3b..efe4295 100644 --- a/backend/app/models/user.rb +++ b/backend/app/models/user.rb @@ -9,4 +9,18 @@ class User < ApplicationRecord has_many :posts has_many :settings 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 diff --git a/backend/app/models/user_ips.rb b/backend/app/models/user_ips.rb new file mode 100644 index 0000000..80cf47d --- /dev/null +++ b/backend/app/models/user_ips.rb @@ -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 diff --git a/backend/app/models/user_post_view.rb b/backend/app/models/user_post_view.rb new file mode 100644 index 0000000..2f6239f --- /dev/null +++ b/backend/app/models/user_post_view.rb @@ -0,0 +1,7 @@ +class UserPostView < ApplicationRecord + belongs_to :user + belongs_to :post + + validates :user_id, presence: true + validates :post_id, presence: true +end diff --git a/backend/app/models/wiki_page.rb b/backend/app/models/wiki_page.rb new file mode 100644 index 0000000..64a5471 --- /dev/null +++ b/backend/app/models/wiki_page.rb @@ -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