Add a new page to list repos and submissions

This commit is contained in:
nemunaire 2022-09-09 20:14:38 +02:00
parent 643e4d50bd
commit 6323d96b60
12 changed files with 167 additions and 33 deletions

View file

@ -1,9 +1,11 @@
package main
import (
"fmt"
"log"
"net/http"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
@ -24,6 +26,7 @@ func declareAPIAuthUsersRoutes(router *gin.RouterGroup) {
declareAPIAuthSurveysRoutes(usersRoutes)
declareAPIAuthKeysRoutes(usersRoutes)
declareAPIAuthWorksRoutes(usersRoutes)
}
func declareAPIAdminUsersRoutes(router *gin.RouterGroup) {
@ -50,7 +53,31 @@ func declareAPIAdminUsersRoutes(router *gin.RouterGroup) {
return
}
c.JSON(http.StatusOK, users)
var filterPromo *uint64
if c.Query("promo") != "" {
fPromo, err := strconv.ParseUint(c.Query("promo"), 10, 64)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to parse promo: %s", err.Error())})
return
}
filterPromo = &fPromo
}
filterGroup := c.Query("group")
if filterPromo == nil && filterGroup == "" {
c.JSON(http.StatusOK, users)
return
}
var ret []User
for _, u := range users {
if (filterPromo == nil || uint(*filterPromo) == u.Promo) && (filterGroup == "" || strings.Contains(u.Groups, filterGroup)) {
ret = append(ret, u)
}
}
c.JSON(http.StatusOK, ret)
})
usersRoutes := router.Group("/users/:uid")