Validate bookmark URL uniqueness
This commit is contained in:
@@ -53,6 +53,12 @@ module Micropub
|
||||
.one
|
||||
end
|
||||
|
||||
def url_exists?(url)
|
||||
!!posts
|
||||
.where(url: url)
|
||||
.one
|
||||
end
|
||||
|
||||
def find!(id)
|
||||
posts
|
||||
.by_pk(id)
|
||||
|
@@ -2,6 +2,9 @@ module Micropub
|
||||
module Validation
|
||||
module Posts
|
||||
class BookmarkContract < Dry::Validation::Contract
|
||||
|
||||
include Deps["repos.post_repo"]
|
||||
|
||||
params do
|
||||
required(:name).filled(:string)
|
||||
required(:content).maybe(:string)
|
||||
@@ -14,6 +17,10 @@ module Micropub
|
||||
required(:photos).array(:hash)
|
||||
required(:cache).filled(:bool)
|
||||
end
|
||||
|
||||
rule(:url) do
|
||||
key.failure("URL already bookmarked") if post_repo.url_exists?(values[:url])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user