mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-04 20:57:38 +08:00
Merge branch 'master' of https://github.com/goodrain/rainbond
This commit is contained in:
commit
4e6f420450
@ -154,6 +154,7 @@ type AppInterface interface {
|
|||||||
// ApplicationInterface tenant application interface
|
// ApplicationInterface tenant application interface
|
||||||
type ApplicationInterface interface {
|
type ApplicationInterface interface {
|
||||||
CreateApp(w http.ResponseWriter, r *http.Request)
|
CreateApp(w http.ResponseWriter, r *http.Request)
|
||||||
|
BatchCreateApp(w http.ResponseWriter, r *http.Request)
|
||||||
UpdateApp(w http.ResponseWriter, r *http.Request)
|
UpdateApp(w http.ResponseWriter, r *http.Request)
|
||||||
ListApps(w http.ResponseWriter, r *http.Request)
|
ListApps(w http.ResponseWriter, r *http.Request)
|
||||||
ListServices(w http.ResponseWriter, r *http.Request)
|
ListServices(w http.ResponseWriter, r *http.Request)
|
||||||
|
@ -137,6 +137,7 @@ func (v2 *V2) tenantNameRouter() chi.Router {
|
|||||||
r.Get("/chargesverify", controller.ChargesVerifyController)
|
r.Get("/chargesverify", controller.ChargesVerifyController)
|
||||||
//tenant app
|
//tenant app
|
||||||
r.Post("/apps", controller.GetManager().CreateApp)
|
r.Post("/apps", controller.GetManager().CreateApp)
|
||||||
|
r.Post("/batch_create_apps", controller.GetManager().BatchCreateApp)
|
||||||
r.Get("/apps", controller.GetManager().ListApps)
|
r.Get("/apps", controller.GetManager().ListApps)
|
||||||
r.Mount("/apps/{app_id}", v2.applicationRouter())
|
r.Mount("/apps/{app_id}", v2.applicationRouter())
|
||||||
//get some service pod info
|
//get some service pod info
|
||||||
|
@ -36,6 +36,23 @@ func (a *ApplicationController) CreateApp(w http.ResponseWriter, r *http.Request
|
|||||||
httputil.ReturnSuccess(r, w, app)
|
httputil.ReturnSuccess(r, w, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BatchCreateApp -
|
||||||
|
func (a *ApplicationController) BatchCreateApp(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var apps model.CreateAppRequest
|
||||||
|
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &apps, nil) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// get current tenant
|
||||||
|
tenant := r.Context().Value(middleware.ContextKey("tenant")).(*dbmodel.Tenants)
|
||||||
|
respList, err := handler.GetApplicationHandler().BatchCreateApp(&apps, tenant.UUID)
|
||||||
|
if err != nil {
|
||||||
|
httputil.ReturnBcodeError(r, w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
httputil.ReturnSuccess(r, w, respList)
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateApp -
|
// UpdateApp -
|
||||||
func (a *ApplicationController) UpdateApp(w http.ResponseWriter, r *http.Request) {
|
func (a *ApplicationController) UpdateApp(w http.ResponseWriter, r *http.Request) {
|
||||||
var updateAppReq model.UpdateAppRequest
|
var updateAppReq model.UpdateAppRequest
|
||||||
|
@ -26,6 +26,7 @@ type ApplicationAction struct {
|
|||||||
// ApplicationHandler defines handler methods to TenantApplication.
|
// ApplicationHandler defines handler methods to TenantApplication.
|
||||||
type ApplicationHandler interface {
|
type ApplicationHandler interface {
|
||||||
CreateApp(req *model.Application) (*model.Application, error)
|
CreateApp(req *model.Application) (*model.Application, error)
|
||||||
|
BatchCreateApp(req *model.CreateAppRequest, tenantID string) ([]model.CreateAppResponse, error)
|
||||||
UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error)
|
UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error)
|
||||||
ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error)
|
ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error)
|
||||||
GetAppByID(appID string) (*dbmodel.Application, error)
|
GetAppByID(appID string) (*dbmodel.Application, error)
|
||||||
@ -72,12 +73,6 @@ func (a *ApplicationAction) CreateApp(req *model.Application) (*model.Applicatio
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(req.ServiceIDs) != 0 {
|
if len(req.ServiceIDs) != 0 {
|
||||||
for _, sid := range req.ServiceIDs {
|
|
||||||
if _, err := db.GetManager().TenantServiceDao().GetServiceByID(sid); err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := db.GetManager().TenantServiceDao().BindAppByServiceIDs(appReq.AppID, req.ServiceIDs); err != nil {
|
if err := db.GetManager().TenantServiceDao().BindAppByServiceIDs(appReq.AppID, req.ServiceIDs); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -91,6 +86,26 @@ func (a *ApplicationAction) CreateApp(req *model.Application) (*model.Applicatio
|
|||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BatchCreateApp -
|
||||||
|
func (a *ApplicationAction) BatchCreateApp(apps *model.CreateAppRequest, tenantID string) ([]model.CreateAppResponse, error) {
|
||||||
|
var (
|
||||||
|
resp model.CreateAppResponse
|
||||||
|
respList []model.CreateAppResponse
|
||||||
|
)
|
||||||
|
for _, app := range apps.AppsInfo {
|
||||||
|
app.TenantID = tenantID
|
||||||
|
regionApp, err := GetApplicationHandler().CreateApp(&app)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Batch Create App [%v] error is [%v] ", app.AppName, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resp.AppID = app.ConsoleAppID
|
||||||
|
resp.RegionAppID = regionApp.AppID
|
||||||
|
respList = append(respList, resp)
|
||||||
|
}
|
||||||
|
return respList, nil
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateApp -
|
// UpdateApp -
|
||||||
func (a *ApplicationAction) UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error) {
|
func (a *ApplicationAction) UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error) {
|
||||||
if req.AppName != "" {
|
if req.AppName != "" {
|
||||||
|
@ -1629,10 +1629,22 @@ func NewAppStatusFromImport(app *ImportAppStruct) *dbmodel.AppStatus {
|
|||||||
|
|
||||||
// Application -
|
// Application -
|
||||||
type Application struct {
|
type Application struct {
|
||||||
AppName string `json:"app_name" validate:"required"`
|
AppName string `json:"app_name" validate:"required"`
|
||||||
AppID string `json:"app_id"`
|
ConsoleAppID int64 `json:"console_app_id"`
|
||||||
TenantID string `json:"tenant_id"`
|
AppID string `json:"app_id"`
|
||||||
ServiceIDs []string `json:"service_ids"`
|
TenantID string `json:"tenant_id"`
|
||||||
|
ServiceIDs []string `json:"service_ids"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateAppRequest -
|
||||||
|
type CreateAppRequest struct {
|
||||||
|
AppsInfo []Application `json:"apps_info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateAppResponse -
|
||||||
|
type CreateAppResponse struct {
|
||||||
|
AppID int64 `json:"app_id"`
|
||||||
|
RegionAppID string `json:"region_app_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAppResponse -
|
// ListAppResponse -
|
||||||
|
Loading…
Reference in New Issue
Block a user