コード例 #1
0
ファイル: word_service.py プロジェクト: Scandinaf/ll_free
 async def save_word(self, arg_json):
     try:
         word_inst = Word.init_form_json(
             validate_json(Word.get_json_schema(), arg_json))
         if await self.db_layer.word.record_is_exists(word_inst.word):
             return Error(
                 "The dictionary already contains this word. Word - {}".
                 format(word_inst.word))
         await self.db_layer.word.save(vars(word_inst))
         await self.producer.send_message(WordKafkaMessage(word_inst.word))
     except (TypeError, ValidationError) as exp:
         return Error(exp)
     except JSONDecodeError:
         return Error("Not valid JSON was passed.")
     except Exception as exp:
         return self.__unexpected_exception__(exp)
     else:
         return "Word was added!!!"
コード例 #2
0
 def __convert_to_inst__(word_list_json):
     return list(
         map(lambda word_json: Word.init_form_json(word_json),
             word_list_json))