gophershare/infrastructure/db/schema/bucket_access.go

70 lines
1.2 KiB
Go
Raw Normal View History

2024-01-17 21:25:51 +00:00
package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
"github.com/google/uuid"
"code.icb4dc0.de/gophershare/gophershare/core/domain"
)
type BucketAccess struct {
ent.Schema
}
func (BucketAccess) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New).
Immutable().
Unique(),
field.UUID("user_id", uuid.UUID{}).
Immutable(),
field.UUID("bucket_id", uuid.UUID{}).
Immutable(),
field.Enum("access_level").
GoType(domain.AccessLevel(0)).
Annotations(
entgql.Type("AccessLevel"),
),
field.Text("public_key"),
}
}
func (BucketAccess) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}
func (BucketAccess) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Field("user_id").
Ref("bucket_accesses").
Unique().
Immutable().
Required(),
edge.From("bucket", Bucket.Type).
Field("bucket_id").
Ref("user_accesses").
Unique().
Immutable().
Required(),
}
}
func (BucketAccess) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.QueryField(),
}
}