#14 ぼちぼち

This commit is contained in:
2025-06-03 01:56:49 +09:00
parent f93cea4e51
commit 0afba7f345
5 changed files with 253 additions and 24 deletions
+22 -4
View File
@@ -32,12 +32,30 @@ class PostsController < ApplicationController
# POST /posts
def create
@post = Post.new(post_params)
# TODO: current_user.role が 'admin' もしくは 'member' でなければ 403
if @post.save
render json: @post, status: :created, location: @post
title = params[:title]
unless title.present?
# TODO:
# 既知サイトなら決まったフォーマットで,
# 未知サイトならページ名をセットする.
end
post = Post.new(title: title, url: params[:url], thumbnail_base: '', uploaded_user: current_user)
if params[:thumbnail].present?
post.thumbnail.attach(params[:thumbnail])
else
render json: @post.errors, status: :unprocessable_entity
# TODO:
# 既知ドメインであれば,指定のアドレスからサムネール取得,
# それ以外なら URL のスクショ・イメージをサムネールに登録.
end
if post.save
if params[:tags].present?
tag_ids = JSON.parse(params[:tags])
post.tags = Tag.where(id: tag_ids)
end
render json: post, status: :created
else
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
end
end