66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package incidenttracker
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"io"
|
|
|
|
"github.com/spf13/cobra"
|
|
_ "modernc.org/sqlite"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidIncident = errors.New("invalid incident input")
|
|
ErrNotFound = errors.New("incident not found")
|
|
)
|
|
|
|
type Incident struct {
|
|
ID int64 `json:"id"`
|
|
Title string `json:"title"`
|
|
Severity string `json:"severity"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type IncidentStore struct {
|
|
//lint:ignore U1000 używane po zaimplementowaniu metod
|
|
db *sql.DB
|
|
}
|
|
|
|
func OpenStore(dbPath string) (*IncidentStore, error) {
|
|
db, err := sql.Open("sqlite", dbPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &IncidentStore{db: db}, nil
|
|
}
|
|
|
|
func (s *IncidentStore) Close() error {
|
|
return s.db.Close()
|
|
}
|
|
|
|
func (s *IncidentStore) InitSchema() error {
|
|
panic("TODO: CREATE TABLE IF NOT EXISTS incidents (...)")
|
|
}
|
|
|
|
func (s *IncidentStore) Add(title, severity string) (Incident, error) {
|
|
panic("TODO: zwaliduj title i severity (low|medium|high|critical), zapisz w SQLite")
|
|
}
|
|
|
|
func (s *IncidentStore) List(severity string) ([]Incident, error) {
|
|
panic("TODO: zwróć incydenty (jeśli severity != '' to przefiltruj)")
|
|
}
|
|
|
|
func (s *IncidentStore) Resolve(id int64) (Incident, error) {
|
|
panic("TODO: ustaw status='resolved' lub zwróć ErrNotFound")
|
|
}
|
|
|
|
func (s *IncidentStore) Stats() (map[string]int, error) {
|
|
panic("TODO: zwróć map[string]int{\"open\": X, \"resolved\": Y}")
|
|
}
|
|
|
|
func NewCLI(dbPath string, out io.Writer) *cobra.Command {
|
|
root := &cobra.Command{Use: "incident-tracker", SilenceUsage: true, SilenceErrors: true}
|
|
root.SetOut(out)
|
|
panic("TODO: dodaj podkomendy add, list, resolve, stats wypisujące JSON do out")
|
|
}
|