admin: improve claims with related exercices
This commit is contained in:
parent
2e3f7c6894
commit
32dc9c1a8c
5 changed files with 91 additions and 11 deletions
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
@ -11,9 +12,12 @@ import (
|
|||
|
||||
func init() {
|
||||
// Tasks
|
||||
router.GET("/api/claims/", apiHandler(getClaims))
|
||||
router.POST("/api/claims/", apiHandler(newClaim))
|
||||
router.DELETE("/api/claims/", apiHandler(clearClaims))
|
||||
router.GET("/api/claims", apiHandler(getClaims))
|
||||
router.POST("/api/claims", apiHandler(newClaim))
|
||||
router.DELETE("/api/claims", apiHandler(clearClaims))
|
||||
router.GET("/api/teams/:tid/claims", apiHandler(teamHandler(getTeamClaims)))
|
||||
router.GET("/api/exercices/:eid/claims", apiHandler(exerciceHandler(getExerciceClaims)))
|
||||
router.GET("/api/themes/:thid/exercices/:eid/claims", apiHandler(exerciceHandler(getExerciceClaims)))
|
||||
|
||||
router.GET("/api/claims/:cid", apiHandler(claimHandler(showClaim)))
|
||||
router.PUT("/api/claims/:cid", apiHandler(claimHandler(updateClaim)))
|
||||
|
@ -21,8 +25,8 @@ func init() {
|
|||
router.DELETE("/api/claims/:cid", apiHandler(claimHandler(deleteClaim)))
|
||||
|
||||
// Assignees
|
||||
router.GET("/api/claims-assignees/", apiHandler(getAssignees))
|
||||
router.POST("/api/claims-assignees/", apiHandler(newAssignee))
|
||||
router.GET("/api/claims-assignees", apiHandler(getAssignees))
|
||||
router.POST("/api/claims-assignees", apiHandler(newAssignee))
|
||||
|
||||
router.GET("/api/claims-assignees/:aid", apiHandler(claimAssigneeHandler(showClaimAssignee)))
|
||||
router.PUT("/api/claims-assignees/:aid", apiHandler(claimAssigneeHandler(updateClaimAssignee)))
|
||||
|
@ -33,6 +37,14 @@ func getClaims(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return fic.GetClaims()
|
||||
}
|
||||
|
||||
func getTeamClaims(team fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.GetClaims()
|
||||
}
|
||||
|
||||
func getExerciceClaims(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return exercice.GetClaims()
|
||||
}
|
||||
|
||||
type ClaimExported struct {
|
||||
Id int64 `json:"id"`
|
||||
Subject string `json:"subject"`
|
||||
|
@ -97,6 +109,10 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if uc.Subject == "" {
|
||||
return nil, errors.New("Claim's subject cannot be empty.")
|
||||
}
|
||||
|
||||
var t *fic.Team
|
||||
if uc.Team != nil {
|
||||
if team, err := fic.GetTeam(*uc.Team); err != nil {
|
||||
|
@ -130,6 +146,10 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
a = nil
|
||||
}
|
||||
|
||||
if uc.Priority == "" {
|
||||
uc.Priority = "medium"
|
||||
}
|
||||
|
||||
return fic.NewClaim(uc.Subject, t, e, a, uc.Priority)
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue