admin: precise kind of error when filling claim

This commit is contained in:
nemunaire 2021-09-02 17:11:07 +02:00
parent 864f78e8fa
commit 2b58e707ca

View File

@ -80,16 +80,16 @@ func showClaim(claim fic.Claim, _ []byte) (interface{}, error) {
var e ClaimExported var e ClaimExported
var err error var err error
if e.Team, err = claim.GetTeam(); err != nil { if e.Team, err = claim.GetTeam(); err != nil {
return nil, err return nil, fmt.Errorf("Unable to find associated team: %w", err)
} }
if e.Exercice, err = claim.GetExercice(); err != nil { if e.Exercice, err = claim.GetExercice(); err != nil {
return nil, err return nil, fmt.Errorf("Unable to find associated exercice: %w", err)
} }
if e.Assignee, err = claim.GetAssignee(); err != nil { if e.Assignee, err = claim.GetAssignee(); err != nil {
return nil, err return nil, fmt.Errorf("Unable to find associated assignee: %w", err)
} }
if e.Descriptions, err = claim.GetDescriptions(); err != nil { if e.Descriptions, err = claim.GetDescriptions(); err != nil {
return nil, err return nil, fmt.Errorf("Unable to find claim's descriptions: %w", err)
} }
e.LastUpdate = e.Creation e.LastUpdate = e.Creation
@ -112,13 +112,13 @@ func showClaim(claim fic.Claim, _ []byte) (interface{}, error) {
type ClaimUploaded struct { type ClaimUploaded struct {
fic.Claim fic.Claim
Whoami *int64 `json:"whoami"` Whoami *int64 `json:"whoami"`
} }
func newClaim(_ httprouter.Params, body []byte) (interface{}, error) { func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var uc ClaimUploaded var uc ClaimUploaded
if err := json.Unmarshal(body, &uc); err != nil { if err := json.Unmarshal(body, &uc); err != nil {
return nil, err return nil, fmt.Errorf("Unable to decode JSON: %w", err)
} }
if uc.Subject == "" { if uc.Subject == "" {
@ -128,7 +128,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var t *fic.Team var t *fic.Team
if uc.IdTeam != nil { if uc.IdTeam != nil {
if team, err := fic.GetTeam(*uc.IdTeam); err != nil { if team, err := fic.GetTeam(*uc.IdTeam); err != nil {
return nil, err return nil, fmt.Errorf("Unable to get associated team: %w", err)
} else { } else {
t = &team t = &team
} }
@ -139,7 +139,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var e *fic.Exercice var e *fic.Exercice
if uc.IdExercice != nil { if uc.IdExercice != nil {
if exercice, err := fic.GetExercice(*uc.IdExercice); err != nil { if exercice, err := fic.GetExercice(*uc.IdExercice); err != nil {
return nil, err return nil, fmt.Errorf("Unable to get associated exercice: %w", err)
} else { } else {
e = &exercice e = &exercice
} }
@ -150,7 +150,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var a *fic.ClaimAssignee var a *fic.ClaimAssignee
if uc.IdAssignee != nil { if uc.IdAssignee != nil {
if assignee, err := fic.GetAssignee(*uc.IdAssignee); err != nil { if assignee, err := fic.GetAssignee(*uc.IdAssignee); err != nil {
return nil, err return nil, fmt.Errorf("Unable to get associated assignee: %w", err)
} else { } else {
a = &assignee a = &assignee
} }
@ -183,13 +183,13 @@ func generateTeamIssuesFile(team fic.Team) error {
func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) { func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
var ud fic.ClaimDescription var ud fic.ClaimDescription
if err := json.Unmarshal(body, &ud); err != nil { if err := json.Unmarshal(body, &ud); err != nil {
return nil, err return nil, fmt.Errorf("Unable to decode JSON: %w", err)
} }
if assignee, err := fic.GetAssignee(ud.IdAssignee); err != nil { if assignee, err := fic.GetAssignee(ud.IdAssignee); err != nil {
return nil, err return nil, fmt.Errorf("Unable to get associated assignee: %w", err)
} else if description, err := claim.AddDescription(ud.Content, assignee, ud.Publish); err != nil { } else if description, err := claim.AddDescription(ud.Content, assignee, ud.Publish); err != nil {
return nil, err return nil, fmt.Errorf("Unable to add description: %w", err)
} else { } else {
if team, _ := claim.GetTeam(); team != nil { if team, _ := claim.GetTeam(); team != nil {
err = generateTeamIssuesFile(*team) err = generateTeamIssuesFile(*team)
@ -202,11 +202,11 @@ func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) { func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
var ud fic.ClaimDescription var ud fic.ClaimDescription
if err := json.Unmarshal(body, &ud); err != nil { if err := json.Unmarshal(body, &ud); err != nil {
return nil, err return nil, fmt.Errorf("Unable to decode JSON: %w", err)
} }
if _, err := ud.Update(); err != nil { if _, err := ud.Update(); err != nil {
return nil, err return nil, fmt.Errorf("Unable to update description: %w", err)
} else { } else {
if team, _ := claim.GetTeam(); team != nil { if team, _ := claim.GetTeam(); team != nil {
err = generateTeamIssuesFile(*team) err = generateTeamIssuesFile(*team)
@ -219,13 +219,13 @@ func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
func updateClaim(claim fic.Claim, body []byte) (interface{}, error) { func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
var uc ClaimUploaded var uc ClaimUploaded
if err := json.Unmarshal(body, &uc); err != nil { if err := json.Unmarshal(body, &uc); err != nil {
return nil, err return nil, fmt.Errorf("Unable to decode JSON: %w", err)
} }
uc.Id = claim.Id uc.Id = claim.Id
if _, err := uc.Update(); err != nil { if _, err := uc.Update(); err != nil {
return nil, err return nil, fmt.Errorf("Unable to update claim: %w", err)
} else { } else {
if claim.State != uc.State { if claim.State != uc.State {
if uc.Whoami != nil { if uc.Whoami != nil {
@ -275,7 +275,7 @@ func showClaimAssignee(assignee fic.ClaimAssignee, _ []byte) (interface{}, error
func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) { func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
var ua fic.ClaimAssignee var ua fic.ClaimAssignee
if err := json.Unmarshal(body, &ua); err != nil { if err := json.Unmarshal(body, &ua); err != nil {
return nil, err return nil, fmt.Errorf("Unable to decode JSON: %w", err)
} }
return fic.NewClaimAssignee(ua.Name) return fic.NewClaimAssignee(ua.Name)
@ -284,13 +284,13 @@ func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
func updateClaimAssignee(assignee fic.ClaimAssignee, body []byte) (interface{}, error) { func updateClaimAssignee(assignee fic.ClaimAssignee, body []byte) (interface{}, error) {
var ua fic.ClaimAssignee var ua fic.ClaimAssignee
if err := json.Unmarshal(body, &ua); err != nil { if err := json.Unmarshal(body, &ua); err != nil {
return nil, err return nil, fmt.Errorf("Unable to decode JSON: %w", err)
} }
ua.Id = assignee.Id ua.Id = assignee.Id
if _, err := ua.Update(); err != nil { if _, err := ua.Update(); err != nil {
return nil, err return nil, fmt.Errorf("Unable to update claim assignee: %w", err)
} else { } else {
return ua, nil return ua, nil
} }