def create_post(id): data = request.get_json() or {} if 'image' not in data: return make_response(400, 'must include image field') data['user_id'] = id post = Post() post.from_dict(data) db.session.add(post) db.session.commit() response = jsonify(post.to_dict()) response.status_code = 201 return response
def create_post(): title = request.json.get('title', None) text = request.json.get('text', None) media = request.json.get('media', None) new_post = Post(title=title, text=text, media=media) if new_post: new_post.create() return jsonify(new_post.to_dict()), 201 else: return {'error': 'Something went wrong'}, 409
def create_post_resolver(obj, info, title, description): try: today = date.today() post = Post(title=title, description=description, created_at=today.strftime("%b-%d-%Y")) db.session.add(post) db.session.commit() payload = {"success": True, "post": post.to_dict()} except ValueError: # date format errors payload = { "success": False, "errors": [ f"Incorrect date format provided. Date should be in " f"the format dd-mm-yyyy" ] } return payload