casdoor/controllers/application.go

109 lines
3.5 KiB
Go
Raw Normal View History

2021-03-13 23:06:03 +08:00
// Copyright 2021 The casbin Authors. All Rights Reserved.
2020-12-20 23:24:09 +08:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package controllers
import (
"encoding/json"
"github.com/casdoor/casdoor/object"
)
// @Title GetApplications
// @Description get all applications
// @Param owner query string true "The owner of applications."
// @Success 200 {array} object.Application The Response object
// @router /get-applications [get]
2020-12-20 23:24:09 +08:00
func (c *ApiController) GetApplications() {
owner := c.Input().Get("owner")
c.Data["json"] = object.GetApplications(owner)
c.ServeJSON()
}
// @Title GetApplication
// @Description get the detail of an application
// @Param id query string true "The id of the application."
// @Success 200 {object} object.Application The Response object
// @router /get-application [get]
2020-12-20 23:24:09 +08:00
func (c *ApiController) GetApplication() {
id := c.Input().Get("id")
c.Data["json"] = object.GetApplication(id)
c.ServeJSON()
}
2021-04-19 01:14:41 +08:00
// @Title GetDefaultApplication
// @Description get the detail of the default application
// @Param owner query string true "The owner of the application."
// @Success 200 {object} object.Application The Response object
// @router /get-default-application [get]
func (c *ApiController) GetDefaultApplication() {
owner := c.Input().Get("owner")
c.Data["json"] = object.GetDefaultApplication(owner)
c.ServeJSON()
}
// @Title UpdateApplication
// @Description update an application
// @Param id query string true "The id of the application"
// @Param body body object.Application true "The details of the application"
// @Success 200 {object} controllers.Response The Response object
// @router /update-application [post]
2020-12-20 23:24:09 +08:00
func (c *ApiController) UpdateApplication() {
id := c.Input().Get("id")
var application object.Application
err := json.Unmarshal(c.Ctx.Input.RequestBody, &application)
if err != nil {
panic(err)
}
2021-03-28 00:48:34 +08:00
c.Data["json"] = wrapActionResponse(object.UpdateApplication(id, &application))
2020-12-20 23:24:09 +08:00
c.ServeJSON()
}
// @Title AddApplication
// @Description add an application
// @Param body body object.Application true "The details of the application"
// @Success 200 {object} controllers.Response The Response object
// @router /add-application [post]
2020-12-20 23:24:09 +08:00
func (c *ApiController) AddApplication() {
var application object.Application
err := json.Unmarshal(c.Ctx.Input.RequestBody, &application)
if err != nil {
panic(err)
}
2021-03-28 00:48:34 +08:00
c.Data["json"] = wrapActionResponse(object.AddApplication(&application))
2020-12-20 23:24:09 +08:00
c.ServeJSON()
}
// @Title DeleteApplication
// @Description delete an application
// @Param body body object.Application true "The details of the application"
// @Success 200 {object} controllers.Response The Response object
// @router /delete-application [post]
2020-12-20 23:24:09 +08:00
func (c *ApiController) DeleteApplication() {
var application object.Application
err := json.Unmarshal(c.Ctx.Input.RequestBody, &application)
if err != nil {
panic(err)
}
2021-03-28 00:48:34 +08:00
c.Data["json"] = wrapActionResponse(object.DeleteApplication(&application))
2020-12-20 23:24:09 +08:00
c.ServeJSON()
}