rename tenant_application to application

This commit is contained in:
yangk 2020-09-21 13:58:08 +08:00
parent 617edc9319
commit 83ce4cf54d
6 changed files with 33 additions and 33 deletions

View File

@ -12,11 +12,11 @@ import (
httputil "github.com/goodrain/rainbond/util/http"
)
// TenantAppStruct -
type TenantAppStruct struct{}
// ApplicationStruct -
type ApplicationStruct struct{}
// CreateApp -
func (a *TenantAppStruct) CreateApp(w http.ResponseWriter, r *http.Request) {
func (a *ApplicationStruct) CreateApp(w http.ResponseWriter, r *http.Request) {
var tenantReq model.Application
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &tenantReq, nil) {
return
@ -27,7 +27,7 @@ func (a *TenantAppStruct) CreateApp(w http.ResponseWriter, r *http.Request) {
tenantReq.TenantID = tenant.UUID
// create app
app, err := handler.GetTenantApplicationHandler().CreateApp(&tenantReq)
app, err := handler.GetApplicationHandler().CreateApp(&tenantReq)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
@ -37,7 +37,7 @@ func (a *TenantAppStruct) CreateApp(w http.ResponseWriter, r *http.Request) {
}
// UpdateApp -
func (a *TenantAppStruct) UpdateApp(w http.ResponseWriter, r *http.Request) {
func (a *ApplicationStruct) UpdateApp(w http.ResponseWriter, r *http.Request) {
var updateAppReq model.UpdateAppRequest
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &updateAppReq, nil) {
return
@ -45,7 +45,7 @@ func (a *TenantAppStruct) UpdateApp(w http.ResponseWriter, r *http.Request) {
app := r.Context().Value(middleware.ContextKey("application")).(*dbmodel.Application)
// update app
app, err := handler.GetTenantApplicationHandler().UpdateApp(app, updateAppReq)
app, err := handler.GetApplicationHandler().UpdateApp(app, updateAppReq)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
@ -55,7 +55,7 @@ func (a *TenantAppStruct) UpdateApp(w http.ResponseWriter, r *http.Request) {
}
// ListApps -
func (a *TenantAppStruct) ListApps(w http.ResponseWriter, r *http.Request) {
func (a *ApplicationStruct) ListApps(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
appName := query.Get("app_name")
pageQuery := query.Get("page")
@ -74,7 +74,7 @@ func (a *TenantAppStruct) ListApps(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(middleware.ContextKey("tenant_id")).(string)
// List apps
resp, err := handler.GetTenantApplicationHandler().ListApps(tenantID, appName, page, pageSize)
resp, err := handler.GetApplicationHandler().ListApps(tenantID, appName, page, pageSize)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
@ -84,7 +84,7 @@ func (a *TenantAppStruct) ListApps(w http.ResponseWriter, r *http.Request) {
}
// ListServices -
func (a *TenantAppStruct) ListServices(w http.ResponseWriter, r *http.Request) {
func (a *ApplicationStruct) ListServices(w http.ResponseWriter, r *http.Request) {
appID := chi.URLParam(r, "app_id")
query := r.URL.Query()
pageQuery := query.Get("page")
@ -110,11 +110,11 @@ func (a *TenantAppStruct) ListServices(w http.ResponseWriter, r *http.Request) {
}
// DeleteApp -
func (a *TenantAppStruct) DeleteApp(w http.ResponseWriter, r *http.Request) {
func (a *ApplicationStruct) DeleteApp(w http.ResponseWriter, r *http.Request) {
appID := chi.URLParam(r, "app_id")
// Delete application
err := handler.GetTenantApplicationHandler().DeleteApp(appID)
err := handler.GetApplicationHandler().DeleteApp(appID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return

View File

@ -58,7 +58,7 @@ type V2Routes struct {
LabelController
AppRestoreController
PodController
TenantAppStruct
ApplicationStruct
}
//Show test
@ -655,7 +655,7 @@ func (t *TenantStruct) CreateService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnBcodeError(r, w, bcode.ErrCreateNeedCorrectAppID)
return
}
_, err := handler.GetTenantApplicationHandler().GetAppByID(ss.AppID)
_, err := handler.GetApplicationHandler().GetAppByID(ss.AppID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
@ -737,7 +737,7 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
return
}
_, err := handler.GetTenantApplicationHandler().GetAppByID(appID)
_, err := handler.GetApplicationHandler().GetAppByID(appID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return

View File

@ -8,11 +8,11 @@ import (
"github.com/goodrain/rainbond/util"
)
// TenantApplicationAction -
type TenantApplicationAction struct{}
// ApplicationAction -
type ApplicationAction struct{}
// TenantApplicationHandler defines handler methods to TenantApplication.
type TenantApplicationHandler interface {
// ApplicationHandler defines handler methods to TenantApplication.
type ApplicationHandler interface {
CreateApp(req *model.Application) (*model.Application, error)
UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error)
ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error)
@ -20,13 +20,13 @@ type TenantApplicationHandler interface {
DeleteApp(appID string) error
}
// NewTenantApplicationHandler creates a new Tenant Application Handler.
func NewTenantApplicationHandler() TenantApplicationHandler {
return &TenantApplicationAction{}
// NewApplicationHandler creates a new Tenant Application Handler.
func NewApplicationHandler() ApplicationHandler {
return &ApplicationAction{}
}
// CreateApp -
func (a *TenantApplicationAction) CreateApp(req *model.Application) (*model.Application, error) {
func (a *ApplicationAction) CreateApp(req *model.Application) (*model.Application, error) {
appReq := &dbmodel.Application{
AppName: req.AppName,
AppID: util.NewUUID(),
@ -40,7 +40,7 @@ func (a *TenantApplicationAction) CreateApp(req *model.Application) (*model.Appl
}
// UpdateApp -
func (a *TenantApplicationAction) UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error) {
func (a *ApplicationAction) UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error) {
srcApp.AppName = req.AppName
if err := db.GetManager().TenantApplicationDao().UpdateModel(srcApp); err != nil {
return nil, err
@ -49,7 +49,7 @@ func (a *TenantApplicationAction) UpdateApp(srcApp *dbmodel.Application, req mod
}
// ListApps -
func (a *TenantApplicationAction) ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error) {
func (a *ApplicationAction) ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error) {
var resp model.ListAppResponse
apps, total, err := db.GetManager().TenantApplicationDao().ListApps(tenantID, appName, page, pageSize)
if err != nil {
@ -68,7 +68,7 @@ func (a *TenantApplicationAction) ListApps(tenantID, appName string, page, pageS
}
// GetAppByID -
func (a *TenantApplicationAction) GetAppByID(appID string) (*dbmodel.Application, error) {
func (a *ApplicationAction) GetAppByID(appID string) (*dbmodel.Application, error) {
app, err := db.GetManager().TenantApplicationDao().GetAppByID(appID)
if err != nil {
return nil, err
@ -77,7 +77,7 @@ func (a *TenantApplicationAction) GetAppByID(appID string) (*dbmodel.Application
}
// DeleteApp -
func (a *TenantApplicationAction) DeleteApp(appID string) error {
func (a *ApplicationAction) DeleteApp(appID string) error {
// Get the number of services under the application
total, err := db.GetManager().TenantServiceDao().CountServiceByAppID(appID)
if err != nil {

View File

@ -200,9 +200,9 @@ func GetClusterHandler() ClusterHandler {
return defClusterHandler
}
var defTenantApplicationHandler *TenantApplicationAction
var defApplicationHandler *ApplicationAction
// GetTenantApplicationHandler returns the default tenant application handler.
func GetTenantApplicationHandler() *TenantApplicationAction {
return defTenantApplicationHandler
// GetApplicationHandler returns the default tenant application handler.
func GetApplicationHandler() *ApplicationAction {
return defApplicationHandler
}

View File

@ -108,7 +108,7 @@ func InitService(next http.Handler) http.Handler {
func InitApplication(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
appID := chi.URLParam(r, "app_id")
tenantApp, err := handler.GetTenantApplicationHandler().GetAppByID(appID)
tenantApp, err := handler.GetApplicationHandler().GetAppByID(appID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return

View File

@ -8,7 +8,7 @@ type Application struct {
TenantID string `gorm:"column:tenant_id" json:"tenant_id"`
}
// TableName return tableName "tenant_application"
// TableName return tableName "application"
func (t *Application) TableName() string {
return "tenant_application"
return "application"
}