Write docs!

This commit is contained in:
nemunaire 2018-03-09 19:07:08 +01:00
commit bcc598ebd5
37 changed files with 478 additions and 188 deletions

View file

@ -5,6 +5,7 @@ import (
"time"
)
// Claim represents an issue, a bug or a ToDo item.
type Claim struct {
Id int64 `json:"id"`
Subject string `json:"subject"`
@ -15,11 +16,13 @@ type Claim struct {
Priority string `json:"priority"`
}
// GetClaim retrieves the claim with the given identifier.
func GetClaim(id int) (c Claim, err error) {
err = DBQueryRow("SELECT id_claim, subject, id_team, id_assignee, creation, state, priority FROM claims WHERE id_claim = ?", id).Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdAssignee, &c.Creation, &c.State, &c.Priority)
return
}
// GetClaims returns a list of all Claim registered in the database.
func GetClaims() (res []Claim, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_claim, subject, id_team, id_assignee, creation, state, priority FROM claims"); err != nil {
@ -39,6 +42,7 @@ func GetClaims() (res []Claim, err error) {
return
}
// GetClaims returns a list of all Claim registered for the Team.
func (t Team) GetClaims() (res []Claim, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_claim, subject, IdTeam, id_assignee, creation, state, priority FROM claims WHERE IdTeam = ?", t.Id); err != nil {
@ -58,6 +62,7 @@ func (t Team) GetClaims() (res []Claim, err error) {
return
}
// NewClaim creates and fills a new struct Claim and registers it into the database.
func NewClaim(subject string, team *Team, assignee *ClaimAssignee, priority string) (Claim, error) {
var tid *int64
if team == nil {
@ -82,6 +87,7 @@ func NewClaim(subject string, team *Team, assignee *ClaimAssignee, priority stri
}
}
// GetTeam returns the Team linked to the issue, if any.
func (c Claim) GetTeam() (*Team, error) {
if c.IdTeam == nil {
return nil, nil
@ -92,10 +98,12 @@ func (c Claim) GetTeam() (*Team, error) {
}
}
// SetTeam defines the Team that is linked to this issue.
func (c Claim) SetTeam(t Team) {
c.IdTeam = &t.Id
}
// Update applies modifications back to the database.
func (c Claim) Update() (int64, error) {
if res, err := DBExec("UPDATE claims SET subject = ?, id_team = ?, id_assignee = ?, creation = ?, state = ?, priority = ? WHERE id_claim = ?", c.Subject, c.IdTeam, c.IdAssignee, c.Creation, c.State, c.Priority, c.Id); err != nil {
return 0, err
@ -106,6 +114,7 @@ func (c Claim) Update() (int64, error) {
}
}
// Delete the issue from the database.
func (c Claim) Delete() (int64, error) {
if res, err := DBExec("DELETE FROM claims WHERE id_claim = ?", c.Id); err != nil {
return 0, err
@ -116,6 +125,7 @@ func (c Claim) Delete() (int64, error) {
}
}
// ClearClaims removes all issues from database.
func ClearClaims() (int64, error) {
if res, err := DBExec("DELETE FROM claims"); err != nil {
return 0, err
@ -126,14 +136,18 @@ func ClearClaims() (int64, error) {
}
}
// ClaimDescription represents some text describing an issue.
type ClaimDescription struct {
Id int64 `json:"id"`
// IdAssignee stores the user who handle the claim (or 0 if nobody handles it).
IdAssignee int64 `json:"id_assignee"`
// Content is the raw description.
Content string `json:"content"`
// Date is the timestamp when the description was written.
Date time.Time `json:"date"`
}
// GetDescriptions returns a list of all descriptions stored in the database for the Claim.
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 {
@ -153,6 +167,7 @@ func (c Claim) GetDescriptions() (res []ClaimDescription, err error) {
return
}
// 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 {
return ClaimDescription{}, err
@ -163,6 +178,7 @@ func (c Claim) AddDescription(content string, assignee ClaimAssignee) (ClaimDesc
}
}
// 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 {
return 0, err
@ -173,6 +189,7 @@ func (d ClaimDescription) Update() (int64, error) {
}
}
// Delete the description in the database.
func (d ClaimDescription) Delete() (int64, error) {
if res, err := DBExec("DELETE FROM claim_descriptions WHERE id_description = ?", d.Id); err != nil {
return 0, err
@ -183,17 +200,19 @@ func (d ClaimDescription) Delete() (int64, error) {
}
}
// ClaimAssignee represents a user that can handle claims.
type ClaimAssignee struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
// GetAssignee retrieves an assignee from its identifier.
func GetAssignee(id int64) (a ClaimAssignee, err error) {
err = DBQueryRow("SELECT id_assignee, name FROM claim_assignees WHERE id_assignee = ?", id).Scan(&a.Id, &a.Name)
return
}
// GetAssignees returns a list of all assignees found in the database.
func GetAssignees() (res []ClaimAssignee, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_assignee, name FROM claim_assignees"); err != nil {
@ -213,6 +232,7 @@ func GetAssignees() (res []ClaimAssignee, err error) {
return
}
// NewClaimAssignee creates and fills a new struct ClaimAssignee and registers it into the database.
func NewClaimAssignee(name string) (ClaimAssignee, error) {
if res, err := DBExec("INSERT INTO claim_assignees (name) VALUES (?)", name); err != nil {
return ClaimAssignee{}, err
@ -223,6 +243,7 @@ func NewClaimAssignee(name string) (ClaimAssignee, error) {
}
}
// Update applies modifications back to the database
func (a ClaimAssignee) Update() (int64, error) {
if res, err := DBExec("UPDATE claim_assignees SET name = ? WHERE id_assignee = ?", a.Name, a.Id); err != nil {
return 0, err
@ -233,6 +254,7 @@ func (a ClaimAssignee) Update() (int64, error) {
}
}
// Delete the assignee in the database.
func (a ClaimAssignee) Delete() (int64, error) {
if res, err := DBExec("DELETE FROM claim_assignees WHERE id_assignee = ?", a.Id); err != nil {
return 0, err
@ -243,6 +265,7 @@ func (a ClaimAssignee) Delete() (int64, error) {
}
}
// ClearAssignees removes all assignees from database.
func ClearAssignees() (int64, error) {
if res, err := DBExec("DELETE FROM claim_assignees"); err != nil {
return 0, err
@ -253,6 +276,7 @@ func ClearAssignees() (int64, error) {
}
}
// GetAssignee returns the assignee assigned to the claim.
func (c Claim) GetAssignee() (*ClaimAssignee, error) {
if c.IdAssignee == nil {
return nil, nil
@ -263,6 +287,7 @@ func (c Claim) GetAssignee() (*ClaimAssignee, error) {
}
}
// SetAssignee defines the assignee that'll handle the claim.
func (c Claim) SetAssignee(a ClaimAssignee) {
c.IdAssignee = &a.Id
}