Skip to content

Commit

Permalink
feat: batch add dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DokiDoki1103 committed Dec 25, 2023
1 parent 41bc5ee commit f344491
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/api/api_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type ServiceInterface interface {
CreateService(w http.ResponseWriter, r *http.Request)
UpdateService(w http.ResponseWriter, r *http.Request)
Dependency(w http.ResponseWriter, r *http.Request)
Dependencys(w http.ResponseWriter, r *http.Request)

Env(w http.ResponseWriter, r *http.Request)
Ports(w http.ResponseWriter, r *http.Request)
PutPorts(w http.ResponseWriter, r *http.Request)
Expand Down
2 changes: 2 additions & 0 deletions api/api_routers/version2/v2Routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ func (v2 *V2) serviceRouter() chi.Router {

//应用依赖关系增加与删除(source)
r.Post("/dependency", middleware.WrapEL(controller.GetManager().Dependency, dbmodel.TargetTypeService, "add-service-dependency", dbmodel.SYNEVENTTYPE))
r.Post("/dependencys", middleware.WrapEL(controller.GetManager().Dependencys, dbmodel.TargetTypeService, "add-service-dependency", dbmodel.SYNEVENTTYPE))

r.Delete("/dependency", middleware.WrapEL(controller.GetManager().Dependency, dbmodel.TargetTypeService, "delete-service-dependency", dbmodel.SYNEVENTTYPE))
//环境变量增删改(source)
r.Post("/env", middleware.WrapEL(controller.GetManager().Env, dbmodel.TargetTypeService, "add-service-env", dbmodel.SYNEVENTTYPE))
Expand Down
57 changes: 57 additions & 0 deletions api/controller/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,14 @@ func (t *TenantStruct) Dependency(w http.ResponseWriter, r *http.Request) {
}
}

// Dependencys Dependencys batch add dependency
func (t *TenantStruct) Dependencys(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "POST":
t.AddDependencys(w, r)
}
}

// AddDependency AddDependency
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/dependency v2 addDependency
//
Expand Down Expand Up @@ -1093,6 +1101,55 @@ func (t *TenantStruct) AddDependency(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, nil)
}

// AddDependencys AddDependencys
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/dependencys v2 addDependencys
//
// 批量增加应用依赖关系
//
// add dependency
//
// ---
// consumes:
// - application/json
// - application/x-protobuf
//
// produces:
// - application/json
// - application/xml
//
// responses:
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式

func (t *TenantStruct) AddDependencys(w http.ResponseWriter, r *http.Request) {
rules := validator.MapData{
"dep_service_ids": []string{"required"},
"dep_service_type": []string{"required"},
"dep_order": []string{},
}
data, ok := httputil.ValidatorRequestMapAndErrorResponse(r, w, rules, nil)
if !ok {
return
}
depServiceIds := data["dep_service_id"].(string)
for _, depServiceId := range strings.Split(",", depServiceIds) {
ds := &api_model.DependService{
TenantID: r.Context().Value(ctxutil.ContextKey("tenant_id")).(string),
ServiceID: r.Context().Value(ctxutil.ContextKey("service_id")).(string),
DepServiceID: depServiceId,
DepServiceType: data["dep_service_type"].(string),
}
if err := handler.GetServiceManager().ServiceDepend("add", ds); err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("add dependency error, %v", err))
return
}
}
httputil.ReturnSuccess(r, w, nil)
}

// DeleteDependency DeleteDependency
// swagger:operation DELETE /v2/tenants/{tenant_name}/services/{service_alias}/dependency v2 deleteDependency
//
Expand Down

0 comments on commit f344491

Please sign in to comment.