From 50e6d353dc3c6948930facff1b2b45938a9e278f Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sun, 11 Sep 2022 17:49:40 -0800 Subject: [PATCH] implement HasID interface for entities --- backend/ent/has_id.go | 45 ++++++++++++++++++++++++ backend/ent/schema/templates/has_id.tmpl | 18 ++++++++++ 2 files changed, 63 insertions(+) create mode 100644 backend/ent/has_id.go create mode 100644 backend/ent/schema/templates/has_id.tmpl diff --git a/backend/ent/has_id.go b/backend/ent/has_id.go new file mode 100644 index 0000000..a6afc6a --- /dev/null +++ b/backend/ent/has_id.go @@ -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 +} diff --git a/backend/ent/schema/templates/has_id.tmpl b/backend/ent/schema/templates/has_id.tmpl new file mode 100644 index 0000000..42b0cd8 --- /dev/null +++ b/backend/ent/schema/templates/has_id.tmpl @@ -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 }} \ No newline at end of file