implemented get all teams the user is part of

This commit is contained in:
konrad 2018-07-16 08:52:16 +02:00 committed by kolaente
parent b11bd9f0b1
commit f6a816941b
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 15 additions and 1 deletions

View File

@ -120,3 +120,15 @@ func (t *Team) ReadOne(id int64) (err error) {
*t, err = GetTeamByID(id)
return
}
// ReadAll gets all teams the user is part of
func (t *Team) ReadAll(user *User) (teams interface{}, err error) {
all := []*Team{}
err = x.Select("teams.*").
Table("teams").
Join("INNER", "team_members", "team_members.team_id = teams.id").
Where("team_members.user_id = ?", user.ID).
Find(&all)
return all, err
}

View File

@ -1 +0,0 @@
package models

View File

@ -1,6 +1,7 @@
package crud
import (
"fmt"
"git.kolaente.de/konrad/list/models"
"github.com/labstack/echo"
"net/http"
@ -15,6 +16,8 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
lists, err := c.CObject.ReadAll(&currentUser)
if err != nil {
fmt.Println(err)
return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.")
}