Exemple #1
0
async def create_team_membership(
        team_membership: schema.TeamMembershipCreate,
        db: Session = Depends(get_db),
        auth_user: User = Depends(auth_required),
):
    user = get_user(db, team_membership.user_id)
    if not user:
        raise NoResourceWithIdError("user", team_membership.user_id)

    team = get_team(db=db, team_id=team_membership.team_id)
    if not team:
        raise NoResourceWithIdError("team", team_membership.team_id)

    role = get_role(db=db, role_id=team_membership.role_id)
    if not role:
        raise NoResourceWithIdError("role", team_membership.role_id)

    found = crud.membership_already_exists(db=db,
                                           user=user,
                                           team=team,
                                           role=role)
    if found:
        raise HTTPException(
            HTTP_409_CONFLICT,
            detail=
            "The user already has membership of that role within the team",
        )

    return crud.create_team_membership(db=db, user=user, team=team, role=role)
Exemple #2
0
async def get_team(team_id: str,
                   db: Session = Depends(get_db),
                   user: User = Depends(auth_required)):
    team = crud.get_team(db, team_id)
    if not team:
        raise NoResourceWithIdError("team", team_id)
    return team
Exemple #3
0
async def get_all_moods(template_id: str = None,
                        db: Session = Depends(get_db)):
    if template_id:
        template = get_mood_template(db, template_id)
        if not template:
            raise NoResourceWithIdError("mood_template", template_id)
    return crud.get_all_moods(db, template_id)
Exemple #4
0
async def create_member_mood(
        team_member_mood: schema.TeamMemberMoodCreate,
        db: Session = Depends(get_db),
        auth_user: User = Depends(auth_required),
):
    team = get_team(db=db, team_id=team_member_mood.team_id)
    if not team:
        raise NoResourceWithIdError("team", team_member_mood.team_id)

    mood = get_mood(db=db, mood_id=team_member_mood.mood_id)
    if not mood:
        raise NoResourceWithIdError("mood", team_member_mood.mood_id)

    return crud.create_team_member_mood(db=db,
                                        user=auth_user,
                                        team=team,
                                        mood=mood)
Exemple #5
0
async def get_all_memberships_for_team(
        team_id: str,
        db: Session = Depends(get_db),
        auth_user: User = Depends(auth_required),
):
    memberships = crud.get_all_memberships_for_team(db, team_id)
    if not memberships:
        raise NoResourceWithIdError("team", team_id)
    return memberships
Exemple #6
0
async def get_all_member_moods_for_team(
        team_id: str,
        db: Session = Depends(get_db),
        auth_user: User = Depends(auth_required),
):
    team = get_team(db=db, team_id=team_id)
    if not team:
        raise NoResourceWithIdError("team", team_id)

    member_moods = crud.get_all_member_moods_for_team(db=db, team=team)
    return member_moods
Exemple #7
0
async def get_mood_template(template_id: str, db: Session = Depends(get_db)):
    template = crud.get_mood_template(db, template_id)
    if not template:
        raise NoResourceWithIdError("mood_template", template_id)
    return template
Exemple #8
0
async def get_mood(mood_id: str, db: Session = Depends(get_db)):
    mood = crud.get_mood(db, mood_id)
    if not mood:
        raise NoResourceWithIdError("mood", mood_id)
    return mood
Exemple #9
0
async def create_mood(mood: schema.MoodCreate, db: Session = Depends(get_db)):
    template = get_mood_template(db, mood.template_id)
    if not template:
        raise NoResourceWithIdError("mood_template", mood.template_id)
    return crud.create_mood(db, mood)