feat: maintenance log (#170)

* remove repo for document tokens

* remove schema for doc tokens

* fix id template and generate cmd

* schema updates

* code gen

* bump dependencies

* fix broken migrations + add maintenance entry type

* spelling

* remove debug logger

* implement repository layer

* routes

* API client

* wip: maintenance log

* remove depreciated call
This commit is contained in:
Hayden 2022-12-09 20:57:57 -09:00 committed by GitHub
parent d6da63187b
commit 5bbb969763
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
79 changed files with 6320 additions and 4957 deletions

View file

@ -4,6 +4,7 @@ import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
@ -38,7 +39,10 @@ func (AuthTokens) Edges() []ent.Edge {
Ref("auth_tokens").
Unique(),
edge.To("roles", AuthRoles.Type).
Unique(),
Unique().
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
}),
}
}

View file

@ -38,10 +38,6 @@ func (Document) Edges() []ent.Edge {
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,

View file

@ -1,50 +0,0 @@
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/homebox/backend/internal/data/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"),
}
}

View file

@ -116,6 +116,10 @@ func (Item) Edges() []ent.Edge {
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
}),
edge.To("maintenance_entries", MaintenanceEntry.Type).
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
}),
edge.To("attachments", Attachment.Type).
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,

View file

@ -0,0 +1,48 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
)
type MaintenanceEntry struct {
ent.Schema
}
func (MaintenanceEntry) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.BaseMixin{},
}
}
func (MaintenanceEntry) Fields() []ent.Field {
return []ent.Field{
field.UUID("item_id", uuid.UUID{}),
field.Time("date").
Default(time.Now),
field.String("name").
MaxLen(255).
NotEmpty(),
field.String("description").
MaxLen(2500).
Optional(),
field.Float("cost").
Default(0.0),
}
}
// Edges of the ItemField.
func (MaintenanceEntry) Edges() []ent.Edge {
return []ent.Edge{
edge.From("item", Item.Type).
Field("item_id").
Ref("maintenance_entries").
Required().
Unique(),
}
}

View file

@ -9,8 +9,13 @@
import "github.com/google/uuid"
{{/* Loop over all nodes and implement the "HasID" interface */}}
{{ range $n := $.Nodes }}
{{ if not $n.ID }}
{{/* If the node doesn't have an ID field, we skip it. */}}
{{ continue }}
{{ end }}
{{/* The "HasID" interface is implemented by the "ID" method. */}}
{{ $receiver := $n.Receiver }}
func ({{ $receiver }} *{{ $n.Name }}) GetID() uuid.UUID {
func ({{ $receiver }} *{{ $n.Name }}) GetID() {{ $n.ID.Type }} {
return {{ $receiver }}.ID
}
{{ end }}