46 lines
958 B
Go
46 lines
958 B
Go
package handlers
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.coopgo.io/coopgo-platform/diags/storage"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func (h DiagsHandler) CreateDiag(diag storage.Diag) (*storage.Diag, error) {
|
|
if diag.ID == "" {
|
|
diag.ID = uuid.NewString()
|
|
}
|
|
|
|
if err := h.storage.CreateDiag(diag); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &diag, nil
|
|
}
|
|
|
|
func (h DiagsHandler) GetDiag(id string) (diag *storage.Diag, err error) {
|
|
diag, err = h.storage.GetDiag(id)
|
|
return
|
|
}
|
|
|
|
func (h DiagsHandler) GetDiags(namespaces []string, mindate *time.Time, maxdate *time.Time) (results []storage.Diag, err error) {
|
|
results = []storage.Diag{}
|
|
diags, err := h.storage.GetDiags(namespaces)
|
|
if err == nil {
|
|
for _, diag := range diags {
|
|
results = append(results, diag)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (h DiagsHandler) UpdateDiag(diag storage.Diag) (*storage.Diag, error) {
|
|
|
|
// Store the account
|
|
if err := h.storage.UpdateDiag(diag); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &diag, nil
|
|
} |