From 0e23ce8d0b514924447330e2ed85b54116ef0a49 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 22 Jan 2019 12:09:42 +0000 Subject: [PATCH] Added web routes for tagging captures --- .../api/v1/blueprints/camera/__init__.py | 5 + .../api/v1/blueprints/camera/capture.py | 109 +++++++++++++++++- openflexure_microscope/camera/capture.py | 18 +-- 3 files changed, 122 insertions(+), 10 deletions(-) diff --git a/openflexure_microscope/api/v1/blueprints/camera/__init__.py b/openflexure_microscope/api/v1/blueprints/camera/__init__.py index 81875403..f21d321e 100644 --- a/openflexure_microscope/api/v1/blueprints/camera/__init__.py +++ b/openflexure_microscope/api/v1/blueprints/camera/__init__.py @@ -18,6 +18,11 @@ def construct_blueprint(microscope_obj): '/capture//metadata', view_func=capture.MetadataRedirectAPI.as_view('metadata_download_redirect', microscope=microscope_obj)) + # Tag routes + blueprint.add_url_rule( + '/capture//tags', + view_func=capture.TagsAPI.as_view('capture_tags', microscope=microscope_obj)) + # Capture routes blueprint.add_url_rule( '/capture//download/', diff --git a/openflexure_microscope/api/v1/blueprints/camera/capture.py b/openflexure_microscope/api/v1/blueprints/camera/capture.py index f30fcc96..13058995 100644 --- a/openflexure_microscope/api/v1/blueprints/camera/capture.py +++ b/openflexure_microscope/api/v1/blueprints/camera/capture.py @@ -1,5 +1,6 @@ from openflexure_microscope.api.utilities import gen, get_bool, JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView +from openflexure_microscope.utilities import filter_dict from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file @@ -224,7 +225,7 @@ class CaptureAPI(MicroscopeView): .. sourcecode:: http - POST /camera/capture HTTP/1.1 + PUT /camera/capture/d0b2067abbb946f19351e075c5e7cd5b HTTP/1.1 Accept: application/json { @@ -374,4 +375,108 @@ class MetadataAPI(MicroscopeView): return Response( data, - mimetype="text/yaml") \ No newline at end of file + mimetype="text/yaml") + +class TagsAPI(MicroscopeView): + def get(self, capture_id): + """ + Return tag list for a capture. + + .. :quickref: Capture; Show capture tags + + **Example request**: + + .. sourcecode:: http + + GET /camera/capture/d0b2067abbb946f19351e075c5e7cd5b/tags HTTP/1.1 + Accept: text/yaml + + :>header Accept: text/yaml + + :>header Content-Type: text/yaml + :status 200: capture data found + :status 404: no capture found with that id + """ + capture_obj = self.microscope.camera.image_from_id(capture_id) + + if not capture_obj or not capture_obj.state['available']: + return abort(404) # 404 Not Found + + metadata_tags = filter_dict(capture_obj.state, ('metadata', 'tags')) + + return jsonify(metadata_tags) + + def put(self, capture_id): + """ + Add tags to the capture + + .. :quickref: Capture; Update capture tags + + **Example request**: + + .. sourcecode:: http + + PUT /camera/capture/d0b2067abbb946f19351e075c5e7cd5b/tags HTTP/1.1 + Accept: application/json + + ["tests", "mytag", "someothertag"] + + :>header Accept: application/json + + :
header Accept: application/json + + :