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
|
|
@ -412,6 +412,7 @@ CREATE TABLE IF NOT EXISTS claim_descriptions(
|
|||
id_assignee INTEGER NOT NULL,
|
||||
date TIMESTAMP NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
publish BOOLEAN NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY(id_assignee) REFERENCES claim_assignees(id_assignee),
|
||||
FOREIGN KEY(id_claim) REFERENCES claims(id_claim)
|
||||
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
||||
|
|
|
|||
|
|
@ -189,19 +189,21 @@ type ClaimDescription struct {
|
|||
Content string `json:"content"`
|
||||
// Date is the timestamp when the description was written.
|
||||
Date time.Time `json:"date"`
|
||||
// Publish indicates wether it is shown back to the team.
|
||||
Publish bool `json:"publish"`
|
||||
}
|
||||
|
||||
// GetDescriptions returns a list of all descriptions stored in the database for the Claim.
|
||||
func (c Claim) GetDescriptions() (res []ClaimDescription, err error) {
|
||||
func (c Claim) GetDescriptions() (res []ClaimDescription, err error) {
|
||||
var rows *sql.Rows
|
||||
if rows, err = DBQuery("SELECT id_description, id_assignee, content, date FROM claim_descriptions WHERE id_claim = ?", c.Id); err != nil {
|
||||
if rows, err = DBQuery("SELECT id_description, id_assignee, content, date, publish FROM claim_descriptions WHERE id_claim = ?", c.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var d ClaimDescription
|
||||
if err = rows.Scan(&d.Id, &d.IdAssignee, &d.Content, &d.Date); err != nil {
|
||||
if err = rows.Scan(&d.Id, &d.IdAssignee, &d.Content, &d.Date, &d.Publish); err != nil {
|
||||
return
|
||||
}
|
||||
res = append(res, d)
|
||||
|
|
@ -212,19 +214,25 @@ func (c Claim) GetDescriptions() (res []ClaimDescription, err error) {
|
|||
}
|
||||
|
||||
// AddDescription append in the database a new description; then returns the corresponding structure.
|
||||
func (c Claim) AddDescription(content string, assignee ClaimAssignee) (ClaimDescription, error) {
|
||||
if res, err := DBExec("INSERT INTO claim_descriptions (id_claim, id_assignee, content, date) VALUES (?, ?, ?, ?)", c.Id, assignee.Id, content, time.Now()); err != nil {
|
||||
func (c Claim) AddDescription(content string, assignee ClaimAssignee, publish bool) (ClaimDescription, error) {
|
||||
if res, err := DBExec("INSERT INTO claim_descriptions (id_claim, id_assignee, content, date, publish) VALUES (?, ?, ?, ?, ?)", c.Id, assignee.Id, content, time.Now(), publish); err != nil {
|
||||
return ClaimDescription{}, err
|
||||
} else if did, err := res.LastInsertId(); err != nil {
|
||||
return ClaimDescription{}, err
|
||||
} else {
|
||||
return ClaimDescription{did, assignee.Id, content, time.Now()}, nil
|
||||
return ClaimDescription{did, assignee.Id, content, time.Now(), publish}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetAssignee retrieves an assignee from its identifier.
|
||||
func (d ClaimDescription) GetAssignee() (a ClaimAssignee, err error) {
|
||||
err = DBQueryRow("SELECT id_assignee, name FROM claim_assignees WHERE id_assignee = ?", d.IdAssignee).Scan(&a.Id, &a.Name)
|
||||
return
|
||||
}
|
||||
|
||||
// Update applies modifications back to the database
|
||||
func (d ClaimDescription) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE claim_descriptions SET id_assignee = ?, content = ?, date = ? WHERE id_description = ?", d.IdAssignee, d.Content, d.Date, d.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE claim_descriptions SET id_assignee = ?, content = ?, date = ?, publish = ? WHERE id_description = ?", d.IdAssignee, d.Content, d.Date, d.Publish, d.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
@ -335,3 +343,67 @@ func (c Claim) GetAssignee() (*ClaimAssignee, error) {
|
|||
func (c Claim) SetAssignee(a ClaimAssignee) {
|
||||
c.IdAssignee = &a.Id
|
||||
}
|
||||
|
||||
type teamIssueText struct {
|
||||
Content string `json:"cnt"`
|
||||
Assignee string `json:"assignee"`
|
||||
Date time.Time `json:"date"`
|
||||
}
|
||||
|
||||
type teamIssueFile struct {
|
||||
Subject string `json:"subject"`
|
||||
Exercice *string `json:"exercice,omitempty"`
|
||||
Assignee *string `json:"assignee,omitempty"`
|
||||
State string `json:"state"`
|
||||
Priority string `json:"priority"`
|
||||
Texts []teamIssueText `json:"texts"`
|
||||
}
|
||||
|
||||
func (t Team) MyIssueFile() (ret []teamIssueFile, err error) {
|
||||
var claims []Claim
|
||||
if claims, err = t.GetClaims(); err == nil {
|
||||
for _, claim := range claims {
|
||||
var exercice *string = nil
|
||||
|
||||
if exo, err := claim.GetExercice(); err == nil && exo != nil {
|
||||
exercice = &exo.Title
|
||||
}
|
||||
|
||||
var assignee *string = nil
|
||||
if a, err := claim.GetAssignee(); err == nil && a != nil {
|
||||
assignee = &a.Name
|
||||
}
|
||||
|
||||
if descriptions, err := claim.GetDescriptions(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
tif := teamIssueFile{
|
||||
Subject: claim.Subject,
|
||||
Exercice: exercice,
|
||||
Assignee: assignee,
|
||||
State: claim.State,
|
||||
Priority: claim.Priority,
|
||||
Texts: []teamIssueText{},
|
||||
}
|
||||
|
||||
for _, description := range descriptions {
|
||||
if description.Publish {
|
||||
if people, err := description.GetAssignee(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
tif.Texts = append(tif.Texts, teamIssueText{
|
||||
Content: description.Content,
|
||||
Assignee: people.Name,
|
||||
Date: description.Date,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = append(ret, tif)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue