26 lines
642 B
Go
26 lines
642 B
Go
package projects
|
|
|
|
import (
|
|
db "ttime/internal/database"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/log"
|
|
)
|
|
|
|
// GetUserProjects returns all projects that the user is a member of
|
|
func GetUserProjects(c *fiber.Ctx) error {
|
|
username := c.Params("username")
|
|
if username == "" {
|
|
log.Info("No username provided")
|
|
return c.Status(400).SendString("No username provided")
|
|
}
|
|
|
|
// Then dip into the database to get the projects
|
|
projects, err := db.GetDb(c).GetProjectsForUser(username)
|
|
if err != nil {
|
|
return c.Status(500).SendString(err.Error())
|
|
}
|
|
|
|
// Return a json serialized list of projects
|
|
return c.JSON(projects)
|
|
}
|