def routine(user: User, board: Board): """ Create new Thread linked to specified board, from POST JSON data. :param user: Requesting User object :param board: Board object :return: New thread inside specified board """ try: # Check thread JSON arguments self.check_args() self.validate_args() # Process anon, image and construct new entity anon = str_to_bool(self.args['anon']) image = self.media_processing() thread = Thread(anon, self.args['title'], self.args['text'], image, board.id, user.id) # Add new Thread table to database uchan.add_to_db(thread) # Add new ThreadUser link thread = user.get_last_thread() uchan.add_to_db(ThreadUser(thread.id, user.id)) return responses.successful(201, JSONRepresentation.thread(thread, user)) except ValueError as msg: return responses.client_error(400, '{}'.format(msg)) except KeyError as key: return responses.client_error(400, 'Invalid parameter: {}'.format(key))
def routine(user: User, board: Board): """ Returns Board's threads list, in JSON representation. :param user: Requesting User object :param board: Board object :return: Board's threads list """ return responses.successful(200, [JSONRepresentation.thread(thread, user) for thread in board.get_threads(page)])
def routine(user: User): return responses.successful(200, [JSONRepresentation.thread(thread, user) for thread in user.get_threads(page)])