From 2f6c7ecd8be6e56c07278d71799eabb4883d76f4 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 18 Sep 2024 12:32:11 +0200 Subject: [PATCH] qa: New route to assign all exercices --- qa/api/todo.go | 56 +++++++++++++++++++++++++++++ qa/ui/src/routes/teams/+page.svelte | 40 +++++++++++++++++++-- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/qa/api/todo.go b/qa/api/todo.go index 9a5ff270..2b2461a1 100644 --- a/qa/api/todo.go +++ b/qa/api/todo.go @@ -1,8 +1,11 @@ package api import ( + "fmt" + "log" "net/http" "strconv" + "strings" "srs.epita.fr/fic-server/libfic" @@ -17,6 +20,7 @@ func declareTodoRoutes(router *gin.RouterGroup) { } func declareTodoManagerRoutes(router *gin.RouterGroup) { + router.POST("/qa_assign_work", assignWork) router.POST("/qa_my_exercices.json", addQAView) router.POST("/qa_work.json", createQATodo) @@ -235,3 +239,55 @@ func deleteQATodo(c *gin.Context) { c.Status(http.StatusOK) } } + +type QAAssignWork struct { + Turns int `json:"turns"` + Start int `json:"start"` +} + +func assignWork(c *gin.Context) { + var uaw QAAssignWork + if err := c.ShouldBindJSON(&uaw); err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()}) + return + } + if uaw.Turns == 0 { + uaw.Turns = 1 + } + + teams, err := fic.GetTeams() + if err != nil { + log.Println("Unable to GetTeams: ", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to list teams: %s", err.Error())}) + return + } + + // Remove assistant team + for tid := len(teams) - 1; tid >= 0; tid-- { + team := teams[tid] + if strings.Contains(strings.ToLower(team.Name), "assistants") { + teams = append(teams[:tid], teams[tid+1:]...) + } + } + + exercices, err := fic.GetExercices() + if err != nil { + log.Println("Unable to GetExercices: ", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to list exercices: %s", err.Error())}) + return + } + + for i := 0; i < uaw.Turns; i++ { + for eid, ex := range exercices { + team := teams[(uaw.Start+eid+uaw.Turns*i)%len(teams)] + + _, err := team.NewQATodo(ex.Id) + if err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()}) + return + } + } + } + + c.JSON(http.StatusOK, "true") +} diff --git a/qa/ui/src/routes/teams/+page.svelte b/qa/ui/src/routes/teams/+page.svelte index 94b3f0cb..344a1eec 100644 --- a/qa/ui/src/routes/teams/+page.svelte +++ b/qa/ui/src/routes/teams/+page.svelte @@ -4,7 +4,9 @@ import { teams } from '$lib/stores/teams'; import { + Button, Container, + Input, Table, } from '@sveltestrap/sveltestrap'; @@ -16,12 +18,44 @@ function show(id) { goto("teams/" + id) } + + let start = 0; + let turns = 3; + + async function assignExercices() { + const res = await fetch(`api/qa_assign_work`, { + method: 'POST', + headers: {'Accept': 'application/json'}, + body: JSON.stringify({ + start, + turns, + }), + }) + if (res.status == 200) { + teams.refresh(); + } else { + throw new Error((await res.json()).errmsg); + } + } -

- Équipes -

+
+

+ Équipes +

+
+ + + +
+