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
No known key found for this signature in database
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) *t, err = GetTeamByID(id)
return 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 package crud
import ( import (
"fmt"
"git.kolaente.de/konrad/list/models" "git.kolaente.de/konrad/list/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
@ -15,6 +16,8 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
lists, err := c.CObject.ReadAll(&currentUser) lists, err := c.CObject.ReadAll(&currentUser)
if err != nil { if err != nil {
fmt.Println(err)
return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.") return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.")
} }