diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 71b72122..ae842179 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -1023,6 +1023,59 @@ const docTemplate = `{ } } }, + "/admin/policy-templates/{policyTemplateId}/versions/{version}/extract-parameters": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "정책 템플릿 파라미터를 기존 버전의 수정불가능한 파라미터를 포함해서 추출한다.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PolicyTemplate" + ], + "summary": "[Admin_ExtractParameters] 정책 템플릿 파라미터 추출", + "parameters": [ + { + "type": "string", + "description": "정책 템플릿 식별자(uuid)", + "name": "policyTemplateId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "버전(v0.0.0 형식)", + "name": "version", + "in": "path", + "required": true + }, + { + "description": "Rego 코드", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersResponse" + } + } + } + } + }, "/admin/stack-templates": { "get": { "security": [ @@ -4800,6 +4853,66 @@ const docTemplate = `{ } } }, + "/organizations/{organizationId}/policy-templates/{policyTemplateId}/versions/{version}/extract-parameters": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "정책 템플릿 파라미터를 기존 버전의 수정불가능한 파라미터를 포함해서 추출한다.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PolicyTemplate" + ], + "summary": "[ExtractParameters] 정책 템플릿 파라미터 추출", + "parameters": [ + { + "type": "string", + "description": "조직 식별자(o로 시작)", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "정책 템플릿 식별자(uuid)", + "name": "policyTemplateId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "버전(v0.0.0 형식)", + "name": "version", + "in": "path", + "required": true + }, + { + "description": "Rego 코드", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ExtractParametersRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ExtractParametersResponse" + } + } + } + } + }, "/organizations/{organizationId}/primary-cluster": { "patch": { "security": [ @@ -8104,6 +8217,40 @@ const docTemplate = `{ } } }, + "/organizations/{organizationId}/system-notification-rules/default-system-rules": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "MakeDefaultSystemNotificationRules", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SystemNotificationRules" + ], + "summary": "MakeDefaultSystemNotificationRules", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/organizations/{organizationId}/system-notification-rules/name/{name}/existence": { "get": { "security": [ @@ -11265,7 +11412,15 @@ const docTemplate = `{ "type": "string" }, "stack": { - "type": "string" + "type": "object", + "properties": { + "abnormal": { + "type": "string" + }, + "normal": { + "type": "string" + } + } }, "storage": { "type": "string" @@ -11373,6 +11528,41 @@ const docTemplate = `{ } } }, + "github_com_openinfradev_tks-api_pkg_domain.ExtractParametersRequest": { + "type": "object", + "required": [ + "rego" + ], + "properties": { + "libs": { + "type": "array", + "items": { + "type": "string" + } + }, + "rego": { + "type": "string", + "example": "Rego 코드" + } + } + }, + "github_com_openinfradev_tks-api_pkg_domain.ExtractParametersResponse": { + "type": "object", + "properties": { + "errors": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.RegoCompieError" + } + }, + "parametersSchema": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ParameterDef" + } + } + } + }, "github_com_openinfradev_tks-api_pkg_domain.FilterResponse": { "type": "object", "properties": { @@ -12631,6 +12821,9 @@ const docTemplate = `{ "isArray": { "type": "boolean" }, + "isNew": { + "type": "boolean" + }, "key": { "type": "string" }, @@ -12745,15 +12938,12 @@ const docTemplate = `{ "type": "string", "example": "labelpolicy" }, - "targetClusterIds": { + "targetClusters": { + "description": "TargetClusterIds []string ` + "`" + `json:\"targetClusterIds\" example:\"83bf8081-f0c5-4b31-826d-23f6f366ec90,83bf8081-f0c5-4b31-826d-23f6f366ec90\"` + "`" + `", "type": "array", "items": { - "type": "string" - }, - "example": [ - "83bf8081-f0c5-4b31-826d-23f6f366ec90", - "83bf8081-f0c5-4b31-826d-23f6f366ec90" - ] + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.SimpleClusterResponse" + } }, "templateId": { "type": "string", @@ -14913,6 +15103,41 @@ const docTemplate = `{ } } }, + "github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersRequest": { + "type": "object", + "required": [ + "rego" + ], + "properties": { + "libs": { + "type": "array", + "items": { + "type": "string" + } + }, + "rego": { + "type": "string", + "example": "Rego 코드" + } + } + }, + "github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersResponse": { + "type": "object", + "properties": { + "errors": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.RegoCompieError" + } + }, + "parametersSchema": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ParameterDef" + } + } + } + }, "github_com_openinfradev_tks-api_pkg_domain_admin.GetPolicyTemplateDeployResponse": { "type": "object", "properties": { diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 89f6e889..5d59d3ef 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -1017,6 +1017,59 @@ } } }, + "/admin/policy-templates/{policyTemplateId}/versions/{version}/extract-parameters": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "정책 템플릿 파라미터를 기존 버전의 수정불가능한 파라미터를 포함해서 추출한다.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PolicyTemplate" + ], + "summary": "[Admin_ExtractParameters] 정책 템플릿 파라미터 추출", + "parameters": [ + { + "type": "string", + "description": "정책 템플릿 식별자(uuid)", + "name": "policyTemplateId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "버전(v0.0.0 형식)", + "name": "version", + "in": "path", + "required": true + }, + { + "description": "Rego 코드", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersResponse" + } + } + } + } + }, "/admin/stack-templates": { "get": { "security": [ @@ -4794,6 +4847,66 @@ } } }, + "/organizations/{organizationId}/policy-templates/{policyTemplateId}/versions/{version}/extract-parameters": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "정책 템플릿 파라미터를 기존 버전의 수정불가능한 파라미터를 포함해서 추출한다.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "PolicyTemplate" + ], + "summary": "[ExtractParameters] 정책 템플릿 파라미터 추출", + "parameters": [ + { + "type": "string", + "description": "조직 식별자(o로 시작)", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "정책 템플릿 식별자(uuid)", + "name": "policyTemplateId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "버전(v0.0.0 형식)", + "name": "version", + "in": "path", + "required": true + }, + { + "description": "Rego 코드", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ExtractParametersRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ExtractParametersResponse" + } + } + } + } + }, "/organizations/{organizationId}/primary-cluster": { "patch": { "security": [ @@ -8098,6 +8211,40 @@ } } }, + "/organizations/{organizationId}/system-notification-rules/default-system-rules": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "MakeDefaultSystemNotificationRules", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SystemNotificationRules" + ], + "summary": "MakeDefaultSystemNotificationRules", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/organizations/{organizationId}/system-notification-rules/name/{name}/existence": { "get": { "security": [ @@ -11259,7 +11406,15 @@ "type": "string" }, "stack": { - "type": "string" + "type": "object", + "properties": { + "abnormal": { + "type": "string" + }, + "normal": { + "type": "string" + } + } }, "storage": { "type": "string" @@ -11367,6 +11522,41 @@ } } }, + "github_com_openinfradev_tks-api_pkg_domain.ExtractParametersRequest": { + "type": "object", + "required": [ + "rego" + ], + "properties": { + "libs": { + "type": "array", + "items": { + "type": "string" + } + }, + "rego": { + "type": "string", + "example": "Rego 코드" + } + } + }, + "github_com_openinfradev_tks-api_pkg_domain.ExtractParametersResponse": { + "type": "object", + "properties": { + "errors": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.RegoCompieError" + } + }, + "parametersSchema": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ParameterDef" + } + } + } + }, "github_com_openinfradev_tks-api_pkg_domain.FilterResponse": { "type": "object", "properties": { @@ -12625,6 +12815,9 @@ "isArray": { "type": "boolean" }, + "isNew": { + "type": "boolean" + }, "key": { "type": "string" }, @@ -12739,15 +12932,12 @@ "type": "string", "example": "labelpolicy" }, - "targetClusterIds": { + "targetClusters": { + "description": "TargetClusterIds []string `json:\"targetClusterIds\" example:\"83bf8081-f0c5-4b31-826d-23f6f366ec90,83bf8081-f0c5-4b31-826d-23f6f366ec90\"`", "type": "array", "items": { - "type": "string" - }, - "example": [ - "83bf8081-f0c5-4b31-826d-23f6f366ec90", - "83bf8081-f0c5-4b31-826d-23f6f366ec90" - ] + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.SimpleClusterResponse" + } }, "templateId": { "type": "string", @@ -14907,6 +15097,41 @@ } } }, + "github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersRequest": { + "type": "object", + "required": [ + "rego" + ], + "properties": { + "libs": { + "type": "array", + "items": { + "type": "string" + } + }, + "rego": { + "type": "string", + "example": "Rego 코드" + } + } + }, + "github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersResponse": { + "type": "object", + "properties": { + "errors": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.RegoCompieError" + } + }, + "parametersSchema": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ParameterDef" + } + } + } + }, "github_com_openinfradev_tks-api_pkg_domain_admin.GetPolicyTemplateDeployResponse": { "type": "object", "properties": { diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index ec528918..04af21fa 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -1394,7 +1394,12 @@ definitions: memory: type: string stack: - type: string + properties: + abnormal: + type: string + normal: + type: string + type: object storage: type: string type: object @@ -1465,6 +1470,29 @@ definitions: existed: type: boolean type: object + github_com_openinfradev_tks-api_pkg_domain.ExtractParametersRequest: + properties: + libs: + items: + type: string + type: array + rego: + example: Rego 코드 + type: string + required: + - rego + type: object + github_com_openinfradev_tks-api_pkg_domain.ExtractParametersResponse: + properties: + errors: + items: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.RegoCompieError' + type: array + parametersSchema: + items: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.ParameterDef' + type: array + type: object github_com_openinfradev_tks-api_pkg_domain.FilterResponse: properties: column: @@ -2285,6 +2313,8 @@ definitions: type: string isArray: type: boolean + isNew: + type: boolean key: type: string type: @@ -2362,12 +2392,11 @@ definitions: policyResourceName: example: labelpolicy type: string - targetClusterIds: - example: - - 83bf8081-f0c5-4b31-826d-23f6f366ec90 - - 83bf8081-f0c5-4b31-826d-23f6f366ec90 + targetClusters: + description: TargetClusterIds []string `json:"targetClusterIds" + example:"83bf8081-f0c5-4b31-826d-23f6f366ec90,83bf8081-f0c5-4b31-826d-23f6f366ec90"` items: - type: string + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.SimpleClusterResponse' type: array templateId: example: d98ef5f1-4a68-4047-a446-2207787ce3ff @@ -3816,6 +3845,29 @@ definitions: existed: type: boolean type: object + github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersRequest: + properties: + libs: + items: + type: string + type: array + rego: + example: Rego 코드 + type: string + required: + - rego + type: object + github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersResponse: + properties: + errors: + items: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.RegoCompieError' + type: array + parametersSchema: + items: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.ParameterDef' + type: array + type: object github_com_openinfradev_tks-api_pkg_domain_admin.GetPolicyTemplateDeployResponse: properties: deployVersion: @@ -4568,6 +4620,40 @@ paths: summary: '[Admin_GetPolicyTemplateVersion] 정책 템플릿 특정 버전 조회' tags: - PolicyTemplate + /admin/policy-templates/{policyTemplateId}/versions/{version}/extract-parameters: + post: + consumes: + - application/json + description: 정책 템플릿 파라미터를 기존 버전의 수정불가능한 파라미터를 포함해서 추출한다. + parameters: + - description: 정책 템플릿 식별자(uuid) + in: path + name: policyTemplateId + required: true + type: string + - description: 버전(v0.0.0 형식) + in: path + name: version + required: true + type: string + - description: Rego 코드 + in: body + name: body + required: true + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain_admin.ExtractParametersResponse' + security: + - JWT: [] + summary: '[Admin_ExtractParameters] 정책 템플릿 파라미터 추출' + tags: + - PolicyTemplate /admin/policy-templates/kind/{policyTemplateKind}/existence: get: consumes: @@ -6945,6 +7031,45 @@ paths: summary: '[GetPolicyTemplateVersion] 정책 템플릿 특정 버전 조회' tags: - PolicyTemplate + /organizations/{organizationId}/policy-templates/{policyTemplateId}/versions/{version}/extract-parameters: + post: + consumes: + - application/json + description: 정책 템플릿 파라미터를 기존 버전의 수정불가능한 파라미터를 포함해서 추출한다. + parameters: + - description: 조직 식별자(o로 시작) + in: path + name: organizationId + required: true + type: string + - description: 정책 템플릿 식별자(uuid) + in: path + name: policyTemplateId + required: true + type: string + - description: 버전(v0.0.0 형식) + in: path + name: version + required: true + type: string + - description: Rego 코드 + in: body + name: body + required: true + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.ExtractParametersRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.ExtractParametersResponse' + security: + - JWT: [] + summary: '[ExtractParameters] 정책 템플릿 파라미터 추출' + tags: + - PolicyTemplate /organizations/{organizationId}/policy-templates/kind/{policyTemplateKind}/existence: get: consumes: @@ -9215,6 +9340,27 @@ paths: summary: Update SystemNotificationRule tags: - SystemNotificationRules + /organizations/{organizationId}/system-notification-rules/default-system-rules: + post: + consumes: + - application/json + description: MakeDefaultSystemNotificationRules + parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + security: + - JWT: [] + summary: MakeDefaultSystemNotificationRules + tags: + - SystemNotificationRules /organizations/{organizationId}/system-notification-rules/name/{name}/existence: get: consumes: diff --git a/internal/delivery/api/endpoint.go b/internal/delivery/api/endpoint.go index 2fef58a9..f0b9c8b2 100644 --- a/internal/delivery/api/endpoint.go +++ b/internal/delivery/api/endpoint.go @@ -136,6 +136,7 @@ const ( CheckSystemNotificationRuleName DeleteSystemNotificationRule UpdateSystemNotificationRule + MakeDefaultSystemNotificationRules // SystemNotification CreateSystemNotification diff --git a/internal/delivery/api/generated_endpoints.go.go b/internal/delivery/api/generated_endpoints.go.go index fc3e3c83..450fb21b 100644 --- a/internal/delivery/api/generated_endpoints.go.go +++ b/internal/delivery/api/generated_endpoints.go.go @@ -51,6 +51,10 @@ var ApiMap = map[Endpoint]EndpointInfo{ Name: "DeleteUser", Group: "User", }, + UpdateUsers: { + Name: "UpdateUsers", + Group: "User", + }, UpdateUser: { Name: "UpdateUser", Group: "User", @@ -411,6 +415,10 @@ var ApiMap = map[Endpoint]EndpointInfo{ Name: "UpdateSystemNotificationRule", Group: "SystemNotificationRule", }, + MakeDefaultSystemNotificationRules: { + Name: "MakeDefaultSystemNotificationRules", + Group: "SystemNotificationRule", + }, CreateSystemNotification: { Name: "CreateSystemNotification", Group: "SystemNotification", @@ -615,6 +623,18 @@ var ApiMap = map[Endpoint]EndpointInfo{ Name: "IsRoleNameExisted", Group: "Role", }, + AppendUsersToRole: { + Name: "AppendUsersToRole", + Group: "Role", + }, + GetUsersInRoleId: { + Name: "GetUsersInRoleId", + Group: "Role", + }, + RemoveUsersFromRole: { + Name: "RemoveUsersFromRole", + Group: "Role", + }, GetPermissionTemplates: { Name: "GetPermissionTemplates", Group: "Permission", @@ -862,6 +882,8 @@ func (e Endpoint) String() string { return "GetUser" case DeleteUser: return "DeleteUser" + case UpdateUsers: + return "UpdateUsers" case UpdateUser: return "UpdateUser" case ResetPassword: @@ -1042,6 +1064,8 @@ func (e Endpoint) String() string { return "DeleteSystemNotificationRule" case UpdateSystemNotificationRule: return "UpdateSystemNotificationRule" + case MakeDefaultSystemNotificationRules: + return "MakeDefaultSystemNotificationRules" case CreateSystemNotification: return "CreateSystemNotification" case GetSystemNotifications: @@ -1144,6 +1168,12 @@ func (e Endpoint) String() string { return "UpdatePermissionsByRoleId" case IsRoleNameExisted: return "IsRoleNameExisted" + case AppendUsersToRole: + return "AppendUsersToRole" + case GetUsersInRoleId: + return "GetUsersInRoleId" + case RemoveUsersFromRole: + return "RemoveUsersFromRole" case GetPermissionTemplates: return "GetPermissionTemplates" case Admin_CreateUser: @@ -1284,6 +1314,8 @@ func GetEndpoint(name string) Endpoint { return GetUser case "DeleteUser": return DeleteUser + case "UpdateUsers": + return UpdateUsers case "UpdateUser": return UpdateUser case "ResetPassword": @@ -1464,6 +1496,8 @@ func GetEndpoint(name string) Endpoint { return DeleteSystemNotificationRule case "UpdateSystemNotificationRule": return UpdateSystemNotificationRule + case "MakeDefaultSystemNotificationRules": + return MakeDefaultSystemNotificationRules case "CreateSystemNotification": return CreateSystemNotification case "GetSystemNotifications": @@ -1566,6 +1600,12 @@ func GetEndpoint(name string) Endpoint { return UpdatePermissionsByRoleId case "IsRoleNameExisted": return IsRoleNameExisted + case "AppendUsersToRole": + return AppendUsersToRole + case "GetUsersInRoleId": + return GetUsersInRoleId + case "RemoveUsersFromRole": + return RemoveUsersFromRole case "GetPermissionTemplates": return GetPermissionTemplates case "Admin_CreateUser": diff --git a/internal/delivery/http/system-notification-rule.go b/internal/delivery/http/system-notification-rule.go index c87e22dc..c143c9d7 100644 --- a/internal/delivery/http/system-notification-rule.go +++ b/internal/delivery/http/system-notification-rule.go @@ -302,16 +302,42 @@ func (h *SystemNotificationRuleHandler) CheckSystemNotificationRuleName(w http.R } // [TEST] - /* - err = h.usecase.MakeDefaultSystemNotificationRules(r.Context(), "oolw6roj6", nil) - if err != nil { - ErrorJSON(w, r, err) - return - } - */ + err = h.usecase.MakeDefaultSystemNotificationRules(r.Context(), "oolw6roj6", nil) + if err != nil { + ErrorJSON(w, r, err) + return + } var out domain.CheckSystemNotificationRuleNameResponse out.Existed = exist ResponseJSON(w, r, http.StatusOK, out) } + +// MakeDefaultSystemNotificationRules godoc +// +// @Tags SystemNotificationRules +// @Summary MakeDefaultSystemNotificationRules +// @Description MakeDefaultSystemNotificationRules +// @Accept json +// @Produce json +// @Param organizationId path string true "organizationId" +// @Success 200 {object} nil +// @Router /organizations/{organizationId}/system-notification-rules/default-system-rules [POST] +// @Security JWT +func (h *SystemNotificationRuleHandler) MakeDefaultSystemNotificationRules(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + organizationId, ok := vars["organizationId"] + if !ok { + ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid organizationId"), "C_INVALID_ORGANIZATION_ID", "")) + return + } + + err := h.usecase.MakeDefaultSystemNotificationRules(r.Context(), organizationId, nil) + if err != nil { + ErrorJSON(w, r, err) + return + } + + ResponseJSON(w, r, http.StatusOK, nil) +} diff --git a/internal/repository/system-notification-rule.go b/internal/repository/system-notification-rule.go index 7d92f850..ce29f0d3 100644 --- a/internal/repository/system-notification-rule.go +++ b/internal/repository/system-notification-rule.go @@ -9,6 +9,7 @@ import ( "github.com/openinfradev/tks-api/internal/model" "github.com/openinfradev/tks-api/internal/pagination" + "github.com/openinfradev/tks-api/pkg/domain" ) // Interfaces @@ -20,6 +21,7 @@ type ISystemNotificationRuleRepository interface { Create(ctx context.Context, dto model.SystemNotificationRule) (systemNotificationRuleId uuid.UUID, err error) Creates(ctx context.Context, dto []model.SystemNotificationRule) (err error) Update(ctx context.Context, dto model.SystemNotificationRule) (err error) + UpdateStatus(ctx context.Context, systemNotificationRuleId uuid.UUID, status domain.SystemNotificationRuleStatus) (err error) Delete(ctx context.Context, dto model.SystemNotificationRule) (err error) } @@ -132,3 +134,16 @@ func (r *SystemNotificationRuleRepository) Delete(ctx context.Context, dto model } return nil } + +func (r *SystemNotificationRuleRepository) UpdateStatus(ctx context.Context, systemNotificationRuleId uuid.UUID, status domain.SystemNotificationRuleStatus) error { + res := r.db.WithContext(ctx).Model(&model.SystemNotificationRule{}). + Where("id = ?", systemNotificationRuleId). + Updates(map[string]interface{}{ + "Status": status, + }) + if res.Error != nil { + return res.Error + } + + return nil +} diff --git a/internal/route/route.go b/internal/route/route.go index db460a75..d3958026 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -232,6 +232,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa systemNotificationRuleHandler := delivery.NewSystemNotificationRuleHandler(usecaseFactory) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules", customMiddleware.Handle(internalApi.CreateSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.CreateSystemNotificationRule))).Methods(http.MethodPost) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules", customMiddleware.Handle(internalApi.GetSystemNotificationRules, http.HandlerFunc(systemNotificationRuleHandler.GetSystemNotificationRules))).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/default-system-rules", customMiddleware.Handle(internalApi.CreateSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.MakeDefaultSystemNotificationRules))).Methods(http.MethodPost) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/name/{name}/existence", customMiddleware.Handle(internalApi.CheckSystemNotificationRuleName, http.HandlerFunc(systemNotificationRuleHandler.CheckSystemNotificationRuleName))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId}", customMiddleware.Handle(internalApi.GetSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.GetSystemNotificationRule))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId}", customMiddleware.Handle(internalApi.UpdateSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.UpdateSystemNotificationRule))).Methods(http.MethodPut) diff --git a/internal/usecase/system-notification-rule.go b/internal/usecase/system-notification-rule.go index 33ffaf0d..d21e1f84 100644 --- a/internal/usecase/system-notification-rule.go +++ b/internal/usecase/system-notification-rule.go @@ -75,8 +75,6 @@ func (u *SystemNotificationRuleUsecase) Create(ctx context.Context, dto model.Sy return uuid.Nil, err } - // [TODO] update kubernetes resources - return } @@ -103,7 +101,8 @@ func (u *SystemNotificationRuleUsecase) Update(ctx context.Context, dto model.Sy return err } - // [TODO] update kubernetes resources + // update status for appling kubernetes + u.repo.UpdateStatus(ctx, dto.ID, domain.SystemNotificationRuleStatus_PENDING) return nil }