parent
fbf67891ed
commit
94dc7b5796
@ -0,0 +1,19 @@
|
||||
require_relative "../models"
|
||||
|
||||
module Alphadex
|
||||
def self.add_bookmark(url, title, note, tags)
|
||||
fail "url already exists" unless Url.where(url:).empty?
|
||||
|
||||
DB.transaction do
|
||||
entity = Entity.create
|
||||
entity.url = Url.new(url:)
|
||||
entity.title = Title.new(title:)
|
||||
entity.add_note(text: note)
|
||||
tags.map { Tag.find_or_create(name: _1) }.each do |tag|
|
||||
entity.add_tag(tag)
|
||||
end
|
||||
|
||||
entity
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue