Commit 8201bc3b by source_reader

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

parent 1765b262
...@@ -55,8 +55,8 @@ module Joule ...@@ -55,8 +55,8 @@ module Joule
@backend.module_interface(joule_module, req) @backend.module_interface(joule_module, req)
end end
def module_post_interface(joule_module, req) def module_post_interface(joule_module, req, body)
@backend.module_post_interface(joule_module, req) @backend.module_post_interface(joule_module, req, body)
end end
# === ANNOTATIONS === # === ANNOTATIONS ===
...@@ -88,6 +88,20 @@ module Joule ...@@ -88,6 +88,20 @@ module Joule
# returns nil # returns nil
@backend.delete_annotation(annotation.id) @backend.delete_annotation(annotation.id)
end 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 === # === END ANNOTATIONS ===
def node_type def node_type
......
...@@ -95,5 +95,24 @@ module Nilmdb ...@@ -95,5 +95,24 @@ module Nilmdb
end end
@backend.write_annotations(path, updated_annotations) @backend.write_annotations(path, updated_annotations)
end 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
end end
...@@ -38,6 +38,22 @@ class AnnotationsController < ApplicationController ...@@ -38,6 +38,22 @@ class AnnotationsController < ApplicationController
render :index render :index
end 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 # DELETE /annotations/1.json
def destroy def destroy
annotation = Annotation.new annotation = Annotation.new
......
...@@ -47,7 +47,7 @@ class InterfacesController < ActionController::Base ...@@ -47,7 +47,7 @@ class InterfacesController < ActionController::Base
def post def post
path = create_proxy_path(request.fullpath, @joule_module.id) 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 render plain: proxied_response.body
proxied_response.headers.each do |key,value| 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