5
0
Fork 0
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:
f 2024-06-04 17:08:31 -03:00
parent 3983f17ba2
commit 74ed69d52c
No known key found for this signature in database
2 changed files with 21 additions and 1 deletions

View file

@ -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

View file

@ -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