def create_comments(meal_date_id, request_user_id=None): request_params = request.get_json() content = request_params.get('content') request_params['mealDateId'] = meal_date_id request_params['userId'] = request_user_id if content is None: return jsonify(userMessage="내용을 입력해주세요."), 400 if meal_date_id is None: return jsonify(userMessage="댓글을 작성할 식단날짜를 입력해주세요."), 400 try: meal_date = db.session.query(MealDate).filter( MealDate.id == meal_date_id).one() except: return jsonify(userMessage="댓글 작성할 식단날짜를 잘못 선택하셨습니다.") if request_user_id is None: return jsonify(userMessage="유저 정보가 없습니다."), 400 try: comment = Comment() comment = comment.update_data(**request_params) db.session.add(comment) db.session.commit() q = db.session.query(Comment, User) \ .outerjoin(User, User.id == Comment.user_id) \ .filter(Comment.id == comment.id) return jsonify(data=SerializableModelMixin.serialize_row(q.one())), 200 except: return jsonify( userMessage="server deny your request, check param value"), 403
def create_comments(meal_date_id, request_user_id=None): request_params = request.get_json() content = request_params.get('content') request_params['mealDateId'] = meal_date_id request_params['userId'] = request_user_id if content is None: return jsonify( userMessage="내용을 입력해주세요." ), 400 if meal_date_id is None: return jsonify( userMessage="댓글을 작성할 식단날짜를 입력해주세요." ), 400 try: meal_date = db.session.query(MealDate).filter(MealDate.id == meal_date_id).one() except: return jsonify( userMessage="댓글 작성할 식단날짜를 잘못 선택하셨습니다." ) if request_user_id is None: return jsonify( userMessage="유저 정보가 없습니다." ), 400 try: comment = Comment() comment = comment.update_data(**request_params) db.session.add(comment) db.session.commit() q = db.session.query(Comment, User) \ .outerjoin(User, User.id == Comment.user_id) \ .filter(Comment.id == comment.id) return jsonify( data=SerializableModelMixin.serialize_row(q.one()) ), 200 except: return jsonify( userMessage="server deny your request, check param value" ), 403