Commit 8201bc3b by source_reader

added edit endpoints for annotations, better logging, and bug fixes

parent 1765b262
......@@ -55,8 +55,8 @@ module Joule
@backend.module_interface(joule_module, req)
end
def module_post_interface(joule_module, req)
@backend.module_post_interface(joule_module, req)
def module_post_interface(joule_module, req, body)
@backend.module_post_interface(joule_module, req, body)
end
# === ANNOTATIONS ===
......@@ -88,6 +88,20 @@ module Joule
# returns nil
@backend.delete_annotation(annotation.id)
end
def edit_annotation(id, title, content, stream)
json = @backend.edit_annotation(id, title, content)
annotation = Annotation.new
annotation.id = json["id"]
annotation.title = json["title"]
annotation.content = json["content"]
annotation.start_time = json["start"]
annotation.end_time = json["end"]
# ignore joule stream_id parameter
# use the db_stream model instead
annotation.db_stream = stream
annotation
end
# === END ANNOTATIONS ===
def node_type
......
......@@ -95,5 +95,24 @@ module Nilmdb
end
@backend.write_annotations(path, updated_annotations)
end
def edit_annotation(id, title, content, stream)
path = stream.path
json = @backend.read_annotations(path)
index = json.index{ |item| item['id']== id.to_i}
raise "error, invalid annotation id" if index.nil?
# find the specified id
json[index]['title'] = title
json[index]['content'] = content
@backend.write_annotations(path, json)
annotation = Annotation.new
annotation.id = json[index]["id"]
annotation.title = json[index]["title"]
annotation.content = json[index]["content"]
annotation.start_time = json[index]["start"]
annotation.end_time = json[index]["end"]
annotation.db_stream = stream
annotation
end
end
end
......@@ -38,6 +38,22 @@ class AnnotationsController < ApplicationController
render :index
end
# PATCH/PUT /annotations/1.json
def update
@service = StubService.new
begin
annotation = @node_adapter.edit_annotation(params[:id],
params[:title],
params[:content],
@db_stream)
rescue RuntimeError => e
@service.add_error("Cannot update annotation [#{e}]")
render 'helpers/empty_response', status: :unprocessable_entity and return
end
@annotations = [annotation]
render :index
end
# DELETE /annotations/1.json
def destroy
annotation = Annotation.new
......
......@@ -47,7 +47,7 @@ class InterfacesController < ActionController::Base
def post
path = create_proxy_path(request.fullpath, @joule_module.id)
proxied_response = @node_adapter.module_post_interface(@joule_module,path)
proxied_response = @node_adapter.module_post_interface(@joule_module,path, request.raw_post)
render plain: proxied_response.body
proxied_response.headers.each do |key,value|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment