implement HasID interface for entities

This commit is contained in:
Hayden 2022-09-11 17:49:40 -08:00
parent 6dca8ffdda
commit 50e6d353dc
2 changed files with 63 additions and 0 deletions

45
backend/ent/has_id.go Normal file
View file

@ -0,0 +1,45 @@
// Code generated by ent, DO NOT EDIT.
package ent
import "github.com/google/uuid"
func (a *Attachment) GetID() uuid.UUID {
return a.ID
}
func (at *AuthTokens) GetID() uuid.UUID {
return at.ID
}
func (d *Document) GetID() uuid.UUID {
return d.ID
}
func (dt *DocumentToken) GetID() uuid.UUID {
return dt.ID
}
func (gr *Group) GetID() uuid.UUID {
return gr.ID
}
func (i *Item) GetID() uuid.UUID {
return i.ID
}
func (_if *ItemField) GetID() uuid.UUID {
return _if.ID
}
func (l *Label) GetID() uuid.UUID {
return l.ID
}
func (l *Location) GetID() uuid.UUID {
return l.ID
}
func (u *User) GetID() uuid.UUID {
return u.ID
}

View 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 }}