mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
40067d252e
chore: locally generated badges (resolve #348)
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package utils
|
|
|
|
import (
|
|
"github.com/muety/wakapi/models"
|
|
"github.com/muety/wakapi/services"
|
|
"github.com/muety/wakapi/utils"
|
|
"net/http"
|
|
)
|
|
|
|
func LoadUserSummary(ss services.ISummaryService, r *http.Request) (*models.Summary, error, int) {
|
|
summaryParams, err := utils.ParseSummaryParams(r)
|
|
if err != nil {
|
|
return nil, err, http.StatusBadRequest
|
|
}
|
|
return LoadUserSummaryByParams(ss, summaryParams)
|
|
}
|
|
|
|
func LoadUserSummaryByParams(ss services.ISummaryService, params *models.SummaryParams) (*models.Summary, error, int) {
|
|
var retrieveSummary services.SummaryRetriever = ss.Retrieve
|
|
if params.Recompute {
|
|
retrieveSummary = ss.Summarize
|
|
}
|
|
|
|
summary, err := ss.Aliased(
|
|
params.From,
|
|
params.To,
|
|
params.User,
|
|
retrieveSummary,
|
|
params.Filters,
|
|
params.Recompute,
|
|
)
|
|
if err != nil {
|
|
return nil, err, http.StatusInternalServerError
|
|
}
|
|
|
|
summary.FromTime = models.CustomTime(summary.FromTime.T().In(params.User.TZ()))
|
|
summary.ToTime = models.CustomTime(summary.ToTime.T().In(params.User.TZ()))
|
|
|
|
return summary, nil, http.StatusOK
|
|
}
|