app/controllers/api_controller.rb
# Inputs
#
# id (integer, required): the id of the note to be updated
# title (string): the updated note title
# content (string): the updated note content
# attachments_to_save (string array): an array of one or more object uids to be "ensured"
# attachments_to_delete (string array): an array of one or more object uids to be removed
#
# Outputs:
# id: the note id
# path (string): the human readable path of the note (which could have changed if the title changed)
#


the note id
path (string): the human readable path of the note (which could have changed if the title changed)
the note id path ( string ) : the human readable path of the note ( which could have changed if the title changed )
def update_note
    id = params[:id].to_i
    fail "id needs to be an Integer" unless id.is_a?(Integer)
    title = params[:title]
    fail "title needs to be a String" unless title.is_a?(String)
    content = params[:content] || ""
    fail "content needs to be a String" unless content.is_a?(String)
    attachments_to_save = params[:attachments_to_save] || []
    fail "attachments_to_save needs to be an array" unless attachments_to_save.is_a?(Array)
    attachments_to_delete = params[:attachments_to_delete] || []
    fail "attachments_to_delete neeeds to be an array" unless attachments_to_delete.is_a?(Array)
    note = nil
    Note.transaction do
      note = Note.editable_by(@context).find_by!(id: params[:id])
      attachments_to_save.each do |uid|
        item = item_from_uid(uid)
        note.attachments.find_or_create_by(item: item)
      end
      attachments_to_delete.each do |uid|
        item = item_from_uid(uid)
        note.attachments.where(item: item).destroy_all
      end
      note.update!(title: title, content: content)
    end
    render json: {
      id: note.id,
      path: note_path(note)
    }
  end
def update_note id = params [ :id ] . to_i fail "id needs to be an Integer" unless id . is_a? ( Integer ) title = params [ :title ] fail "title needs to be a String" unless title . is_a? ( String ) content = params [ :content ] || "" fail "content needs to be a String" unless content . is_a? ( String ) attachments_to_save = params [ :attachments_to_save ] || [ ] fail "attachments_to_save needs to be an array" unless attachments_to_save . is_a? ( Array ) attachments_to_delete = params [ :attachments_to_delete ] || [ ] fail "attachments_to_delete neeeds to be an array" unless attachments_to_delete . is_a? ( Array ) note = nil Note . transaction do note = Note . editable_by ( @context ) . find_by! ( id : params [ :id ] ) attachments_to_save . each do | uid | item = item_from_uid ( uid ) note . attachments . find_or_create_by ( item : item ) end attachments_to_delete . each do | uid | item = item_from_uid ( uid ) note . attachments . where ( item : item ) . destroy_all end note . update! ( title : title , content : content ) end render json : { id : note . id , path : note_path ( note ) } end
Inputs
id (integer, required): the id of the note to be updated
title (string): the updated note title
content (string): the updated note content
attachments_to_save (string array): an array of one or more object uids to be "ensured"
attachments_to_delete (string array): an array of one or more object uids to be removed
Inputs id ( integer required ) : the id of the note to be updated title ( string ) : the updated note title content ( string ) : the updated note content attachments_to_save ( string array ) : an array of one or more object uids to be " ensured " attachments_to_delete ( string array ) : an array of one or more object uids to be removed