qa: Managers can view team and manage theirs todo list

This commit is contained in:
nemunaire 2023-07-25 11:17:40 +02:00
commit cd64fc90bf
13 changed files with 526 additions and 24 deletions

View file

@ -2,6 +2,7 @@ package api
import (
"net/http"
"strconv"
"srs.epita.fr/fic-server/libfic"
@ -18,12 +19,22 @@ func declareTodoRoutes(router *gin.RouterGroup) {
func declareTodoManagerRoutes(router *gin.RouterGroup) {
router.POST("/qa_my_exercices.json", addQAView)
router.POST("/qa_work.json", createQATodo)
todosRoutes := router.Group("/todo/:wid")
todosRoutes.Use(todoHandler)
todosRoutes.GET("", showTodo)
todosRoutes.DELETE("", deleteQATodo)
}
type exerciceTested map[int64]string
func getExerciceTested(c *gin.Context) {
teamid := c.MustGet("LoggedTeam").(int64)
var teamid int64
if team, ok := c.Get("team"); ok {
teamid = team.(*fic.Team).Id
} else {
teamid = c.MustGet("LoggedTeam").(int64)
}
team, err := fic.GetTeam(teamid)
if err != nil {
@ -55,7 +66,12 @@ func getExerciceTested(c *gin.Context) {
}
func getQAView(c *gin.Context) {
teamid := c.MustGet("LoggedTeam").(int64)
var teamid int64
if team, ok := c.Get("team"); ok {
teamid = team.(*fic.Team).Id
} else {
teamid = c.MustGet("LoggedTeam").(int64)
}
team, err := fic.GetTeam(teamid)
if err != nil {
@ -73,7 +89,12 @@ func getQAView(c *gin.Context) {
}
func getQAWork(c *gin.Context) {
teamid := c.MustGet("LoggedTeam").(int64)
var teamid int64
if team, ok := c.Get("team"); ok {
teamid = team.(*fic.Team).Id
} else {
teamid = c.MustGet("LoggedTeam").(int64)
}
team, err := fic.GetTeam(teamid)
if err != nil {
@ -91,7 +112,12 @@ func getQAWork(c *gin.Context) {
}
func getQATodo(c *gin.Context) {
teamid := c.MustGet("LoggedTeam").(int64)
var teamid int64
if team, ok := c.Get("team"); ok {
teamid = team.(*fic.Team).Id
} else {
teamid = c.MustGet("LoggedTeam").(int64)
}
team, err := fic.GetTeam(teamid)
if err != nil {
@ -167,3 +193,45 @@ func addQAView(c *gin.Context) {
c.JSON(http.StatusOK, view)
}
func todoHandler(c *gin.Context) {
team := c.MustGet("team").(*fic.Team)
var wid int64
var todos []*fic.QATodo
var err error
if wid, err = strconv.ParseInt(string(c.Param("wid")), 10, 64); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Bad todo identifier."})
return
}
if todos, err = team.GetQATodo(); err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Todo not found."})
return
}
for _, t := range todos {
if t.Id == wid {
c.Set("todo", t)
c.Next()
return
}
}
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Unable to find the requested QA Todo"})
}
func showTodo(c *gin.Context) {
c.JSON(http.StatusOK, c.MustGet("todo"))
}
func deleteQATodo(c *gin.Context) {
todo := c.MustGet("todo").(*fic.QATodo)
if _, err := todo.Delete(); err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
} else {
c.Status(http.StatusOK)
}
}