33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package useCases
|
|
|
|
import "RenewCMS/internal/domain/update"
|
|
|
|
type GetUpdateStatusUseCase struct {
|
|
store update.StatusStore
|
|
jobs update.JobStore
|
|
helper update.HelperDetector
|
|
currentVersion string
|
|
}
|
|
|
|
func NewGetUpdateStatusUseCase(store update.StatusStore, jobs update.JobStore, helper update.HelperDetector, currentVersion string) *GetUpdateStatusUseCase {
|
|
return &GetUpdateStatusUseCase{store: store, jobs: jobs, helper: helper, currentVersion: currentVersion}
|
|
}
|
|
|
|
func (g *GetUpdateStatusUseCase) GetStatus(isOwner bool) update.UpdateStatus {
|
|
return buildUpdateStatus(g.store, g.jobs, g.currentVersion, isOwner && g.helper.Installed())
|
|
}
|
|
|
|
func buildUpdateStatus(store update.StatusStore, jobs update.JobStore, currentVersion string, canApply bool) update.UpdateStatus {
|
|
var status update.UpdateStatus
|
|
if result, found := store.Load(); found {
|
|
status = update.NewStatus(currentVersion, &result)
|
|
} else {
|
|
status = update.NewStatus(currentVersion, nil)
|
|
}
|
|
if job, found := jobs.Load(); found {
|
|
status = status.WithJob(job)
|
|
}
|
|
status.CanApply = canApply
|
|
return status
|
|
}
|