-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_controller.rb
41 lines (32 loc) · 1.12 KB
/
create_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# typed: true
# frozen_string_literal: true
class Posts::CreateController < ApplicationController
include ControllerConcerns::Authenticatable
include ControllerConcerns::Localizable
around_action :set_locale
before_action :require_authentication
sig { returns(T.untyped) }
def call
@form = PostForm.new(form_params)
if @form.invalid?
return render("posts/new/call", status: :unprocessable_entity)
end
result = CreatePostUseCase.new.call(
viewer: viewer!,
content: @form.content.not_nil!,
canonical_url: @form.canonical_url.not_nil!
)
unless @form.with_frame
flash[:notice] = t("messages.posts.created")
return redirect_to(home_path)
end
@post = result.post
@stamp_checker = StampChecker.new(profile: viewer!.profile, posts: [@post])
@form = PostForm.new(with_frame: true)
render(content_type: "text/vnd.turbo-stream.html", layout: false)
end
sig { returns(ActionController::Parameters) }
private def form_params
T.cast(params.require(:post_form), ActionController::Parameters).permit(:canonical_url, :content, :with_frame)
end
end