From 227a2afd37de05d202c0ea5b7af0e475285b82ae Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 24 Jul 2018 17:29:46 +0200 Subject: [PATCH] implemented viewing all teams of a list --- models/team_list_readall.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 models/team_list_readall.go diff --git a/models/team_list_readall.go b/models/team_list_readall.go new file mode 100644 index 00000000..dcc52a97 --- /dev/null +++ b/models/team_list_readall.go @@ -0,0 +1,24 @@ +package models + +// ReadAll implements the method to read all teams of a namespace +func (tl *TeamList) ReadAll(user *User) (interface{}, error) { + // Check if the user can read the namespace + l, err := GetListByID(tl.ListID) + if err != nil { + return nil, err + } + if !l.CanRead(user) { + return nil, ErrNeedToHaveListReadAccess{ListID: tl.ListID, UserID: user.ID} + } + + // Get the teams + all := []*Team{} + + err = x.Select("teams.*"). + Table("teams"). + Join("INNER", "team_list", "team_id = teams.id"). + Where("team_list.list_id = ?", tl.ListID). + Find(&all) + + return all, err +}