From 859b6a318e04b3c20a0684326dc123f10e929c18 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 25 Jul 2023 17:05:18 +0200 Subject: [PATCH] qa: Can export QA in JSON --- qa/api/qa.go | 78 ++++++++++++++++++++++++++++ qa/ui/src/routes/themes/+page.svelte | 19 +++++-- 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/qa/api/qa.go b/qa/api/qa.go index 27f56881..82230635 100644 --- a/qa/api/qa.go +++ b/qa/api/qa.go @@ -18,6 +18,7 @@ func declareQARoutes(router *gin.RouterGroup) { exercicesRoutes.POST("", createExerciceQA) exercicesRoutes.GET("/export", exportQA) + exercicesRoutes.GET("/export.json", exportQAJSON) qaRoutes := exercicesRoutes.Group("/:qid") qaRoutes.Use(qaHandler) @@ -143,6 +144,83 @@ func exportQA(c *gin.Context) { c.JSON(http.StatusOK, report) } +type ExportTheme struct { + Theme *fic.Theme `json:"theme"` + Exercices []ExportExercice `json:"exercices"` +} + +type ExportExercice struct { + Exercice *fic.Exercice `json:"exercice"` + Reports []ExportReport `json:"reports"` +} + +type ExportReport struct { + Report *fic.QAQuery `json:"report"` + Comments []*fic.QAComment `json:"comments"` +} + +func exportQAJSON(c *gin.Context) { + report := map[string]ExportTheme{} + + themes, err := fic.GetThemes() + if err != nil { + log.Println("Unable to GetThemes: ", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to list themes: %s", err.Error())}) + return + } + + for _, th := range themes { + export_theme := ExportTheme{ + Theme: th, + } + + exercices, err := th.GetExercices() + if err != nil { + log.Println("Unable to GetExercices: ", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to list exercices for theme #%d: %s", th.Id, err.Error())}) + return + } + + for _, exercice := range exercices { + export_exercice := ExportExercice{ + Exercice: exercice, + } + + qa, err := exercice.GetQAQueries() + if err != nil { + log.Println("Unable to GetQAQueries: ", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to list QA entries: %s", err.Error())}) + return + } + + for _, q := range qa { + export_report := ExportReport{ + Report: q, + } + + comments, err := q.GetComments() + if err != nil { + log.Println("Unable to GetQAComments: ", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to list QA comments: %s", err.Error())}) + return + } + + for _, c := range comments { + export_report.Comments = append(export_report.Comments, c) + } + + export_exercice.Reports = append(export_exercice.Reports, export_report) + } + + export_theme.Exercices = append(export_theme.Exercices, export_exercice) + } + + report[th.Name] = export_theme + } + + c.JSON(http.StatusOK, report) +} + type QAQueryAndComment struct { *fic.QAQuery Content string `json:"content"` diff --git a/qa/ui/src/routes/themes/+page.svelte b/qa/ui/src/routes/themes/+page.svelte index 9ff945cc..74c476f3 100644 --- a/qa/ui/src/routes/themes/+page.svelte +++ b/qa/ui/src/routes/themes/+page.svelte @@ -6,6 +6,7 @@ import { Button, + ButtonGroup, Container, Table, } from 'sveltestrap'; @@ -22,12 +23,22 @@ {#if $auth && $auth.is_manager} - + + + {/if}

Scénarios