#1 #2 #4 バックエンド資産作成

This commit is contained in:
2025-08-06 06:09:57 +09:00
parent 22ddfba57a
commit 634ac6e587
95 changed files with 2283 additions and 0 deletions
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
@@ -0,0 +1,27 @@
class PostsController < ApplicationController
before_action :set_post, only: [:good, :bad, :destroy]
# POST /posts/:id/good
def good
@post.increment!(:good)
head :no_content
end
# POST /posts/:id/bad
def bad
@post.increment!(:bad)
head :no_content
end
# DELETE /posts/:id
def destroy
@post.update!(deleted_at: Time.current)
head :no_content
end
private
def set_post
@post = Post.active.find(params[:id])
end
end
@@ -0,0 +1,35 @@
class ThreadPostsController < ApplicationController
before_action :set_thread
# GET /api/threads/:thread_id/posts
def index
sort = params[:sort].presence_in(['created_at', 'score']) || 'created_at'
order = params[:order].presence_in(['asc', 'desc']) || 'desc'
posts = @thread.posts
.select('posts.*, (good - bad) AS score')
.order("#{ sort } #{ order }")
render json: posts
end
# POST /api/threads/:thread_id/posts
def create
post = @thread.posts.new(post_params)
if post.save
render json: post, status: :created
else
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
end
end
private
def set_thread
@thread = Topic.find(params[:thread_id])
end
def post_params
params.require(:post).permit(:name, :body, :password)
end
end
@@ -0,0 +1,29 @@
class ThreadsController < ApplicationController
# GET /api/threads
def index
threads = Topic.order(updated_at: :desc)
render json: threads
end
# GET /api/threads/:id
def show
thread = Topic.find(params[:id])
render json: thread
end
# POST /api/threads
def create
thread = Topic.new(thread_params)
if thread.save
render json: thread, status: :created
else
render json: { errors: thread.errors.full_messages }, status: :unprocessable_entity
end
end
private
def thread_params
params.require(:thread).permit(:title, :description)
end
end
+7
View File
@@ -0,0 +1,7 @@
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
end
+3
View File
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
View File
+4
View File
@@ -0,0 +1,4 @@
class LegacyBase < ActiveRecord::Base
self.abstract_class = true
establish_connection :legacy_bbs
end
+3
View File
@@ -0,0 +1,3 @@
class LegacyResponse < LegacyBase
self.table_name = 'responses'
end
+3
View File
@@ -0,0 +1,3 @@
class LegacyThread < LegacyBase
self.table_name = 'threads'
end
+8
View File
@@ -0,0 +1,8 @@
class Post < ApplicationRecord
belongs_to :thread, class_name: 'Topic', foreign_key: :thread_id
has_one_attached :image
has_secure_password validations: false
scope :active, -> { where deleted_at: nil }
end
+9
View File
@@ -0,0 +1,9 @@
class Topic < ApplicationRecord
self.table_name = 'threads'
has_many :posts, foreign_key: :thread_id, dependent: :destroy
scope :active, -> { where deleted_at: nil }
validates :name, presence: true
end
+13
View File
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>
@@ -0,0 +1 @@
<%= yield %>