mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
feat: set html base path from server base path
refactor: services
This commit is contained in:
@@ -22,14 +22,22 @@ type AggregationService struct {
|
||||
HeartbeatService *HeartbeatService
|
||||
}
|
||||
|
||||
func NewAggregationService(db *gorm.DB, userService *UserService, summaryService *SummaryService, heartbeatService *HeartbeatService) *AggregationService {
|
||||
return &AggregationService{
|
||||
Config: models.GetConfig(),
|
||||
Db: db,
|
||||
UserService: userService,
|
||||
SummaryService: summaryService,
|
||||
HeartbeatService: heartbeatService,
|
||||
}
|
||||
}
|
||||
|
||||
type AggregationJob struct {
|
||||
UserID string
|
||||
From time.Time
|
||||
To time.Time
|
||||
}
|
||||
|
||||
func (srv *AggregationService) Init() {}
|
||||
|
||||
// Schedule a job to (re-)generate summaries every day shortly after midnight
|
||||
// TODO: Make configurable
|
||||
func (srv *AggregationService) Schedule() {
|
||||
|
@@ -13,9 +13,14 @@ type AliasService struct {
|
||||
Db *gorm.DB
|
||||
}
|
||||
|
||||
var userAliases sync.Map
|
||||
func NewAliasService(db *gorm.DB) *AliasService {
|
||||
return &AliasService{
|
||||
Config: models.GetConfig(),
|
||||
Db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (srv *AliasService) Init() {}
|
||||
var userAliases sync.Map
|
||||
|
||||
func (srv *AliasService) LoadUserAliases(userId string) error {
|
||||
var aliases []*models.Alias
|
||||
|
@@ -1,5 +0,0 @@
|
||||
package services
|
||||
|
||||
type Initializable interface {
|
||||
Init()
|
||||
}
|
@@ -21,7 +21,12 @@ type HeartbeatService struct {
|
||||
Db *gorm.DB
|
||||
}
|
||||
|
||||
func (srv *HeartbeatService) Init() {}
|
||||
func NewHeartbeatService(db *gorm.DB) *HeartbeatService {
|
||||
return &HeartbeatService{
|
||||
Config: models.GetConfig(),
|
||||
Db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (srv *HeartbeatService) InsertBatch(heartbeats []*models.Heartbeat) error {
|
||||
var batch []interface{}
|
||||
|
@@ -21,15 +21,21 @@ type SummaryService struct {
|
||||
AliasService *AliasService
|
||||
}
|
||||
|
||||
func NewSummaryService(db *gorm.DB, heartbeatService *HeartbeatService, aliasService *AliasService) *SummaryService {
|
||||
return &SummaryService{
|
||||
Config: models.GetConfig(),
|
||||
Cache: cache.New(24*time.Hour, 24*time.Hour),
|
||||
Db: db,
|
||||
HeartbeatService: heartbeatService,
|
||||
AliasService: aliasService,
|
||||
}
|
||||
}
|
||||
|
||||
type Interval struct {
|
||||
Start time.Time
|
||||
End time.Time
|
||||
}
|
||||
|
||||
func (srv *SummaryService) Init() {
|
||||
srv.Cache = cache.New(24*time.Hour, 24*time.Hour)
|
||||
}
|
||||
|
||||
func (srv *SummaryService) Construct(from, to time.Time, user *models.User, recompute bool) (*models.Summary, error) {
|
||||
var existingSummaries []*models.Summary
|
||||
var cacheKey string
|
||||
|
@@ -13,7 +13,12 @@ type UserService struct {
|
||||
Db *gorm.DB
|
||||
}
|
||||
|
||||
func (srv *UserService) Init() {}
|
||||
func NewUserService(db *gorm.DB) *UserService {
|
||||
return &UserService{
|
||||
Config: models.GetConfig(),
|
||||
Db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (srv *UserService) GetUserById(userId string) (*models.User, error) {
|
||||
u := &models.User{}
|
||||
|
Reference in New Issue
Block a user