2022-10-30 04:05:38 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import "github.com/hay-kot/homebox/backend/internal/data/repo"
|
|
|
|
|
|
|
|
type AllServices struct {
|
|
|
|
User *UserService
|
|
|
|
Group *GroupService
|
|
|
|
Items *ItemService
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
at: attachmentTokens{},
|
|
|
|
autoIncrementAssetID: options.autoIncrementAssetID,
|
2022-10-30 04:05:38 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|