mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-06 10:38:35 +00:00
feat: items-editor (#5)
* format readme * update logo * format html * add logo to docs * repository for document and document tokens * add attachments type and repository * autogenerate types via scripts * use autogenerated types * attachment type updates * add insured and quantity fields for items * implement HasID interface for entities * implement label updates for items * implement service update method * WIP item update client side actions * check err on attachment * finish types for basic items editor * remove unused var * house keeping
This commit is contained in:
parent
fbc364dcd2
commit
95ab14b866
125 changed files with 15626 additions and 1791 deletions
42
backend/ent/schema/attachment.go
Normal file
42
backend/ent/schema/attachment.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// Attachment holds the schema definition for the Attachment entity.
|
||||
type Attachment struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Attachment) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Attachment.
|
||||
func (Attachment) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("type").
|
||||
Values("photo", "manual", "warranty", "attachment").
|
||||
Default("attachment"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Attachment.
|
||||
func (Attachment) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("item", Item.Type).
|
||||
Ref("attachments").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.From("document", Document.Type).
|
||||
Ref("attachments").
|
||||
Required().
|
||||
Unique(),
|
||||
}
|
||||
}
|
|
@ -42,7 +42,6 @@ func (AuthTokens) Edges() []ent.Edge {
|
|||
|
||||
func (AuthTokens) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
// non-unique index.
|
||||
index.Fields("token"),
|
||||
}
|
||||
}
|
||||
|
|
50
backend/ent/schema/document.go
Normal file
50
backend/ent/schema/document.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// Document holds the schema definition for the Document entity.
|
||||
type Document struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Document) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Document.
|
||||
func (Document) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("title").
|
||||
MaxLen(255).
|
||||
NotEmpty(),
|
||||
field.String("path").
|
||||
MaxLen(500).
|
||||
NotEmpty(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Document.
|
||||
func (Document) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("group", Group.Type).
|
||||
Ref("documents").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.To("document_tokens", DocumentToken.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("attachments", Attachment.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
}
|
||||
}
|
50
backend/ent/schema/document_token.go
Normal file
50
backend/ent/schema/document_token.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// DocumentToken holds the schema definition for the DocumentToken entity.
|
||||
type DocumentToken struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (DocumentToken) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the DocumentToken.
|
||||
func (DocumentToken) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Bytes("token").
|
||||
NotEmpty().
|
||||
Unique(),
|
||||
field.Int("uses").
|
||||
Default(1),
|
||||
field.Time("expires_at").
|
||||
Default(func() time.Time { return time.Now().Add(time.Minute * 10) }),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the DocumentToken.
|
||||
func (DocumentToken) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("document", Document.Type).
|
||||
Ref("document_tokens").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (DocumentToken) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("token"),
|
||||
}
|
||||
}
|
|
@ -34,17 +34,25 @@ func (Group) Fields() []ent.Field {
|
|||
// Edges of the Home.
|
||||
func (Group) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("users", User.Type).Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("locations", Location.Type).Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("items", Item.Type).Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("labels", Label.Type).Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("users", User.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("locations", Location.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("items", Item.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("labels", Label.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("documents", Document.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,10 @@ func (Item) Fields() []ent.Field {
|
|||
field.String("notes").
|
||||
MaxLen(1000).
|
||||
Optional(),
|
||||
field.Int("quantity").
|
||||
Default(1),
|
||||
field.Bool("insured").
|
||||
Default(false),
|
||||
|
||||
// ------------------------------------
|
||||
// item identification
|
||||
|
@ -93,10 +97,15 @@ func (Item) Edges() []ent.Edge {
|
|||
edge.From("location", Location.Type).
|
||||
Ref("items").
|
||||
Unique(),
|
||||
edge.To("fields", ItemField.Type).Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("fields", ItemField.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.From("label", Label.Type).
|
||||
Ref("items"),
|
||||
edge.To("attachments", Attachment.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
18
backend/ent/schema/templates/has_id.tmpl
Normal file
18
backend/ent/schema/templates/has_id.tmpl
Normal file
|
@ -0,0 +1,18 @@
|
|||
{{/* The line below tells Intellij/GoLand to enable the autocompletion based on the *gen.Graph type. */}}
|
||||
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}
|
||||
|
||||
{{ define "has_id" }}
|
||||
|
||||
{{/* Add the base header for the generated file */}}
|
||||
{{ $pkg := base $.Config.Package }}
|
||||
{{ template "header" $ }}
|
||||
import "github.com/google/uuid"
|
||||
{{/* Loop over all nodes and implement the "HasID" interface */}}
|
||||
{{ range $n := $.Nodes }}
|
||||
{{ $receiver := $n.Receiver }}
|
||||
func ({{ $receiver }} *{{ $n.Name }}) GetID() uuid.UUID {
|
||||
return {{ $receiver }}.ID
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ end }}
|
Loading…
Add table
Add a link
Reference in a new issue