From f615d0b8d805703e139c9abb5d84fb293d521204 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 16 Sep 2022 17:26:02 +0200 Subject: [PATCH] Filter repositories route by work if defined --- repositories.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/repositories.go b/repositories.go index 2f7f897..8b0b1b2 100644 --- a/repositories.go +++ b/repositories.go @@ -55,7 +55,19 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) { return } - c.JSON(http.StatusOK, repositories) + if work, ok := c.Get("work"); ok { + var res []*Repository + + for _, r := range repositories { + if r.IdWork == work.(*Work).Id { + res = append(res, r) + } + } + + c.JSON(http.StatusOK, res) + } else { + c.JSON(http.StatusOK, repositories) + } }) router.POST("/repositories", func(c *gin.Context) { var u *User