56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package main
|
|
|
|
// findings (novox/hq issue 1069): the whole-set findings kept (judgeSet, kb.go), or only those naming one
|
|
// record.
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// FindingRow is one whole-set finding as findings answers it.
|
|
type FindingRow struct {
|
|
Rule string `json:"rule"`
|
|
Records []string `json:"records"`
|
|
Says string `json:"says"`
|
|
At time.Time `json:"at"`
|
|
}
|
|
|
|
// Findings is the answer to findings.
|
|
type Findings struct {
|
|
Rows []FindingRow `json:"rows"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
// Findings is the whole-set findings kept, or only those naming one record, given as a record names it ("276",
|
|
// "ADR 276", "research 045") (novox/hq issue 1069).
|
|
func (k *KB) Findings(number string) (*Findings, error) {
|
|
named := ""
|
|
if strings.TrimSpace(number) != "" {
|
|
ref, err := ParseRef(number)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
key, ok := ref.Record()
|
|
if !ok {
|
|
return nil, fmt.Errorf("number is a record's number, such as 276 or research 045, not %q", number)
|
|
}
|
|
named = key.String()
|
|
}
|
|
all, err := k.Store.Findings(context.Background())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &Findings{Rows: []FindingRow{}}
|
|
for _, f := range all {
|
|
if named != "" && !contains(f.Records, named) {
|
|
continue
|
|
}
|
|
out.Rows = append(out.Rows, FindingRow{Rule: f.Rule, Records: f.Records, Says: f.Says, At: f.At})
|
|
}
|
|
out.Count = len(out.Rows)
|
|
return out, nil
|
|
}
|