44from services .metadata_service .api .utils import format_response , \
55 handle_exceptions
66import json
7- from aiohttp import web
87
98import asyncio
109
@@ -98,14 +97,14 @@ async def update_tags(self, request):
9897 raise ValueError ("invalid artifact specification: %s" % o ['id' ])
9998 obj_filter = table .get_filter_dict (* pathspec )
10099 except ValueError as e :
101- return web . Response ( status = 400 , body = json .dumps (
100+ return DBResponse ( response_code = 400 , body = json .dumps (
102101 {"message" : "invalid input: %s" % str (e )}))
103102
104103 # Now we can get the object
105104 obj = await table .get_records (
106105 filter_dict = obj_filter , fetch_single = True , expanded = True )
107106 if obj .response_code != 200 :
108- return web . Response ( status = obj .response_code , body = json .dumps (
107+ return DBResponse ( response_code = obj .response_code , body = json .dumps (
109108 {"message" : "could not get object %s: %s" % (o ['id' ], obj .body )}))
110109
111110 # At this point do some checks and update the tags
@@ -115,7 +114,7 @@ async def update_tags(self, request):
115114 # This is the only error we fail hard on; adding a tag that is
116115 # in system tag
117116 if o ['tag' ] in obj ['system_tags' ]:
118- return web . Response ( status = 405 , body = json .dumps (
117+ return DBResponse ( response_code = 405 , body = json .dumps (
119118 {"message" : "tag %s is already a system tag and can't be added to %s"
120119 % (o ['tag' ], o ['id' ])}))
121120 if o ['tag' ] not in obj ['tags' ]:
@@ -126,15 +125,15 @@ async def update_tags(self, request):
126125 modified = True
127126 obj ['tags' ].remove (o ['tag' ])
128127 else :
129- return web . Response ( status = 400 , body = json .dumps (
128+ return DBResponse ( response_code = 400 , body = json .dumps (
130129 {"message" : "invalid tag operation %s" % o ['operation' ]}))
131130 if modified :
132131 # We save the value back
133132 result = await table .update_row (filter_dict = obj_filter , update_dict = {
134133 'tags' : "'%s'" % json .dumps (obj ['tags' ])})
135134 if result .response_code != 200 :
136- return web . Response ( status = result .response_code , body = json .dumps (
135+ return DBResponse ( response_code = result .response_code , body = json .dumps (
137136 {"message" : "error updating tags for %s: %s" % (o ['id' ], result .body )}))
138137 results .append (obj )
139138
140- return DBResponse (response_code = 200 , body = results )
139+ return DBResponse (response_code = 200 , body = json . dumps ( results ) )
0 commit comments