mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
124 lines
3.4 KiB
Go
124 lines
3.4 KiB
Go
// Copyright 2023-2025 Hanzo AI Inc. All Rights Reserved.
|
|
// Portions Copyright 2025 The OpenAgent Authors. All Rights Reserved.
|
|
//
|
|
// 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/hanzoai/ai/object"
|
|
)
|
|
|
|
// GetGlobalForms
|
|
// @Title GetGlobalForms
|
|
// @Tag Form API
|
|
// @Description get global forms
|
|
// @Success 200 {array} object.Form The Response object
|
|
// @router /get-global-forms [get]
|
|
func (c *ApiController) GetGlobalForms() {
|
|
forms, ok := within(c, object.GetGlobalForms, object.GetForms)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
c.ResponseOk(object.GetMaskedForms(forms, true))
|
|
}
|
|
|
|
// GetForms
|
|
// @Title GetForms
|
|
// @Tag Form API
|
|
// @Description get forms
|
|
// @Param owner query string true "The owner of form"
|
|
// @Success 200 {array} object.Form The Response object
|
|
// @router /get-forms [get]
|
|
func (c *ApiController) GetForms() {
|
|
listed(c, table[object.Form]{all: object.GetForms, mask: object.GetMaskedForms,
|
|
count: object.GetFormCount, page: object.GetPaginationForms})
|
|
}
|
|
|
|
// GetForm
|
|
// @Title GetForm
|
|
// @Tag Form API
|
|
// @Description get form
|
|
// @Param id query string true "The id (owner/name) of form"
|
|
// @Success 200 {object} object.Form The Response object
|
|
// @router /get-form [get]
|
|
func (c *ApiController) GetForm() {
|
|
id := c.Input().Get("id")
|
|
|
|
form, err := object.GetForm(id)
|
|
if err != nil {
|
|
c.ResponseError(err.Error())
|
|
return
|
|
}
|
|
if form != nil && !reachable(c, form.Owner) {
|
|
return
|
|
}
|
|
|
|
c.ResponseOk(object.GetMaskedForm(form, true))
|
|
}
|
|
|
|
// UpdateForm
|
|
// @Title UpdateForm
|
|
// @Tag Form API
|
|
// @Description update form
|
|
// @Param id query string true "The id (owner/name) of the form"
|
|
// @Param body body object.Form true "The details of the form"
|
|
// @Success 200 {object} controllers.Response The Response object
|
|
// @router /update-form [post]
|
|
func (c *ApiController) UpdateForm() {
|
|
owner, allowed := c.GetScopedOwner()
|
|
if !allowed {
|
|
return
|
|
}
|
|
id := c.Input().Get("id")
|
|
|
|
var form object.Form
|
|
err := json.Unmarshal(c.Body(), &form)
|
|
if err != nil {
|
|
c.ResponseError(err.Error())
|
|
return
|
|
}
|
|
// Whose row this is, not what the body said — the same answer this table's
|
|
// listing uses.
|
|
form.Owner = owner
|
|
|
|
success, err := object.UpdateForm(id, &form, c.GetAcceptLanguage())
|
|
if err != nil {
|
|
c.ResponseError(err.Error())
|
|
return
|
|
}
|
|
|
|
c.ResponseOk(success)
|
|
}
|
|
|
|
// AddForm
|
|
// @Title AddForm
|
|
// @Tag Form API
|
|
// @Description add form
|
|
// @Param body body object.Form true "The details of the form"
|
|
// @Success 200 {object} controllers.Response The Response object
|
|
// @router /add-form [post]
|
|
func (c *ApiController) AddForm() { stored(c, c.GetScopedOwner, object.AddForm) }
|
|
|
|
// DeleteForm
|
|
// @Title DeleteForm
|
|
// @Tag Form API
|
|
// @Description delete form
|
|
// @Param body body object.Form true "The details of the form"
|
|
// @Success 200 {object} controllers.Response The Response object
|
|
// @router /delete-form [post]
|
|
func (c *ApiController) DeleteForm() { stored(c, c.GetScopedOwner, object.DeleteForm) }
|