2018-06-10 14:41:42 +02:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.kolaente.de/konrad/list/models"
|
2018-06-10 14:43:35 +02:00
|
|
|
"github.com/labstack/echo"
|
2018-06-10 14:41:42 +02:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-06-10 14:43:35 +02:00
|
|
|
// GetListsByUser gets all lists a user owns
|
2018-06-10 14:41:42 +02:00
|
|
|
func GetListsByUser(c echo.Context) error {
|
|
|
|
|
|
|
|
currentUser, err := models.GetCurrentUser(c)
|
|
|
|
if err != nil {
|
|
|
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not determine the current user."})
|
|
|
|
}
|
|
|
|
|
|
|
|
allLists, err := models.GetListsByUser(¤tUser)
|
|
|
|
if err != nil {
|
2018-06-10 19:49:40 +02:00
|
|
|
|
|
|
|
if models.IsErrListDoesNotExist(err) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-10 14:41:42 +02:00
|
|
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get lists."})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, allLists)
|
2018-06-10 14:43:35 +02:00
|
|
|
}
|