50 lines
826 B
Go
50 lines
826 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/borgmatic"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Host struct {
|
|
gorm.Model
|
|
|
|
Name string `gorm:"not null"`
|
|
Token string `gorm:"not null"`
|
|
Infos []Info `gorm:"one2many:info;not null"`
|
|
}
|
|
|
|
func (h *Host) ArchivesCount() int {
|
|
c := 0
|
|
|
|
for _, item := range h.Infos {
|
|
if infos := *item.Infos(); infos != nil {
|
|
for _, info := range *item.Infos() {
|
|
c += len(info.Archives)
|
|
}
|
|
}
|
|
}
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
func (h *Host) LastArchive() *borgmatic.Archive {
|
|
var last *borgmatic.Archive
|
|
var lastDate *time.Time
|
|
|
|
for _, item := range h.Infos {
|
|
if infos := *item.Infos(); infos != nil {
|
|
for _, info := range infos {
|
|
for _, a := range info.Archives {
|
|
if lastDate == nil || a.End.After(*lastDate) {
|
|
last = &a
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return last
|
|
}
|