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-02-26 02:54:40 +00:00
|
|
|
User *UserService
|
|
|
|
Group *GroupService
|
|
|
|
Items *ItemService
|
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
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|