2020-11-08 12:12:49 +03:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2022-03-20 18:27:21 +03:00
|
|
|
datastructure "github.com/duke-git/lancet/v2/datastructure/set"
|
2020-11-08 12:12:49 +03:00
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IAggregationService interface {
|
|
|
|
Schedule()
|
2022-03-20 18:27:21 +03:00
|
|
|
Run(set datastructure.Set[string]) error
|
2020-11-08 12:12:49 +03:00
|
|
|
}
|
|
|
|
|
2021-01-17 11:24:09 +03:00
|
|
|
type IMiscService interface {
|
|
|
|
ScheduleCountTotalTime()
|
|
|
|
}
|
|
|
|
|
2020-11-08 12:12:49 +03:00
|
|
|
type IAliasService interface {
|
2021-01-21 02:26:52 +03:00
|
|
|
Create(*models.Alias) (*models.Alias, error)
|
|
|
|
Delete(*models.Alias) error
|
|
|
|
DeleteMulti([]*models.Alias) error
|
2020-11-08 12:12:49 +03:00
|
|
|
IsInitialized(string) bool
|
2021-01-21 02:26:52 +03:00
|
|
|
InitializeUser(string) error
|
|
|
|
GetByUser(string) ([]*models.Alias, error)
|
2022-01-13 19:10:24 +03:00
|
|
|
GetByUserAndType(string, uint8) ([]*models.Alias, error)
|
2021-01-21 02:26:52 +03:00
|
|
|
GetByUserAndKeyAndType(string, string, uint8) ([]*models.Alias, error)
|
|
|
|
GetAliasOrDefault(string, uint8, string) (string, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type IHeartbeatService interface {
|
2021-02-05 20:47:28 +03:00
|
|
|
Insert(*models.Heartbeat) error
|
2020-11-08 12:12:49 +03:00
|
|
|
InsertBatch([]*models.Heartbeat) error
|
2022-03-19 12:30:32 +03:00
|
|
|
Count(bool) (int64, error)
|
2021-02-13 13:23:58 +03:00
|
|
|
CountByUser(*models.User) (int64, error)
|
|
|
|
CountByUsers([]*models.User) ([]*models.CountByUser, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
GetAllWithin(time.Time, time.Time, *models.User) ([]*models.Heartbeat, error)
|
2022-03-13 10:17:50 +03:00
|
|
|
GetAllWithinByFilters(time.Time, time.Time, *models.User, *models.Filters) ([]*models.Heartbeat, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
GetFirstByUsers() ([]*models.TimeByUser, error)
|
2021-04-30 11:12:28 +03:00
|
|
|
GetLatestByUser(*models.User) (*models.Heartbeat, error)
|
2021-02-06 02:31:30 +03:00
|
|
|
GetLatestByOriginAndUser(string, *models.User) (*models.Heartbeat, error)
|
2021-05-01 14:52:03 +03:00
|
|
|
GetEntitySetByUser(uint8, *models.User) ([]string, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
DeleteBefore(time.Time) error
|
2022-03-17 13:55:13 +03:00
|
|
|
DeleteByUser(*models.User) error
|
2020-11-08 12:12:49 +03:00
|
|
|
}
|
|
|
|
|
2021-08-07 11:16:50 +03:00
|
|
|
type IDiagnosticsService interface {
|
|
|
|
Create(*models.Diagnostics) (*models.Diagnostics, error)
|
|
|
|
}
|
|
|
|
|
2020-11-08 12:12:49 +03:00
|
|
|
type IKeyValueService interface {
|
|
|
|
GetString(string) (*models.KeyStringValue, error)
|
2021-02-05 20:47:28 +03:00
|
|
|
MustGetString(string) *models.KeyStringValue
|
2020-11-08 12:12:49 +03:00
|
|
|
PutString(*models.KeyStringValue) error
|
|
|
|
DeleteString(string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type ILanguageMappingService interface {
|
|
|
|
GetById(uint) (*models.LanguageMapping, error)
|
|
|
|
GetByUser(string) ([]*models.LanguageMapping, error)
|
|
|
|
ResolveByUser(string) (map[string]string, error)
|
|
|
|
Create(*models.LanguageMapping) (*models.LanguageMapping, error)
|
|
|
|
Delete(mapping *models.LanguageMapping) error
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:59:34 +03:00
|
|
|
type IProjectLabelService interface {
|
|
|
|
GetById(uint) (*models.ProjectLabel, error)
|
|
|
|
GetByUser(string) ([]*models.ProjectLabel, error)
|
2021-06-12 11:44:19 +03:00
|
|
|
GetByUserGrouped(string) (map[string][]*models.ProjectLabel, error)
|
2021-10-13 18:12:55 +03:00
|
|
|
GetByUserGroupedInverted(string) (map[string][]*models.ProjectLabel, error)
|
2021-06-11 21:59:34 +03:00
|
|
|
Create(*models.ProjectLabel) (*models.ProjectLabel, error)
|
2021-06-12 12:09:24 +03:00
|
|
|
Delete(*models.ProjectLabel) error
|
2021-06-11 21:59:34 +03:00
|
|
|
}
|
|
|
|
|
2021-04-30 15:07:14 +03:00
|
|
|
type IMailService interface {
|
|
|
|
SendPasswordReset(*models.User, string) error
|
2021-08-07 00:28:03 +03:00
|
|
|
SendWakatimeFailureNotification(*models.User, int) error
|
2021-04-30 15:07:14 +03:00
|
|
|
SendImportNotification(*models.User, time.Duration, int) error
|
|
|
|
SendReport(*models.User, *models.Report) error
|
|
|
|
}
|
|
|
|
|
2021-12-14 17:30:03 +03:00
|
|
|
type IDurationService interface {
|
2021-12-26 19:02:14 +03:00
|
|
|
Get(time.Time, time.Time, *models.User, *models.Filters) (models.Durations, error)
|
2021-12-14 17:30:03 +03:00
|
|
|
}
|
|
|
|
|
2020-11-08 12:12:49 +03:00
|
|
|
type ISummaryService interface {
|
2021-12-26 19:02:14 +03:00
|
|
|
Aliased(time.Time, time.Time, *models.User, SummaryRetriever, *models.Filters, bool) (*models.Summary, error)
|
|
|
|
Retrieve(time.Time, time.Time, *models.User, *models.Filters) (*models.Summary, error)
|
|
|
|
Summarize(time.Time, time.Time, *models.User, *models.Filters) (*models.Summary, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
GetLatestByUser() ([]*models.TimeByUser, error)
|
|
|
|
DeleteByUser(string) error
|
|
|
|
Insert(*models.Summary) error
|
|
|
|
}
|
|
|
|
|
2021-04-30 15:07:14 +03:00
|
|
|
type IReportService interface {
|
|
|
|
Schedule()
|
2021-04-30 17:20:08 +03:00
|
|
|
SyncSchedule(user *models.User) bool
|
2021-04-30 15:07:14 +03:00
|
|
|
Run(*models.User, time.Duration) error
|
|
|
|
}
|
|
|
|
|
2022-10-02 01:01:39 +03:00
|
|
|
type ILeaderboardService interface {
|
|
|
|
ScheduleDefault()
|
|
|
|
Run([]*models.User, *models.IntervalKey, []uint8) error
|
2022-10-02 11:13:39 +03:00
|
|
|
ExistsAnyByUser(string) (bool, error)
|
2022-10-04 00:52:22 +03:00
|
|
|
GetByInterval(*models.IntervalKey, bool) (models.Leaderboard, error)
|
|
|
|
GetAggregatedByInterval(*models.IntervalKey, *uint8, bool) (models.Leaderboard, error)
|
2022-10-02 01:01:39 +03:00
|
|
|
GenerateByUser(*models.User, *models.IntervalKey) (*models.LeaderboardItem, error)
|
|
|
|
GenerateAggregatedByUser(*models.User, *models.IntervalKey, uint8) ([]*models.LeaderboardItem, error)
|
|
|
|
}
|
|
|
|
|
2020-11-08 12:12:49 +03:00
|
|
|
type IUserService interface {
|
|
|
|
GetUserById(string) (*models.User, error)
|
|
|
|
GetUserByKey(string) (*models.User, error)
|
2021-04-05 23:57:57 +03:00
|
|
|
GetUserByEmail(string) (*models.User, error)
|
|
|
|
GetUserByResetToken(string) (*models.User, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
GetAll() ([]*models.User, error)
|
2022-10-04 00:52:22 +03:00
|
|
|
GetMany([]string) ([]*models.User, error)
|
|
|
|
GetManyMapped([]string) (map[string]*models.User, error)
|
2021-04-30 15:07:14 +03:00
|
|
|
GetAllByReports(bool) ([]*models.User, error)
|
2022-10-02 01:01:39 +03:00
|
|
|
GetAllByLeaderboard(bool) ([]*models.User, error)
|
2021-06-26 13:42:51 +03:00
|
|
|
GetActive(bool) ([]*models.User, error)
|
2021-02-12 20:49:47 +03:00
|
|
|
Count() (int64, error)
|
|
|
|
CreateOrGet(*models.Signup, bool) (*models.User, bool, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
Update(*models.User) (*models.User, error)
|
2021-02-03 00:54:22 +03:00
|
|
|
Delete(*models.User) error
|
2020-11-08 12:12:49 +03:00
|
|
|
ResetApiKey(*models.User) (*models.User, error)
|
2022-01-21 14:35:05 +03:00
|
|
|
SetWakatimeApiCredentials(*models.User, string, string) (*models.User, error)
|
2020-11-08 12:12:49 +03:00
|
|
|
MigrateMd5Password(*models.User, *models.Login) (*models.User, error)
|
2021-04-05 23:57:57 +03:00
|
|
|
GenerateResetToken(*models.User) (*models.User, error)
|
2021-02-07 00:32:03 +03:00
|
|
|
FlushCache()
|
2020-11-08 12:12:49 +03:00
|
|
|
}
|