admin: Insert $team assignee in db automatically

This commit is contained in:
nemunaire 2021-09-03 12:18:02 +02:00
parent f5941dcece
commit abf0715dbf
4 changed files with 37 additions and 32 deletions

View File

@ -171,11 +171,11 @@ func clearClaims(_ httprouter.Params, _ []byte) (interface{}, error) {
func generateTeamIssuesFile(team fic.Team) error { func generateTeamIssuesFile(team fic.Team) error {
if my, err := team.MyIssueFile(); err != nil { if my, err := team.MyIssueFile(); err != nil {
return err return fmt.Errorf("Unable to generate issue FILE (tid=%d): %w", team.Id, err)
} else if j, err := json.Marshal(my); err != nil { } else if j, err := json.Marshal(my); err != nil {
return err return fmt.Errorf("Unable to encode issues' file JSON: %w", err)
} else if err = ioutil.WriteFile(path.Join(TeamsDir, fmt.Sprintf("%d", team.Id), "issues.json"), j, 0644); err != nil { } else if err = ioutil.WriteFile(path.Join(TeamsDir, fmt.Sprintf("%d", team.Id), "issues.json"), j, 0644); err != nil {
return err return fmt.Errorf("Unable to write issues' file: %w", err)
} }
return nil return nil
} }

View File

@ -283,9 +283,9 @@ func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httproute
func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) { func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) { return func(ps httprouter.Params, body []byte) (interface{}, error) {
if cid, err := strconv.ParseInt(string(ps.ByName("cid")), 10, 64); err != nil { if cid, err := strconv.ParseInt(string(ps.ByName("cid")), 10, 64); err != nil {
return nil, err return nil, fmt.Errorf("Invalid claim id: %w", err)
} else if claim, err := fic.GetClaim(cid); err != nil { } else if claim, err := fic.GetClaim(cid); err != nil {
return nil, err return nil, fmt.Errorf("Unable to find requested claim (id=%d): %w", cid, err)
} else { } else {
return f(claim, body) return f(claim, body)
} }

View File

@ -400,6 +400,8 @@ CREATE TABLE IF NOT EXISTS claim_assignees(
`); err != nil { `); err != nil {
return err return err
} }
db.Exec(`INSERT INTO claim_assignees VALUES (0, "$team");`)
db.Exec(`UPDATE claim_assignees SET id_assignee = 0 WHERE name = "$team";`)
if _, err := db.Exec(` if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS claims( CREATE TABLE IF NOT EXISTS claims(
id_claim INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, id_claim INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,

View File

@ -2,6 +2,7 @@ package fic
import ( import (
"database/sql" "database/sql"
"fmt"
"path" "path"
"time" "time"
) )
@ -394,7 +395,7 @@ func (t Team) MyIssueFile() (ret []teamIssueFile, err error) {
} }
if descriptions, err := claim.GetDescriptions(); err != nil { if descriptions, err := claim.GetDescriptions(); err != nil {
return nil, err return nil, fmt.Errorf("Error occurs during description retrieval (cid=%d): %w", claim.Id, err)
} else { } else {
tif := teamIssueFile{ tif := teamIssueFile{
Id: claim.Id, Id: claim.Id,
@ -410,7 +411,7 @@ func (t Team) MyIssueFile() (ret []teamIssueFile, err error) {
for _, description := range descriptions { for _, description := range descriptions {
if description.Publish { if description.Publish {
if people, err := description.GetAssignee(); err != nil { if people, err := description.GetAssignee(); err != nil {
return nil, err return nil, fmt.Errorf("Error ocurs during assignee retrieval (aid=%d): %w", description.IdAssignee, err)
} else { } else {
tif.Texts = append(tif.Texts, teamIssueText{ tif.Texts = append(tif.Texts, teamIssueText{
Content: description.Content, Content: description.Content,
@ -424,6 +425,8 @@ func (t Team) MyIssueFile() (ret []teamIssueFile, err error) {
ret = append(ret, tif) ret = append(ret, tif)
} }
} }
} else {
err = fmt.Errorf("Error occurs during claim retrieval: %w", err)
} }
return return