This commit is contained in:
@@ -44,7 +44,8 @@ class PostsController < ApplicationController
|
||||
filtered_posts
|
||||
.joins("LEFT JOIN (#{ pt_max_sql }) pt_max ON pt_max.post_id = posts.id")
|
||||
.reselect('posts.*', Arel.sql("#{ updated_at_all_sql } AS updated_at_all"))
|
||||
.preload(tags: [:deerjikists, :materials, { tag_name: :wiki_page }])
|
||||
.preload(:parents, :children,
|
||||
tags: [:deerjikists, :materials, { tag_name: :wiki_page }])
|
||||
.with_attached_thumbnail
|
||||
|
||||
q = q.where('posts.url LIKE ?', "%#{ url }%") if url
|
||||
@@ -95,7 +96,8 @@ class PostsController < ApplicationController
|
||||
end
|
||||
|
||||
def random
|
||||
post = filtered_posts.preload(tags: [:deerjikists, :materials, { tag_name: :wiki_page }])
|
||||
post = filtered_posts.preload(:parents, :childern,
|
||||
tags: [:deerjikists, :materials, { tag_name: :wiki_page }])
|
||||
.order('RAND()')
|
||||
.first
|
||||
return head :not_found unless post
|
||||
@@ -104,7 +106,11 @@ class PostsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
post = Post.includes(tags: [:deerjikists, :materials, { tag_name: :wiki_page }]).find_by(id: params[:id])
|
||||
post = Post
|
||||
.preload(:parents, :children)
|
||||
.includes(:parents, :children,
|
||||
tags: [:deerjikists, :materials, { tag_name: :wiki_page }])
|
||||
.find_by(id: params[:id])
|
||||
return head :not_found unless post
|
||||
|
||||
render json: PostRepr.base(post, current_user)
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
class TheatreCommentsController < ApplicationController
|
||||
def index
|
||||
limit = params[:limit].to_i
|
||||
limit = 20 if limit <= 0
|
||||
|
||||
no_gt = params[:no_gt].to_i
|
||||
no_gt = 0 if no_gt.negative?
|
||||
no_gt = 0 if no_gt < 0
|
||||
|
||||
comments = TheatreComment
|
||||
.where(theatre_id: params[:theatre_id])
|
||||
.where('no > ?', no_gt)
|
||||
.order(no: :desc)
|
||||
.limit(limit)
|
||||
|
||||
render json: comments.as_json(include: { user: { only: [:id, :name] } })
|
||||
render json: comments.map {
|
||||
_1.as_json(include: { user: { only: [:id, :name] } })
|
||||
.merge(content: _1.discarded? ? nil : _1.content, deleted: _1.discarded?)
|
||||
}
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -29,4 +36,18 @@ class TheatreCommentsController < ApplicationController
|
||||
|
||||
render json: comment, status: :created
|
||||
end
|
||||
|
||||
def destroy
|
||||
return head :unauthorized unless current_user
|
||||
|
||||
theatre_id = params[:theatre_id].to_i
|
||||
no = params[:id].to_i
|
||||
|
||||
comment = TheatreComment.find_by(theatre_id:, no:)
|
||||
return head :not_found unless comment
|
||||
|
||||
comment.discard!
|
||||
|
||||
head :no_content
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class TheatreProgrammesController < ApplicationController
|
||||
def index
|
||||
limit = params[:limit].to_i
|
||||
limit = 100 if limit <= 0
|
||||
|
||||
position_gt = params[:position_gt].to_i
|
||||
position_gt = 0 if position_gt < 0
|
||||
|
||||
programmes = TheatreProgramme
|
||||
.where(theatre_id: params[:theatre_id])
|
||||
.where('position > ?', position_gt)
|
||||
.order(position: :desc).limit(100)
|
||||
.limit(limit)
|
||||
|
||||
render json: programmes.as_json(include: { post: PostRepr::BASE })
|
||||
end
|
||||
end
|
||||
@@ -43,11 +43,14 @@ class TheatresController < ApplicationController
|
||||
return head :not_found unless theatre
|
||||
return head :forbidden if theatre.host_user != current_user
|
||||
|
||||
post = Post.where("url LIKE '%nicovideo.jp%'")
|
||||
.or(Post.where("url LIKE '%youtube.com%'"))
|
||||
.order('RAND()')
|
||||
.first
|
||||
theatre.update!(current_post: post, current_post_started_at: Time.current)
|
||||
ApplicationRecord.transaction do
|
||||
post = Post.where("url LIKE '%nicovideo.jp%'")
|
||||
.order('RAND()')
|
||||
.first
|
||||
theatre.update!(current_post: post, current_post_started_at: Time.current)
|
||||
position = (theatre.programmes.maximum(:position) || 0) + 1
|
||||
theatre.programmes.create!(position:, post:)
|
||||
end
|
||||
|
||||
head :no_content
|
||||
end
|
||||
|
||||
@@ -81,7 +81,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
def material_id = materials.first&.id
|
||||
|
||||
def has_deerjikists = deerjikists.present?
|
||||
def has_deerjikists = deerjikists.exists?
|
||||
|
||||
def self.tagme = find_or_create_by_tag_name!('タグ希望', category: :meta)
|
||||
def self.bot = find_or_create_by_tag_name!('bot操作', category: :meta)
|
||||
|
||||
@@ -7,6 +7,8 @@ class Theatre < ApplicationRecord
|
||||
class_name: 'TheatreWatchingUser', inverse_of: :theatre
|
||||
has_many :watching_users, through: :active_theatre_watching_users, source: :user
|
||||
|
||||
has_many :programmes, class_name: 'TheatreProgramme'
|
||||
|
||||
belongs_to :host_user, class_name: 'User', optional: true
|
||||
belongs_to :current_post, class_name: 'Post', optional: true
|
||||
belongs_to :created_by_user, class_name: 'User'
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class TheatreProgramme < ApplicationRecord
|
||||
self.primary_key = :theatre_id, :position
|
||||
|
||||
belongs_to :theatre
|
||||
belongs_to :post
|
||||
end
|
||||
Reference in New Issue
Block a user