filter tasks for user

This commit is contained in:
Florian Hoss 2022-04-07 16:09:42 +02:00
parent 30ed1c3cb5
commit 55fc355abf
2 changed files with 4 additions and 3 deletions

View file

@ -28,9 +28,9 @@ func (db *Database) Initialize() {
db.ORM = orm
}
func (db *Database) GetAllTasks() []Task {
func (db *Database) GetAllTasks(username string) []Task {
var tasks []Task
db.ORM.Find(&tasks)
db.ORM.Where("username = ?", username).Find(&tasks)
return tasks
}

View file

@ -39,7 +39,8 @@ func (wp *Webpage) defineRoutes() {
{
tasks.GET("", func(c *gin.Context) {
if wp.isLoggedInMiddleware(c) {
tasks := wp.Database.GetAllTasks()
username := c.Request.Header.Get("username")
tasks := wp.Database.GetAllTasks(username)
c.JSON(200, gin.H{"tasks": tasks})
}
})