Add user expansion to upstream model
This commit is contained in:
parent
8033d052fe
commit
1d5d3ecd7a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user