qa: Managers can view team and manage theirs todo list
This commit is contained in:
parent
b94beb363b
commit
cd64fc90bf
13 changed files with 526 additions and 24 deletions
|
|
@ -29,4 +29,5 @@ func DeclareRoutes(router *gin.RouterGroup) {
|
|||
}))
|
||||
|
||||
declareTodoManagerRoutes(apiManagerRoutes)
|
||||
declareTeamsRoutes(apiManagerRoutes)
|
||||
}
|
||||
|
|
|
|||
53
qa/api/team.go
Normal file
53
qa/api/team.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func declareTeamsRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/teams", listTeams)
|
||||
|
||||
teamsRoutes := router.Group("/teams/:tid")
|
||||
teamsRoutes.Use(teamHandler)
|
||||
teamsRoutes.GET("", showTeam)
|
||||
|
||||
declareTodoRoutes(teamsRoutes)
|
||||
declareTodoManagerRoutes(teamsRoutes)
|
||||
}
|
||||
|
||||
func teamHandler(c *gin.Context) {
|
||||
var team *fic.Team
|
||||
if tid, err := strconv.ParseInt(string(c.Param("tid")), 10, 64); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Bad team identifier."})
|
||||
return
|
||||
} else if team, err = fic.GetTeam(tid); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Team not found."})
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("team", team)
|
||||
|
||||
c.Next()
|
||||
}
|
||||
|
||||
func listTeams(c *gin.Context) {
|
||||
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
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, teams)
|
||||
}
|
||||
|
||||
func showTeam(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, c.MustGet("team"))
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue