2022-09-12 22:47:27 +00:00
|
|
|
package repo
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/hay-kot/homebox/backend/pkgs/set"
|
|
|
|
)
|
2022-09-12 22:47:27 +00:00
|
|
|
|
|
|
|
// HasID is an interface to entities that have an ID uuid.UUID field and a GetID() method.
|
|
|
|
// This interface is fulfilled by all entities generated by entgo.io/ent via a custom template
|
|
|
|
type HasID interface {
|
|
|
|
GetID() uuid.UUID
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
func newIDSet[T HasID](entities []T) set.Set[uuid.UUID] {
|
|
|
|
uuids := make([]uuid.UUID, 0, len(entities))
|
2022-09-12 22:47:27 +00:00
|
|
|
for _, e := range entities {
|
2022-09-27 23:52:13 +00:00
|
|
|
uuids = append(uuids, e.GetID())
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
return set.New(uuids...)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|