qa: Can export QA in JSON
This commit is contained in:
parent
cd64fc90bf
commit
859b6a318e
78
qa/api/qa.go
78
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"`
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
import {
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Container,
|
||||
Table,
|
||||
} from 'sveltestrap';
|
||||
@ -22,12 +23,22 @@
|
||||
|
||||
<Container class="mt-2 mb-5">
|
||||
{#if $auth && $auth.is_manager}
|
||||
<Button
|
||||
href="export"
|
||||
<ButtonGroup
|
||||
class="float-end"
|
||||
>
|
||||
Exporter toutes les remarques
|
||||
</Button>
|
||||
<Button
|
||||
href="export"
|
||||
>
|
||||
Exporter toutes les remarques
|
||||
</Button>
|
||||
<Button
|
||||
href="api/qa/export.json"
|
||||
color="dark"
|
||||
download
|
||||
>
|
||||
JSON
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
{/if}
|
||||
<h2>
|
||||
Scénarios
|
||||
|
Loading…
x
Reference in New Issue
Block a user