2024-01-04 17:55:26 +00:00
|
|
|
// Package services provides the core business logic for the application.
|
2022-10-30 04:05:38 +00:00
|
|
|
package services
|
|
|
|
|
2023-02-13 19:00:29 +00:00
|
|
|
import (
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
|
|
|
)
|
2022-10-30 04:05:38 +00:00
|
|
|
|
|
|
|
type AllServices struct {
|
2023-03-21 19:32:48 +00:00
|
|
|
User *UserService
|
|
|
|
Group *GroupService
|
|
|
|
Items *ItemService
|
|
|
|
BackgroundService *BackgroundService
|
2022-10-30 04:05:38 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 23:17:55 +00:00
|
|
|
type OptionsFunc func(*options)
|
|
|
|
|
|
|
|
type options struct {
|
|
|
|
autoIncrementAssetID bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAutoIncrementAssetID(v bool) func(*options) {
|
|
|
|
return func(o *options) {
|
|
|
|
o.autoIncrementAssetID = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(repos *repo.AllRepos, opts ...OptionsFunc) *AllServices {
|
2022-10-30 04:05:38 +00:00
|
|
|
if repos == nil {
|
|
|
|
panic("repos cannot be nil")
|
|
|
|
}
|
|
|
|
|
2022-11-13 23:17:55 +00:00
|
|
|
options := &options{
|
|
|
|
autoIncrementAssetID: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(options)
|
|
|
|
}
|
|
|
|
|
2022-10-30 04:05:38 +00:00
|
|
|
return &AllServices{
|
|
|
|
User: &UserService{repos},
|
|
|
|
Group: &GroupService{repos},
|
|
|
|
Items: &ItemService{
|
2022-11-13 23:17:55 +00:00
|
|
|
repo: repos,
|
|
|
|
autoIncrementAssetID: options.autoIncrementAssetID,
|
2022-10-30 04:05:38 +00:00
|
|
|
},
|
2023-03-21 19:32:48 +00:00
|
|
|
BackgroundService: &BackgroundService{repos},
|
2022-10-30 04:05:38 +00:00
|
|
|
}
|
|
|
|
}
|