2022-02-13 23:39:27 +08:00
|
|
|
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
2021-12-17 16:32:53 +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"
|
2022-08-07 12:26:14 +08:00
|
|
|
|
2022-09-29 19:44:08 +08:00
|
|
|
"github.com/beego/beego/utils/pagination"
|
2022-01-20 14:11:46 +08:00
|
|
|
"github.com/casdoor/casdoor/object"
|
|
|
|
"github.com/casdoor/casdoor/util"
|
2021-12-17 16:32:53 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetSyncers
|
|
|
|
// @Title GetSyncers
|
|
|
|
// @Tag Syncer API
|
|
|
|
// @Description get syncers
|
|
|
|
// @Param owner query string true "The owner of syncers"
|
|
|
|
// @Success 200 {array} object.Syncer The Response object
|
|
|
|
// @router /get-syncers [get]
|
|
|
|
func (c *ApiController) GetSyncers() {
|
|
|
|
owner := c.Input().Get("owner")
|
|
|
|
limit := c.Input().Get("pageSize")
|
|
|
|
page := c.Input().Get("p")
|
2021-12-25 10:55:10 +08:00
|
|
|
field := c.Input().Get("field")
|
|
|
|
value := c.Input().Get("value")
|
|
|
|
sortField := c.Input().Get("sortField")
|
|
|
|
sortOrder := c.Input().Get("sortOrder")
|
2023-05-09 00:06:52 +08:00
|
|
|
organization := c.Input().Get("organization")
|
2023-05-30 15:49:39 +08:00
|
|
|
|
2021-12-17 16:32:53 +08:00
|
|
|
if limit == "" || page == "" {
|
2023-05-30 15:49:39 +08:00
|
|
|
organizationSyncers, err := object.GetOrganizationSyncers(owner, organization)
|
|
|
|
if err != nil {
|
2023-06-27 20:33:47 +07:00
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
2023-05-30 15:49:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Data["json"] = organizationSyncers
|
2021-12-17 16:32:53 +08:00
|
|
|
c.ServeJSON()
|
|
|
|
} else {
|
|
|
|
limit := util.ParseInt(limit)
|
2023-05-30 15:49:39 +08:00
|
|
|
count, err := object.GetSyncerCount(owner, organization, field, value)
|
|
|
|
if err != nil {
|
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
paginator := pagination.SetPaginator(c.Ctx, limit, count)
|
|
|
|
syncers, err := object.GetPaginationSyncers(owner, organization, paginator.Offset(), limit, field, value, sortField, sortOrder)
|
|
|
|
if err != nil {
|
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-17 16:32:53 +08:00
|
|
|
c.ResponseOk(syncers, paginator.Nums())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:50:49 +08:00
|
|
|
// GetSyncer
|
2021-12-17 16:32:53 +08:00
|
|
|
// @Title GetSyncer
|
|
|
|
// @Tag Syncer API
|
|
|
|
// @Description get syncer
|
2023-02-10 10:42:16 +08:00
|
|
|
// @Param id query string true "The id ( owner/name ) of the syncer"
|
2021-12-17 16:32:53 +08:00
|
|
|
// @Success 200 {object} object.Syncer The Response object
|
|
|
|
// @router /get-syncer [get]
|
|
|
|
func (c *ApiController) GetSyncer() {
|
|
|
|
id := c.Input().Get("id")
|
|
|
|
|
2023-05-30 15:49:39 +08:00
|
|
|
syncer, err := object.GetSyncer(id)
|
|
|
|
if err != nil {
|
2023-06-27 20:33:47 +07:00
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
2023-05-30 15:49:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Data["json"] = syncer
|
2021-12-17 16:32:53 +08:00
|
|
|
c.ServeJSON()
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:50:49 +08:00
|
|
|
// UpdateSyncer
|
2021-12-17 16:32:53 +08:00
|
|
|
// @Title UpdateSyncer
|
|
|
|
// @Tag Syncer API
|
|
|
|
// @Description update syncer
|
2023-02-10 10:42:16 +08:00
|
|
|
// @Param id query string true "The id ( owner/name ) of the syncer"
|
2021-12-17 16:32:53 +08:00
|
|
|
// @Param body body object.Syncer true "The details of the syncer"
|
|
|
|
// @Success 200 {object} controllers.Response The Response object
|
|
|
|
// @router /update-syncer [post]
|
|
|
|
func (c *ApiController) UpdateSyncer() {
|
|
|
|
id := c.Input().Get("id")
|
|
|
|
|
|
|
|
var syncer object.Syncer
|
|
|
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &syncer)
|
|
|
|
if err != nil {
|
2022-08-20 21:09:32 +08:00
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
2021-12-17 16:32:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Data["json"] = wrapActionResponse(object.UpdateSyncer(id, &syncer))
|
|
|
|
c.ServeJSON()
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:50:49 +08:00
|
|
|
// AddSyncer
|
2021-12-17 16:32:53 +08:00
|
|
|
// @Title AddSyncer
|
|
|
|
// @Tag Syncer API
|
|
|
|
// @Description add syncer
|
|
|
|
// @Param body body object.Syncer true "The details of the syncer"
|
|
|
|
// @Success 200 {object} controllers.Response The Response object
|
|
|
|
// @router /add-syncer [post]
|
|
|
|
func (c *ApiController) AddSyncer() {
|
|
|
|
var syncer object.Syncer
|
|
|
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &syncer)
|
|
|
|
if err != nil {
|
2022-08-20 21:09:32 +08:00
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
2021-12-17 16:32:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Data["json"] = wrapActionResponse(object.AddSyncer(&syncer))
|
|
|
|
c.ServeJSON()
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:50:49 +08:00
|
|
|
// DeleteSyncer
|
2021-12-17 16:32:53 +08:00
|
|
|
// @Title DeleteSyncer
|
|
|
|
// @Tag Syncer API
|
|
|
|
// @Description delete syncer
|
|
|
|
// @Param body body object.Syncer true "The details of the syncer"
|
|
|
|
// @Success 200 {object} controllers.Response The Response object
|
|
|
|
// @router /delete-syncer [post]
|
|
|
|
func (c *ApiController) DeleteSyncer() {
|
|
|
|
var syncer object.Syncer
|
|
|
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &syncer)
|
|
|
|
if err != nil {
|
2022-08-20 21:09:32 +08:00
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
2021-12-17 16:32:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c.Data["json"] = wrapActionResponse(object.DeleteSyncer(&syncer))
|
|
|
|
c.ServeJSON()
|
|
|
|
}
|
2022-04-18 16:27:34 +08:00
|
|
|
|
2022-08-09 16:50:49 +08:00
|
|
|
// RunSyncer
|
2022-04-18 16:27:34 +08:00
|
|
|
// @Title RunSyncer
|
|
|
|
// @Tag Syncer API
|
|
|
|
// @Description run syncer
|
|
|
|
// @Param body body object.Syncer true "The details of the syncer"
|
|
|
|
// @Success 200 {object} controllers.Response The Response object
|
|
|
|
// @router /run-syncer [get]
|
|
|
|
func (c *ApiController) RunSyncer() {
|
|
|
|
id := c.Input().Get("id")
|
2023-05-30 15:49:39 +08:00
|
|
|
syncer, err := object.GetSyncer(id)
|
|
|
|
if err != nil {
|
|
|
|
c.ResponseError(err.Error())
|
|
|
|
return
|
|
|
|
}
|
2022-04-18 16:27:34 +08:00
|
|
|
|
|
|
|
object.RunSyncer(syncer)
|
|
|
|
|
|
|
|
c.ResponseOk()
|
|
|
|
}
|