mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-26 23:21:39 +01:00
* Remove documents table (WIP) * Further cleanup of documents table * This should clean up the errors, but actual attachment handling still needs added. * Full generation to update the JS side of things too * Further fixes * Fix cyclic dependency issue * In theory the API side works now * Fix go linting issues * Fix frontend issues * Way closer, but has a foreign key constrant issue * UI actually works now * Fix deduplication feature not working right * Upgrade to `golangci-lint` v2 file * Add ability to set primary during attachment creation * Update swagger with new primary attachment during creation stuff * Files are actually saved now, but there's still a bug * Fix critical issue whith how deletions were working * Fix the byte copy issue * Hopefully everything is fixed now * Fix golangci-lint config and lint files * Fix lint issue * Fix a few more tests * Fix lint issues again * More minor test fixes * Update backend/internal/core/services/service_items_attachments.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix migration (I think) * Fixed postgres migration * Change some migration options to work better * Some more little things that I tried * Fix merge go.mod * Fix migrations * Little lint thing * Fix AttachmentsList.vue with updated API --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
85 lines
1.6 KiB
Go
85 lines
1.6 KiB
Go
package schema
|
|
|
|
import (
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/mixin"
|
|
"github.com/google/uuid"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema/mixins"
|
|
)
|
|
|
|
// Group holds the schema definition for the Group entity.
|
|
type Group struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (Group) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
mixins.BaseMixin{},
|
|
}
|
|
}
|
|
|
|
// Fields of the Home.
|
|
func (Group) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.String("name").
|
|
MaxLen(255).
|
|
NotEmpty(),
|
|
field.String("currency").
|
|
Default("usd"),
|
|
}
|
|
}
|
|
|
|
// Edges of the Home.
|
|
func (Group) Edges() []ent.Edge {
|
|
owned := func(name string, t any) ent.Edge {
|
|
return edge.To(name, t).
|
|
Annotations(entsql.Annotation{
|
|
OnDelete: entsql.Cascade,
|
|
})
|
|
}
|
|
|
|
return []ent.Edge{
|
|
owned("users", User.Type),
|
|
owned("locations", Location.Type),
|
|
owned("items", Item.Type),
|
|
owned("labels", Label.Type),
|
|
owned("invitation_tokens", GroupInvitationToken.Type),
|
|
owned("notifiers", Notifier.Type),
|
|
// $scaffold_edge
|
|
}
|
|
}
|
|
|
|
// GroupMixin when embedded in an ent.Schema, adds a reference to
|
|
// the Group entity.
|
|
type GroupMixin struct {
|
|
ref string
|
|
field string
|
|
mixin.Schema
|
|
}
|
|
|
|
func (g GroupMixin) Fields() []ent.Field {
|
|
if g.field != "" {
|
|
return []ent.Field{
|
|
field.UUID(g.field, uuid.UUID{}),
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (g GroupMixin) Edges() []ent.Edge {
|
|
edge := edge.From("group", Group.Type).
|
|
Ref(g.ref).
|
|
Unique().
|
|
Required()
|
|
|
|
if g.field != "" {
|
|
edge = edge.Field(g.field)
|
|
}
|
|
|
|
return []ent.Edge{edge}
|
|
}
|