diff --git a/endpoints/api/globalmessages.py b/endpoints/api/globalmessages.py index 0ed868836..43ea58083 100644 --- a/endpoints/api/globalmessages.py +++ b/endpoints/api/globalmessages.py @@ -102,7 +102,10 @@ class GlobalUserMessages(ApiResource): abort(404) if SuperUserPermission().can(): - model.create_message(request.get_json()['message']) + message_req = request.get_json()['message'] + message = model.create_message(message_req['severity'], message_req['media_type'], message_req['content']) + if message is None: + abort(400) return make_response('', 201) abort(403) diff --git a/endpoints/api/globalmessages_models_interface.py b/endpoints/api/globalmessages_models_interface.py index b3b556ffc..679462c1d 100644 --- a/endpoints/api/globalmessages_models_interface.py +++ b/endpoints/api/globalmessages_models_interface.py @@ -23,17 +23,32 @@ class GlobalMessage( @add_metaclass(ABCMeta) class GlobalMessageDataInterface(object): + """ + Data interface for globalmessages API + """ @abstractmethod def get_all_messages(self): - pass + """ + + Returns: + list(GlobalMessage) + """ @abstractmethod - def create_message(self): - pass + def create_message(self, severity, media_type_name, content): + """ + + Returns: + GlobalMessage or None + """ @abstractmethod - def delete_message(self): - pass + def delete_message(self, uuid): + """ + + Returns: + void + """ \ No newline at end of file diff --git a/endpoints/api/globalmessages_models_pre_oci.py b/endpoints/api/globalmessages_models_pre_oci.py index 9a91ee0e7..d9a623f1b 100644 --- a/endpoints/api/globalmessages_models_pre_oci.py +++ b/endpoints/api/globalmessages_models_pre_oci.py @@ -8,13 +8,21 @@ class GlobalMessagePreOCI(GlobalMessageDataInterface): messages = model.message.get_messages() return [self._message(m) for m in messages] - def create_message(self, content): - model.message.create([content]) + def create_message(self, severity, media_type_name, content): + message = { + 'severity': severity, + 'media_type': media_type_name, + 'content': content + } + messages = model.message.create([message]) + return self._message(messages[0]) def delete_message(self, uuid): model.message.delete_message([uuid]) def _message(self, message_obj): + if message_obj is None: + return None return GlobalMessage( uuid=message_obj.uuid, content=message_obj.content,