mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 19:26:21 +00:00
feat: poder actualizar el post si sabemos el uuid
This commit is contained in:
parent
3983f17ba2
commit
74ed69d52c
2 changed files with 21 additions and 1 deletions
|
@ -117,7 +117,7 @@ class PostsController < ApplicationController
|
|||
service = PostService.new(site: site,
|
||||
usuarie: current_usuarie,
|
||||
params: params)
|
||||
@post = service.create
|
||||
@post = service.create_or_update
|
||||
|
||||
if post.persisted?
|
||||
site.touch
|
||||
|
|
|
@ -3,6 +3,26 @@
|
|||
# Este servicio se encarga de crear artículos y guardarlos en git,
|
||||
# asignándoselos a une usuarie
|
||||
PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||
|
||||
# Si estamos pasando el UUID con los parámetros, el post quizás
|
||||
# existe.
|
||||
#
|
||||
# @return [Post]
|
||||
def create_or_update
|
||||
uuid = params.require(base).permit(:uuid).values.first
|
||||
|
||||
binding.pry
|
||||
|
||||
if uuid.blank?
|
||||
create
|
||||
elsif (indexed_post = site.indexed_posts.find_by(post_id: uuid)).present?
|
||||
self.post = indexed_post.post
|
||||
update
|
||||
else
|
||||
create
|
||||
end
|
||||
end
|
||||
|
||||
# Crea un artículo nuevo
|
||||
#
|
||||
# @return Post
|
||||
|
|
Loading…
Reference in a new issue