mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 18:58:02 +08:00
modified controller get appID method
This commit is contained in:
parent
4c180ff7a6
commit
d9931af19b
@ -11,6 +11,7 @@ import (
|
||||
"github.com/goodrain/rainbond/api/model"
|
||||
dbmodel "github.com/goodrain/rainbond/db/model"
|
||||
httputil "github.com/goodrain/rainbond/util/http"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
// TenantAppStruct -
|
||||
@ -51,12 +52,20 @@ func (a *TenantAppStruct) UpdateApp(w http.ResponseWriter, r *http.Request) {
|
||||
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &updateAppReq, nil) {
|
||||
return
|
||||
}
|
||||
|
||||
appID := chi.URLParam(r, "app_id")
|
||||
tenantApp, err := handler.GetTenantApplicationHandler().GetAppByID(appID)
|
||||
if err != nil {
|
||||
if err.Error() == gorm.ErrRecordNotFound.Error() {
|
||||
httputil.ReturnError(r, w, 404, "can't find application")
|
||||
return
|
||||
}
|
||||
httputil.ReturnError(r, w, 500, "get assign tenant application failed")
|
||||
return
|
||||
}
|
||||
// get current tenant
|
||||
tenant := r.Context().Value(middleware.ContextKey("tenant")).(*dbmodel.Tenants)
|
||||
appID := r.Context().Value(middleware.ContextKey("app_id")).(string)
|
||||
updateAppReq.TenantID = tenant.UUID
|
||||
updateAppReq.AppID = appID
|
||||
updateAppReq.AppID = tenantApp.AppID
|
||||
|
||||
// create app
|
||||
app, err := handler.GetTenantApplicationHandler().UpdateApp(&updateAppReq)
|
||||
|
@ -58,11 +58,6 @@ func InitTenant(next http.Handler) http.Handler {
|
||||
httputil.ReturnError(r, w, 404, "cant find tenant")
|
||||
return
|
||||
}
|
||||
appID := chi.URLParam(r, "app_id")
|
||||
if appID == "" {
|
||||
httputil.ReturnError(r, w, 404, "can't find application")
|
||||
return
|
||||
}
|
||||
tenant, err := db.GetManager().TenantDao().GetTenantIDByName(tenantName)
|
||||
if err != nil {
|
||||
logrus.Errorf("get tenant by tenantName error: %s %v", tenantName, err)
|
||||
@ -73,20 +68,9 @@ func InitTenant(next http.Handler) http.Handler {
|
||||
httputil.ReturnError(r, w, 500, "get assign tenant uuid failed")
|
||||
return
|
||||
}
|
||||
tenantApp, err := db.GetManager().TenantApplicationDao().GetAppByID(appID)
|
||||
if err != nil {
|
||||
logrus.Errorf("get tenant application by appID error: %s %v", appID, err)
|
||||
if err.Error() == gorm.ErrRecordNotFound.Error() {
|
||||
httputil.ReturnError(r, w, 404, "can't find application")
|
||||
return
|
||||
}
|
||||
httputil.ReturnError(r, w, 500, "get assign tenant application failed")
|
||||
return
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), ContextKey("tenant_name"), tenantName)
|
||||
ctx = context.WithValue(ctx, ContextKey("tenant_id"), tenant.UUID)
|
||||
ctx = context.WithValue(ctx, ContextKey("tenant"), tenant)
|
||||
ctx = context.WithValue(ctx, ContextKey("app_id"), tenantApp.AppID)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
}
|
||||
return http.HandlerFunc(fn)
|
||||
|
Loading…
Reference in New Issue
Block a user