def listening(owner_email, listening_email): if owner_email == listening_email: return abort(400, "can't listen yourself") listening_state = session.query(Listen).\ filter(Listen.listeningEmail == listening_email).\ filter(Listen.listenerEmail == owner_email).first() if listening_state: return abort(400, "already listening") listening_user = session.query(User).filter( User.email == listening_email).first() if listening_user: try: new_listening = Listen(listeningEmail=listening_email, listenerEmail=owner_email) session.add(new_listening) session.commit() return {"message": "Success"} except SQLAlchemyError: session.rollback() return abort(418, "db_error") else: return abort(404, "No such user")
def post(title, content): new_post = Posts(title=title, content=content) session.add(new_post) session.commit() return {'message': 'Create post successfully'}, 201
def create_notice(title, content, user_email): new_notice = Notice(title=title, content=content, user_email=user_email) session.add(new_notice) session.commit() # sendMessage(title="새로운 공지사항", body=title) return {"message": "success"}, 201
def create_new_user(email, password, nickname, age): new_user = User(email=email, password=generate_password_hash(password), nickname=nickname, age=age) session.add(new_user) session.commit()
def sign_up(email, password, name, major): origin_user = session.query(User).filter(User.email == email).first() if origin_user: abort(409, "this email is already in use") else: add_user = User(email=email, password=generate_password_hash(password), name=name, major=major, email_status=1) session.add(add_user) session.commit() return {"message": "success"}, 201
def sign_up(email, password, name, phone_number, gender): user = session.query(User).filter(User.email == email).first() if user: return abort(409, 'This email already signed up') add_user = User(email=email, password=generate_password_hash(password), name=name, phone_number=phone_number, gender=gender) session.add(add_user) session.commit() return {'message': 'Sign up successfully'}, 201