Files
RenewCMS/internal/infrastructure/useCases/CheckForUpdate.go
T

30 lines
841 B
Go

package useCases
import (
"RenewCMS/internal/domain/update"
"time"
)
type CheckForUpdateUseCase struct {
feed update.ReleaseFeed
store update.StatusStore
currentVersion string
now func() time.Time
}
func NewCheckForUpdateUseCase(feed update.ReleaseFeed, store update.StatusStore, currentVersion string, now func() time.Time) *CheckForUpdateUseCase {
return &CheckForUpdateUseCase{feed: feed, store: store, currentVersion: currentVersion, now: now}
}
func (c *CheckForUpdateUseCase) Check() (update.UpdateStatus, error) {
release, err := c.feed.Latest()
if err != nil {
return update.UpdateStatus{}, err
}
result := update.NewResult(release, c.now())
if err := c.store.Save(result); err != nil {
return update.UpdateStatus{}, err
}
return update.NewStatus(c.currentVersion, &result), nil
}