Refactor GetDefaultApplication().

This commit is contained in:
Yang Luo 2021-05-16 23:07:45 +08:00
parent 6508d96162
commit b103683fea
2 changed files with 18 additions and 6 deletions

View File

@ -50,9 +50,18 @@ func (c *ApiController) GetApplication() {
// @Success 200 {object} object.Application The Response object
// @router /get-default-application [get]
func (c *ApiController) GetDefaultApplication() {
owner := c.Input().Get("owner")
//owner := c.Input().Get("owner")
c.Data["json"] = object.GetDefaultApplication(owner)
if c.GetSessionUser() == "" {
c.Data["json"] = nil
c.ServeJSON()
return
}
username := c.GetSessionUser()
user := object.GetUser(username)
c.Data["json"] = object.GetApplicationByUser(user)
c.ServeJSON()
}

View File

@ -89,10 +89,9 @@ func getApplication(owner string, name string) *Application {
}
}
func GetDefaultApplication(owner string) *Application {
name := "app-built-in"
application := Application{Owner: owner, Name: name}
existed, err := adapter.Engine.Get(&application)
func getApplicationByOrganization(organization string) *Application {
application := Application{}
existed, err := adapter.Engine.Where("organization=?", organization).Get(&application)
if err != nil {
panic(err)
}
@ -106,6 +105,10 @@ func GetDefaultApplication(owner string) *Application {
}
}
func GetApplicationByUser(user *User) *Application {
return getApplicationByOrganization(user.Owner)
}
func getApplicationByClientId(clientId string) *Application {
application := Application{}
existed, err := adapter.Engine.Where("client_id=?", clientId).Get(&application)