"""Client API for teams in Nexus."""importqnexus.exceptionsasqnx_excfromqnexus.clientimportget_nexus_clientfromqnexus.models.referencesimportDataframableList,TeamRef
[docs]defget_all()->DataframableList[TeamRef]:"""No fuzzy name matching."""res=get_nexus_client().get("/api/v5/user/teams",)ifres.status_code!=200:raiseqnx_exc.ResourceFetchFailed(message=res.text,status_code=res.status_code)returnDataframableList([TeamRef(id=team["id"],name=team["team_name"],description=team["description"],)forteaminres.json()])
[docs]defget(name:str)->TeamRef:""" Get a single team using filters. Throws an exception if the filters do not match exactly one object. """res=get_nexus_client().get("/api/v5/user/teams",params={"name":name})ifres.status_code==404orres.json()==[]:raiseqnx_exc.ZeroMatchesifres.status_code!=200:raiseqnx_exc.ResourceFetchFailed(message=res.text,status_code=res.status_code)teams_list=[TeamRef(id=team["id"],name=team["team_name"],description=team["description"],)forteaminres.json()]iflen(teams_list)>1:raiseqnx_exc.NoUniqueMatchreturnteams_list[0]
def_fetch_by_id(team_id:str)->TeamRef:""" Get a single team by id. """res=get_nexus_client().get(f"/api/v5/user/teams/{team_id}")ifres.status_code==404:raiseqnx_exc.ZeroMatchesifres.status_code!=200:raiseqnx_exc.ResourceFetchFailed(message=res.text,status_code=res.status_code)team_dict=res.json()returnTeamRef(id=team_dict["id"],name=team_dict["team_name"],description=team_dict["description"],)
[docs]defcreate(name:str,description:str|None=None)->TeamRef:"""Create a team in Nexus."""resp=get_nexus_client().post("api/v5/user/teams/new",json={"team_name":name,"description":description,},)ifresp.status_code!=201:raiseqnx_exc.ResourceCreateFailed(message=resp.text,status_code=resp.status_code)team_dict=resp.json()returnTeamRef(id=team_dict["id"],name=team_dict["team_name"],description=team_dict["description"],)