示例#1
0
def set_user_postion(userId: int, user_position: UserPositionModel):
    user = UserService.get_user(db_session, userId)
    if user is None:
        raise HTTPException(status_code=404, detail="User doesnt exists.")
    try:
        UserService.set_user_postion(db_session, userId, user_position)
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))
    return user
示例#2
0
def change_search_info(userId: int, user_data: UserChangeSearchSettingsModel):
    user = UserService.get_user(db_session, userId)
    if user is None:
        raise HTTPException(status_code=404, detail="User doesnt exists.")
    try:
        UserService.change_search_info(db_session, userId, user_data)
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))
    return user
示例#3
0
async def post_user_photo(userId: int, photo: UploadFile = File(...)):
    user = UserService.get_user(db_session, userId)
    if user is None:
        raise HTTPException(status_code=404, detail="User doesnt exists.")
    if photo.content_type == "image/jpeg":
        photo_bytes = await photo.read()
        try:
            UserService.upload_photo(db_session, userId, photo_bytes)
        except Exception as e:
            raise HTTPException(status_code=400, detail=str(e))
    return user
 def get_new_proposition(db_session: Session, user_id: int,
                         proposition_amount: int, offset: int):
     user = UserService.get_user(db_session, user_id)
     if user is None:
         raise Exception('User doesn\'t exists')
     user_search_settings = user.searchSettings
     if user_search_settings is None:
         raise Exception('User search settings don\'t exists')
     new_propositions = db_session.query(User) \
         .join(UserPersonalInfo) \
         .join(UserSearchSettings) \
         .filter(UserPersonalInfo.gender == user_search_settings.gender_preferences.value) \
         .filter(UserPersonalInfo.age.between(user_search_settings.minAge, user_search_settings.maxAge)) \
         .filter(User.id != user.id) \
         .filter(UserSearchSettings.haversine(user_search_settings) <= user_search_settings.distance) \
         .order_by(User.id.asc()) \
         .limit(proposition_amount) \
         .offset(offset) \
         .all()
     for proposed_user in new_propositions:
         if ConnectionService.find_in_old_propositions(
                 user.id, proposed_user.id).count() > 0:
             new_propositions.remove(proposed_user)
     return new_propositions
示例#5
0
def set_personal_info(userId: int, user_data: UserPersonalInfoUpdate):
    user = UserService.get_user(db_session, userId)
    if user is None:
        raise HTTPException(status_code=404, detail="User doesnt exists.")
    UserService.change_personal_info(db_session, userId, user_data)
    return user
示例#6
0
def create_user(user_data: NewUser):
    user = UserService.get_by_email(db_session, user_data.email)
    if user is not None:
        raise HTTPException(status_code=400, detail="Email already registered")
    return UserService.create_user(db_session, user_data)
示例#7
0
def get_user(userId: int):
    return UserService.get_user(db_session, userId)
示例#8
0
def get_all_users():
    print(UserService.get_all_users(db_session))
    return UserService.get_all_users(db_session)