From 1d5d3ecd7a17d720cb8757255d3a948cadfb40e3 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Tue, 10 Jan 2023 12:57:43 +1000 Subject: [PATCH] Add user expansion to upstream model --- backend/internal/entity/upstream/model.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/internal/entity/upstream/model.go b/backend/internal/entity/upstream/model.go index d1d189aa..588e23c3 100644 --- a/backend/internal/entity/upstream/model.go +++ b/backend/internal/entity/upstream/model.go @@ -8,6 +8,7 @@ import ( "npm/internal/database" "npm/internal/entity/nginxtemplate" "npm/internal/entity/upstreamserver" + "npm/internal/entity/user" "npm/internal/status" "npm/internal/types" "npm/internal/util" @@ -39,6 +40,7 @@ type Model struct { // Expansions Servers []upstreamserver.Model `json:"servers"` NginxTemplate *nginxtemplate.Model `json:"nginx_template,omitempty"` + User *user.Model `json:"user,omitempty"` } func (m *Model) getByQuery(query string, params []interface{}) error { @@ -121,6 +123,12 @@ func (m *Model) Expand(items []string) error { m.Servers, err = upstreamserver.GetByUpstreamID(m.ID) } + if util.SliceContainsItem(items, "user") && m.ID > 0 { + var usr user.Model + usr, err = user.GetByID(m.UserID) + m.User = &usr + } + if util.SliceContainsItem(items, "nginxtemplate") && m.NginxTemplateID > 0 { var templ nginxtemplate.Model templ, err = nginxtemplate.GetByID(m.NginxTemplateID)