frontend: display issues related to the team
This commit is contained in:
parent
7bec409ab8
commit
a3ffdeae17
12 changed files with 238 additions and 12 deletions
|
|
@ -3,6 +3,9 @@ package api
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
|
@ -11,6 +14,11 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
router.GET("/api/teams/:tid/issue.json", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.MyIssueFile()
|
||||
})))
|
||||
|
||||
// Tasks
|
||||
router.GET("/api/claims", apiHandler(getClaims))
|
||||
router.POST("/api/claims", apiHandler(newClaim))
|
||||
|
|
@ -24,6 +32,8 @@ func init() {
|
|||
router.POST("/api/claims/:cid", apiHandler(claimHandler(addClaimDescription)))
|
||||
router.DELETE("/api/claims/:cid", apiHandler(claimHandler(deleteClaim)))
|
||||
|
||||
router.PUT("/api/claims/:cid/descriptions", apiHandler(claimHandler(updateClaimDescription)))
|
||||
|
||||
// Assignees
|
||||
router.GET("/api/claims-assignees", apiHandler(getAssignees))
|
||||
router.POST("/api/claims-assignees", apiHandler(newAssignee))
|
||||
|
|
@ -157,6 +167,17 @@ func clearClaims(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return fic.ClearClaims()
|
||||
}
|
||||
|
||||
func generateTeamIssuesFile(team fic.Team) error {
|
||||
if my, err := team.MyIssueFile(); err != nil {
|
||||
return err
|
||||
} else if j, err := json.Marshal(my); err != nil {
|
||||
return err
|
||||
} else if err = ioutil.WriteFile(path.Join(TeamsDir, fmt.Sprintf("%d", team.Id), "issues.json"), j, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
|
||||
var ud fic.ClaimDescription
|
||||
if err := json.Unmarshal(body, &ud); err != nil {
|
||||
|
|
@ -165,8 +186,31 @@ func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
|
|||
|
||||
if assignee, err := fic.GetAssignee(ud.IdAssignee); err != nil {
|
||||
return nil, err
|
||||
} else if description, err := claim.AddDescription(ud.Content, assignee, ud.Publish); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return claim.AddDescription(ud.Content, assignee)
|
||||
if team, _ := claim.GetTeam(); team != nil {
|
||||
err = generateTeamIssuesFile(*team)
|
||||
}
|
||||
|
||||
return description, err
|
||||
}
|
||||
}
|
||||
|
||||
func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
|
||||
var ud fic.ClaimDescription
|
||||
if err := json.Unmarshal(body, &ud); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := ud.Update(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if team, _ := claim.GetTeam(); team != nil {
|
||||
err = generateTeamIssuesFile(*team)
|
||||
}
|
||||
|
||||
return ud, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +225,11 @@ func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
|
|||
if _, err := uc.Update(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return uc, nil
|
||||
if team, _ := claim.GetTeam(); team != nil {
|
||||
err = generateTeamIssuesFile(*team)
|
||||
}
|
||||
|
||||
return uc, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue