diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 6980cdfc..1a5cdb39 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -1366,6 +1366,13 @@ const docTemplate = `{ ], "summary": "Update SystemNotificationTemplate", "parameters": [ + { + "type": "string", + "description": "systemNotificationTemplateId", + "name": "systemNotificationTemplateId", + "in": "path", + "required": true + }, { "description": "Update alert template request", "name": "body", @@ -1381,6 +1388,38 @@ const docTemplate = `{ "description": "OK" } } + }, + "delete": { + "security": [ + { + "JWT": [] + } + ], + "description": "Delete SystemNotificationTemplate", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SystemNotificationTemplates" + ], + "summary": "Delete SystemNotificationTemplate", + "parameters": [ + { + "type": "string", + "description": "systemNotificationTemplateId", + "name": "systemNotificationTemplateId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + } + } } }, "/app-groups": { @@ -6837,6 +6876,13 @@ const docTemplate = `{ ], "summary": "Get SystemNotificationRules", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "pageSize", @@ -6899,6 +6945,13 @@ const docTemplate = `{ ], "summary": "Create SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "create stack template request", "name": "body", @@ -6944,6 +6997,13 @@ const docTemplate = `{ "name": "name", "in": "path", "required": true + }, + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true } ], "responses": { @@ -6975,6 +7035,13 @@ const docTemplate = `{ ], "summary": "Get SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "systemNotificationRuleId", @@ -7010,6 +7077,20 @@ const docTemplate = `{ ], "summary": "Update SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "systemNotificationRuleId", + "name": "systemNotificationRuleId", + "in": "path", + "required": true + }, { "description": "Update systemNotificationRule request", "name": "body", @@ -7044,6 +7125,13 @@ const docTemplate = `{ ], "summary": "Delete SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "systemNotificationRuleId", @@ -7140,6 +7228,13 @@ const docTemplate = `{ ], "summary": "Remove organization systemNotificationTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Remove organization systemNotification templates request", "name": "body", @@ -7174,6 +7269,13 @@ const docTemplate = `{ ], "summary": "Add organization systemNotificationTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Add organization systemNotification templates request", "name": "body", @@ -7330,6 +7432,13 @@ const docTemplate = `{ "in": "path", "required": true }, + { + "type": "string", + "description": "systemNotificationId", + "name": "systemNotificationId", + "in": "path", + "required": true + }, { "description": "Update cloud setting request", "name": "body", @@ -7411,6 +7520,13 @@ const docTemplate = `{ "name": "organizationId", "in": "path", "required": true + }, + { + "type": "string", + "description": "systemNotificationId", + "name": "systemNotificationId", + "in": "path", + "required": true } ], "responses": { diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index fa4311e5..c4fd3f12 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -1360,6 +1360,13 @@ ], "summary": "Update SystemNotificationTemplate", "parameters": [ + { + "type": "string", + "description": "systemNotificationTemplateId", + "name": "systemNotificationTemplateId", + "in": "path", + "required": true + }, { "description": "Update alert template request", "name": "body", @@ -1375,6 +1382,38 @@ "description": "OK" } } + }, + "delete": { + "security": [ + { + "JWT": [] + } + ], + "description": "Delete SystemNotificationTemplate", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SystemNotificationTemplates" + ], + "summary": "Delete SystemNotificationTemplate", + "parameters": [ + { + "type": "string", + "description": "systemNotificationTemplateId", + "name": "systemNotificationTemplateId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + } + } } }, "/app-groups": { @@ -6831,6 +6870,13 @@ ], "summary": "Get SystemNotificationRules", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "pageSize", @@ -6893,6 +6939,13 @@ ], "summary": "Create SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "create stack template request", "name": "body", @@ -6938,6 +6991,13 @@ "name": "name", "in": "path", "required": true + }, + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true } ], "responses": { @@ -6969,6 +7029,13 @@ ], "summary": "Get SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "systemNotificationRuleId", @@ -7004,6 +7071,20 @@ ], "summary": "Update SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "systemNotificationRuleId", + "name": "systemNotificationRuleId", + "in": "path", + "required": true + }, { "description": "Update systemNotificationRule request", "name": "body", @@ -7038,6 +7119,13 @@ ], "summary": "Delete SystemNotificationRule", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "systemNotificationRuleId", @@ -7134,6 +7222,13 @@ ], "summary": "Remove organization systemNotificationTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Remove organization systemNotification templates request", "name": "body", @@ -7168,6 +7263,13 @@ ], "summary": "Add organization systemNotificationTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Add organization systemNotification templates request", "name": "body", @@ -7324,6 +7426,13 @@ "in": "path", "required": true }, + { + "type": "string", + "description": "systemNotificationId", + "name": "systemNotificationId", + "in": "path", + "required": true + }, { "description": "Update cloud setting request", "name": "body", @@ -7405,6 +7514,13 @@ "name": "organizationId", "in": "path", "required": true + }, + { + "type": "string", + "description": "systemNotificationId", + "name": "systemNotificationId", + "in": "path", + "required": true } ], "responses": { diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index f22662d2..17dd7af9 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -4355,6 +4355,26 @@ paths: tags: - SystemNotificationTemplates /admin/system-notification-templates/{systemNotificationTemplateId}: + delete: + consumes: + - application/json + description: Delete SystemNotificationTemplate + parameters: + - description: systemNotificationTemplateId + in: path + name: systemNotificationTemplateId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + security: + - JWT: [] + summary: Delete SystemNotificationTemplate + tags: + - SystemNotificationTemplates get: consumes: - application/json @@ -4382,6 +4402,11 @@ paths: - application/json description: Update SystemNotificationTemplate parameters: + - description: systemNotificationTemplateId + in: path + name: systemNotificationTemplateId + required: true + type: string - description: Update alert template request in: body name: body @@ -7870,6 +7895,11 @@ paths: - application/json description: Get SystemNotificationRules parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: pageSize in: query name: limit @@ -7910,6 +7940,11 @@ paths: - application/json description: Create SystemNotificationRule parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: create stack template request in: body name: body @@ -7934,6 +7969,11 @@ paths: - application/json description: Delete SystemNotificationRule parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: systemNotificationRuleId in: path name: systemNotificationRuleId @@ -7954,6 +7994,11 @@ paths: - application/json description: Get SystemNotificationRule parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: systemNotificationRuleId in: path name: systemNotificationRuleId @@ -7976,6 +8021,16 @@ paths: - application/json description: Update SystemNotificationRule parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string + - description: systemNotificationRuleId + in: path + name: systemNotificationRuleId + required: true + type: string - description: Update systemNotificationRule request in: body name: body @@ -8003,6 +8058,11 @@ paths: name: name required: true type: string + - description: organizationId + in: path + name: organizationId + required: true + type: string produces: - application/json responses: @@ -8061,6 +8121,11 @@ paths: - application/json description: Add organization systemNotificationTemplates parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: Add organization systemNotification templates request in: body name: body @@ -8082,6 +8147,11 @@ paths: - application/json description: Remove organization systemNotificationTemplates parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: Remove organization systemNotification templates request in: body name: body @@ -8207,6 +8277,11 @@ paths: name: organizationId required: true type: string + - description: systemNotificationId + in: path + name: systemNotificationId + required: true + type: string - description: Update cloud setting request in: body name: body @@ -8234,6 +8309,11 @@ paths: name: organizationId required: true type: string + - description: systemNotificationId + in: path + name: systemNotificationId + required: true + type: string produces: - application/json responses: diff --git a/internal/delivery/api/endpoint.go b/internal/delivery/api/endpoint.go index e740b404..b69a561d 100644 --- a/internal/delivery/api/endpoint.go +++ b/internal/delivery/api/endpoint.go @@ -120,6 +120,7 @@ const ( // SystemNotificationTemplate Admin_CreateSystemNotificationTemplate Admin_UpdateSystemNotificationTemplate + Admin_DeleteSystemNotificationTemplate Admin_GetSystemNotificationTemplates Admin_GetSystemNotificationTemplate GetOrganizationSystemNotificationTemplates diff --git a/internal/delivery/api/generated_endpoints.go.go b/internal/delivery/api/generated_endpoints.go.go index 9e2c008d..1af52d51 100644 --- a/internal/delivery/api/generated_endpoints.go.go +++ b/internal/delivery/api/generated_endpoints.go.go @@ -359,6 +359,10 @@ var ApiMap = map[Endpoint]EndpointInfo{ Name: "Admin_UpdateSystemNotificationTemplate", Group: "SystemNotificationTemplate", }, + Admin_DeleteSystemNotificationTemplate: { + Name: "Admin_DeleteSystemNotificationTemplate", + Group: "SystemNotificationTemplate", + }, Admin_GetSystemNotificationTemplates: { Name: "Admin_GetSystemNotificationTemplates", Group: "SystemNotificationTemplate", @@ -988,6 +992,8 @@ func (e Endpoint) String() string { return "Admin_CreateSystemNotificationTemplate" case Admin_UpdateSystemNotificationTemplate: return "Admin_UpdateSystemNotificationTemplate" + case Admin_DeleteSystemNotificationTemplate: + return "Admin_DeleteSystemNotificationTemplate" case Admin_GetSystemNotificationTemplates: return "Admin_GetSystemNotificationTemplates" case Admin_GetSystemNotificationTemplate: @@ -1396,6 +1402,8 @@ func GetEndpoint(name string) Endpoint { return Admin_CreateSystemNotificationTemplate case "Admin_UpdateSystemNotificationTemplate": return Admin_UpdateSystemNotificationTemplate + case "Admin_DeleteSystemNotificationTemplate": + return Admin_DeleteSystemNotificationTemplate case "Admin_GetSystemNotificationTemplates": return Admin_GetSystemNotificationTemplates case "Admin_GetSystemNotificationTemplate": diff --git a/internal/delivery/http/stack-template.go b/internal/delivery/http/stack-template.go index ba1d7935..fdbcd4b9 100644 --- a/internal/delivery/http/stack-template.go +++ b/internal/delivery/http/stack-template.go @@ -220,13 +220,24 @@ func (h *StackTemplateHandler) UpdateStackTemplate(w http.ResponseWriter, r *htt // @Security JWT func (h *StackTemplateHandler) DeleteStackTemplate(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - _, ok := vars["stackTemplateId"] + strId, ok := vars["stackTemplateId"] if !ok { ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid stackTemplateId"), "C_INVALID_STACK_TEMPLATE_ID", "")) return } - ErrorJSON(w, r, fmt.Errorf("need implementation")) + stackTemplateId, err := uuid.Parse(strId) + if err != nil { + ErrorJSON(w, r, httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to parse uuid %s"), "C_INVALID_STACK_TEMPLATE_ID", "")) + return + } + + err = h.usecase.Delete(r.Context(), stackTemplateId) + if err != nil { + ErrorJSON(w, r, err) + return + } + ResponseJSON(w, r, http.StatusOK, nil) } // GetStackTemplateServices godoc diff --git a/internal/delivery/http/system-notification-rule.go b/internal/delivery/http/system-notification-rule.go index 2c27207c..ee245d95 100644 --- a/internal/delivery/http/system-notification-rule.go +++ b/internal/delivery/http/system-notification-rule.go @@ -34,8 +34,9 @@ func NewSystemNotificationRuleHandler(h usecase.Usecase) *SystemNotificationRule // @Description Create SystemNotificationRule // @Accept json // @Produce json -// @Param body body domain.CreateSystemNotificationRuleRequest true "create stack template request" -// @Success 200 {object} domain.CreateSystemNotificationRuleResponse +// @Param organizationId path string true "organizationId" +// @Param body body domain.CreateSystemNotificationRuleRequest true "create stack template request" +// @Success 200 {object} domain.CreateSystemNotificationRuleResponse // @Router /organizations/{organizationId}/system-notification-rules [post] // @Security JWT func (h *SystemNotificationRuleHandler) CreateSystemNotificationRule(w http.ResponseWriter, r *http.Request) { @@ -85,12 +86,13 @@ func (h *SystemNotificationRuleHandler) CreateSystemNotificationRule(w http.Resp // @Description Get SystemNotificationRules // @Accept json // @Produce json -// @Param limit query string false "pageSize" -// @Param page query string false "pageNumber" -// @Param soertColumn query string false "sortColumn" -// @Param sortOrder query string false "sortOrder" -// @Param filters query []string false "filters" -// @Success 200 {object} domain.GetSystemNotificationRulesResponse +// @Param organizationId path string true "organizationId" +// @Param limit query string false "pageSize" +// @Param page query string false "pageNumber" +// @Param soertColumn query string false "sortColumn" +// @Param sortOrder query string false "sortOrder" +// @Param filters query []string false "filters" +// @Success 200 {object} domain.GetSystemNotificationRulesResponse // @Router /organizations/{organizationId}/system-notification-rules [get] // @Security JWT func (h *SystemNotificationRuleHandler) GetSystemNotificationRules(w http.ResponseWriter, r *http.Request) { @@ -150,6 +152,7 @@ func (h *SystemNotificationRuleHandler) GetSystemNotificationRules(w http.Respon // @Description Get SystemNotificationRule // @Accept json // @Produce json +// @Param organizationId path string true "organizationId" // @Param systemNotificationRuleId path string true "systemNotificationRuleId" // @Success 200 {object} domain.GetSystemNotificationRuleResponse // @Router /organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId} [get] @@ -158,13 +161,13 @@ func (h *SystemNotificationRuleHandler) GetSystemNotificationRule(w http.Respons vars := mux.Vars(r) strId, ok := vars["systemNotificationRuleId"] if !ok { - ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid systemNotificationRuleId"), "C_INVALID_STACK_TEMPLATE_ID", "")) + ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid systemNotificationRuleId"), "C_INVALID_SYSTEM_NOTIFICATION_RULE_ID", "")) return } systemNotificationRuleId, err := uuid.Parse(strId) if err != nil { - ErrorJSON(w, r, httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to parse uuid %s"), "C_INVALID_STACK_TEMPLATE_ID", "")) + ErrorJSON(w, r, httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to parse uuid %s"), "C_INVALID_SYSTEM_NOTIFICATION_RULE_ID", "")) return } @@ -201,8 +204,10 @@ func (h *SystemNotificationRuleHandler) GetSystemNotificationRule(w http.Respons // @Description Update SystemNotificationRule // @Accept json // @Produce json -// @Param body body domain.UpdateSystemNotificationRuleRequest true "Update systemNotificationRule request" -// @Success 200 {object} nil +// @Param organizationId path string true "organizationId" +// @Param systemNotificationRuleId path string true "systemNotificationRuleId" +// @Param body body domain.UpdateSystemNotificationRuleRequest true "Update systemNotificationRule request" +// @Success 200 {object} nil // @Router /organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId} [put] // @Security JWT func (h *SystemNotificationRuleHandler) UpdateSystemNotificationRule(w http.ResponseWriter, r *http.Request) { @@ -260,19 +265,30 @@ func (h *SystemNotificationRuleHandler) UpdateSystemNotificationRule(w http.Resp // @Description Delete SystemNotificationRule // @Accept json // @Produce json +// @Param organizationId path string true "organizationId" // @Param systemNotificationRuleId path string true "systemNotificationRuleId" // @Success 200 {object} nil // @Router /organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId} [delete] // @Security JWT func (h *SystemNotificationRuleHandler) DeleteSystemNotificationRule(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - _, ok := vars["systemNotificationRuleId"] + strId, ok := vars["systemNotificationRuleId"] if !ok { - ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid systemNotificationRuleId"), "C_INVALID_STACK_TEMPLATE_ID", "")) + ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid systemNotificationRuleId"), "C_INVALID_SYSTEM_NOTIFICATION_RULE_ID", "")) + return + } + systemNotificationRuleId, err := uuid.Parse(strId) + if err != nil { + ErrorJSON(w, r, httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to parse uuid %s"), "C_INVALID_SYSTEM_NOTIFICATION_RULE_ID", "")) return } - ErrorJSON(w, r, fmt.Errorf("need implementation")) + err = h.usecase.Delete(r.Context(), systemNotificationRuleId) + if err != nil { + ErrorJSON(w, r, err) + return + } + ResponseJSON(w, r, http.StatusOK, nil) } // CheckSystemNotificationRuleName godoc @@ -282,8 +298,9 @@ func (h *SystemNotificationRuleHandler) DeleteSystemNotificationRule(w http.Resp // @Description Check name for systemNotificationRule // @Accept json // @Produce json -// @Param name path string true "name" -// @Success 200 {object} domain.CheckSystemNotificationRuleNameResponse +// @Param name path string true "name" +// @Param organizationId path string true "organizationId" +// @Success 200 {object} domain.CheckSystemNotificationRuleNameResponse // @Router /organizations/{organizationId}/system-notification-rules/name/{name}/existence [GET] // @Security JWT func (h *SystemNotificationRuleHandler) CheckSystemNotificationRuleName(w http.ResponseWriter, r *http.Request) { diff --git a/internal/delivery/http/system-notification-template.go b/internal/delivery/http/system-notification-template.go index e4b11b01..ce4aefa0 100644 --- a/internal/delivery/http/system-notification-template.go +++ b/internal/delivery/http/system-notification-template.go @@ -175,8 +175,9 @@ func (h *SystemNotificationTemplateHandler) GetSystemNotificationTemplate(w http // @Description Update SystemNotificationTemplate // @Accept json // @Produce json -// @Param body body domain.UpdateSystemNotificationTemplateRequest true "Update alert template request" -// @Success 200 {object} nil +// @Param systemNotificationTemplateId path string true "systemNotificationTemplateId" +// @Param body body domain.UpdateSystemNotificationTemplateRequest true "Update alert template request" +// @Success 200 {object} nil // @Router /admin/system-notification-templates/{systemNotificationTemplateId} [put] // @Security JWT func (h *SystemNotificationTemplateHandler) UpdateSystemNotificationTemplate(w http.ResponseWriter, r *http.Request) { @@ -220,6 +221,39 @@ func (h *SystemNotificationTemplateHandler) UpdateSystemNotificationTemplate(w h ResponseJSON(w, r, http.StatusOK, nil) } +// DeleteSystemNotificationTemplate godoc +// +// @Tags SystemNotificationTemplates +// @Summary Delete SystemNotificationTemplate +// @Description Delete SystemNotificationTemplate +// @Accept json +// @Produce json +// @Param systemNotificationTemplateId path string true "systemNotificationTemplateId" +// @Success 200 {object} nil +// @Router /admin/system-notification-templates/{systemNotificationTemplateId} [delete] +// @Security JWT +func (h *SystemNotificationTemplateHandler) DeleteSystemNotificationTemplate(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + strId, ok := vars["systemNotificationTemplateId"] + if !ok { + ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid systemNotificationTemplateId"), "C_INVALID_SYSTEM_NOTIFICATION_TEMPLATE_ID", "")) + return + } + systemNotificationTemplateId, err := uuid.Parse(strId) + if err != nil { + ErrorJSON(w, r, httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to parse uuid %s"), "C_INVALID_SYSTEM_NOTIFICATION_TEMPLATE_ID", "")) + return + } + + err = h.usecase.Delete(r.Context(), systemNotificationTemplateId) + if err != nil { + ErrorJSON(w, r, err) + return + } + + ResponseJSON(w, r, http.StatusOK, nil) +} + // GetOrganizationSystemNotificationTemplates godoc // // @Tags SystemNotificationTemplates @@ -280,8 +314,9 @@ func (h *SystemNotificationTemplateHandler) GetOrganizationSystemNotificationTem // @Description Add organization systemNotificationTemplates // @Accept json // @Produce json -// @Param body body domain.AddOrganizationSystemNotificationTemplatesRequest true "Add organization systemNotification templates request" -// @Success 200 {object} nil +// @Param organizationId path string true "organizationId" +// @Param body body domain.AddOrganizationSystemNotificationTemplatesRequest true "Add organization systemNotification templates request" +// @Success 200 {object} nil // @Router /organizations/{organizationId}/system-notification-templates [post] // @Security JWT func (h *SystemNotificationTemplateHandler) AddOrganizationSystemNotificationTemplates(w http.ResponseWriter, r *http.Request) { @@ -314,8 +349,9 @@ func (h *SystemNotificationTemplateHandler) AddOrganizationSystemNotificationTem // @Description Remove organization systemNotificationTemplates // @Accept json // @Produce json -// @Param body body domain.RemoveOrganizationSystemNotificationTemplatesRequest true "Remove organization systemNotification templates request" -// @Success 200 {object} nil +// @Param organizationId path string true "organizationId" +// @Param body body domain.RemoveOrganizationSystemNotificationTemplatesRequest true "Remove organization systemNotification templates request" +// @Success 200 {object} nil // @Router /organizations/{organizationId}/system-notification-templates [put] // @Security JWT func (h *SystemNotificationTemplateHandler) RemoveOrganizationSystemNotificationTemplates(w http.ResponseWriter, r *http.Request) { diff --git a/internal/delivery/http/system-notification.go b/internal/delivery/http/system-notification.go index 9f056bcb..49322289 100644 --- a/internal/delivery/http/system-notification.go +++ b/internal/delivery/http/system-notification.go @@ -204,9 +204,10 @@ func (h *SystemNotificationHandler) GetSystemNotification(w http.ResponseWriter, // @Description Update SystemNotification // @Accept json // @Produce json -// @Param organizationId path string true "organizationId" -// @Param body body domain.UpdateSystemNotificationRequest true "Update cloud setting request" -// @Success 200 {object} nil +// @Param organizationId path string true "organizationId" +// @Param systemNotificationId path string true "systemNotificationId" +// @Param body body domain.UpdateSystemNotificationRequest true "Update cloud setting request" +// @Success 200 {object} nil // @Router /organizations/{organizationId}/system-notifications/{systemNotificationId} [put] // @Security JWT func (h *SystemNotificationHandler) UpdateSystemNotification(w http.ResponseWriter, r *http.Request) { @@ -246,8 +247,9 @@ func (h *SystemNotificationHandler) SystemNotificationTest(w http.ResponseWriter // @Description Create systemNotification action // @Accept json // @Produce json -// @Param organizationId path string true "organizationId" -// @Success 200 {object} nil +// @Param organizationId path string true "organizationId" +// @Param systemNotificationId path string true "systemNotificationId" +// @Success 200 {object} nil // @Router /organizations/{organizationId}/system-notifications/{systemNotificationId}/actions [post] // @Security JWT func (h *SystemNotificationHandler) CreateSystemNotificationAction(w http.ResponseWriter, r *http.Request) { diff --git a/internal/model/system-notification-rule.go b/internal/model/system-notification-rule.go index 9ab63c37..e1fc06eb 100644 --- a/internal/model/system-notification-rule.go +++ b/internal/model/system-notification-rule.go @@ -30,8 +30,8 @@ type SystemNotificationRule struct { Organization Organization `gorm:"foreignKey:OrganizationId"` SystemNotificationTemplate SystemNotificationTemplate `gorm:"foreignKey:SystemNotificationTemplateId"` SystemNotificationTemplateId string - SystemNotificationConditions []SystemNotificationCondition `gorm:"foreignKey:SystemNotificationRuleId"` - TargetUsers []User `gorm:"many2many:system_notification_rule_users"` + SystemNotificationConditions []SystemNotificationCondition `gorm:"foreignKey:SystemNotificationRuleId;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"` + TargetUsers []User `gorm:"many2many:system_notification_rule_users;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"` TargetUserIds []string `gorm:"-:all"` MessageTitle string MessageContent string diff --git a/internal/model/system-notification-template.go b/internal/model/system-notification-template.go index 3c07964e..4c8ba603 100644 --- a/internal/model/system-notification-template.go +++ b/internal/model/system-notification-template.go @@ -7,8 +7,10 @@ import ( // Models type MetricParameter struct { - SystemNotificationTemplateId uuid.UUID `gorm:"primarykey"` - Order int `gorm:"primarykey"` + gorm.Model + + SystemNotificationTemplateId uuid.UUID + Order int Key string Value string } @@ -18,11 +20,11 @@ type SystemNotificationTemplate struct { ID uuid.UUID `gorm:"primarykey"` Name string `gorm:"index:idx_name,unique"` - Organizations []Organization `gorm:"many2many:system_notification_template_organizations"` + Organizations []Organization `gorm:"many2many:system_notification_template_organizations;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"` OrganizationIds []string `gorm:"-:all"` Description string MetricQuery string - MetricParameters []MetricParameter `gorm:"foreignKey:SystemNotificationTemplateId;references:ID"` + MetricParameters []MetricParameter `gorm:"foreignKey:SystemNotificationTemplateId;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"` CreatorId *uuid.UUID Creator User `gorm:"foreignKey:CreatorId"` UpdatorId *uuid.UUID diff --git a/internal/model/system-notification.go b/internal/model/system-notification.go index aea8cbb0..3c5678cc 100644 --- a/internal/model/system-notification.go +++ b/internal/model/system-notification.go @@ -26,13 +26,13 @@ type SystemNotification struct { Node string CheckPoint string GrafanaUrl string - FiredAt *time.Time `gorm:"-:all"` - TakedAt *time.Time `gorm:"-:all"` - ClosedAt *time.Time `gorm:"-:all"` - TakedSec int `gorm:"-:all"` - ProcessingSec int `gorm:"-:all"` - LastTaker User `gorm:"-:all"` - SystemNotificationActions []SystemNotificationAction + FiredAt *time.Time `gorm:"-:all"` + TakedAt *time.Time `gorm:"-:all"` + ClosedAt *time.Time `gorm:"-:all"` + TakedSec int `gorm:"-:all"` + ProcessingSec int `gorm:"-:all"` + LastTaker User `gorm:"-:all"` + SystemNotificationActions []SystemNotificationAction `gorm:"foreignKey:SystemNotificationId;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"` Summary string RawData datatypes.JSON Status domain.SystemNotificationActionStatus `gorm:"index"` diff --git a/internal/route/route.go b/internal/route/route.go index 36a6fbd4..a209a15f 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -224,6 +224,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates", customMiddleware.Handle(internalApi.Admin_GetSystemNotificationTemplates, http.HandlerFunc(systemNotificationTemplateHandler.GetSystemNotificationTemplates))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates/{systemNotificationTemplateId}", customMiddleware.Handle(internalApi.Admin_GetSystemNotificationTemplate, http.HandlerFunc(systemNotificationTemplateHandler.GetSystemNotificationTemplate))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates/{systemNotificationTemplateId}", customMiddleware.Handle(internalApi.Admin_UpdateSystemNotificationTemplate, http.HandlerFunc(systemNotificationTemplateHandler.UpdateSystemNotificationTemplate))).Methods(http.MethodPut) + r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates/{systemNotificationTemplateId}", customMiddleware.Handle(internalApi.Admin_DeleteSystemNotificationTemplate, http.HandlerFunc(systemNotificationTemplateHandler.DeleteSystemNotificationTemplate))).Methods(http.MethodDelete) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-templates", customMiddleware.Handle(internalApi.GetOrganizationSystemNotificationTemplates, http.HandlerFunc(systemNotificationTemplateHandler.GetOrganizationSystemNotificationTemplates))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-templates", customMiddleware.Handle(internalApi.AddOrganizationSystemNotificationTemplates, http.HandlerFunc(systemNotificationTemplateHandler.AddOrganizationSystemNotificationTemplates))).Methods(http.MethodPost) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-templates", customMiddleware.Handle(internalApi.RemoveOrganizationSystemNotificationTemplates, http.HandlerFunc(systemNotificationTemplateHandler.RemoveOrganizationSystemNotificationTemplates))).Methods(http.MethodPut) @@ -233,6 +234,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa 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/{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) + r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId}", customMiddleware.Handle(internalApi.DeleteSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.DeleteSystemNotificationRule))).Methods(http.MethodDelete) stackHandler := delivery.NewStackHandler(usecaseFactory) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks", customMiddleware.Handle(internalApi.GetStacks, http.HandlerFunc(stackHandler.GetStacks))).Methods(http.MethodGet) diff --git a/internal/usecase/stack-template.go b/internal/usecase/stack-template.go index 2b56f9e1..b397e01f 100644 --- a/internal/usecase/stack-template.go +++ b/internal/usecase/stack-template.go @@ -22,7 +22,7 @@ type IStackTemplateUsecase interface { FetchWithOrganization(ctx context.Context, organizationId string, pg *pagination.Pagination) ([]model.StackTemplate, error) Create(ctx context.Context, dto model.StackTemplate) (stackTemplate uuid.UUID, err error) Update(ctx context.Context, dto model.StackTemplate) error - Delete(ctx context.Context, dto model.StackTemplate) error + Delete(ctx context.Context, stackTemplateId uuid.UUID) error UpdateOrganizations(ctx context.Context, dto model.StackTemplate) error GetByName(ctx context.Context, name string) (model.StackTemplate, error) AddOrganizationStackTemplates(ctx context.Context, organizationId string, stackTemplateIds []string) error @@ -32,12 +32,14 @@ type IStackTemplateUsecase interface { type StackTemplateUsecase struct { repo repository.IStackTemplateRepository organizationRepo repository.IOrganizationRepository + clusterRepo repository.IClusterRepository } func NewStackTemplateUsecase(r repository.Repository) IStackTemplateUsecase { return &StackTemplateUsecase{ repo: r.StackTemplate, organizationRepo: r.Organization, + clusterRepo: r.Cluster, } } @@ -130,7 +132,34 @@ func (u *StackTemplateUsecase) FetchWithOrganization(ctx context.Context, organi return res, nil } -func (u *StackTemplateUsecase) Delete(ctx context.Context, dto model.StackTemplate) (err error) { +func (u *StackTemplateUsecase) Delete(ctx context.Context, stackTemplateId uuid.UUID) (err error) { + stackTemplate, err := u.repo.Get(ctx, stackTemplateId) + if err != nil { + return err + } + + user, ok := request.UserFrom(ctx) + if !ok { + return httpErrors.NewBadRequestError(fmt.Errorf("Invalid token"), "", "") + } + userId := user.GetUserId() + stackTemplate.UpdatorId = &userId + + // check if used + pg := pagination.NewPaginationWithFilter("stack_template_id", "", "$eq", []string{stackTemplateId.String()}) + res, err := u.clusterRepo.Fetch(ctx, pg) + if err != nil { + return err + } + if len(res) > 0 { + return httpErrors.NewBadRequestError(fmt.Errorf("Failed to delete stackTemplate %s", stackTemplateId.String()), "ST_FAILED_DELETE_EXIST_CLUSTERS", "") + } + + err = u.repo.Delete(ctx, stackTemplate) + if err != nil { + return err + } + return nil } diff --git a/internal/usecase/system-notification-rule.go b/internal/usecase/system-notification-rule.go index d69c5c15..096e552f 100644 --- a/internal/usecase/system-notification-rule.go +++ b/internal/usecase/system-notification-rule.go @@ -20,7 +20,7 @@ type ISystemNotificationRuleUsecase interface { Fetch(ctx context.Context, organizationId string, pg *pagination.Pagination) ([]model.SystemNotificationRule, error) Create(ctx context.Context, dto model.SystemNotificationRule) (systemNotificationRule uuid.UUID, err error) Update(ctx context.Context, dto model.SystemNotificationRule) error - Delete(ctx context.Context, dto model.SystemNotificationRule) error + Delete(ctx context.Context, systemNotificationRuleId uuid.UUID) error GetByName(ctx context.Context, name string) (model.SystemNotificationRule, error) } @@ -141,6 +141,22 @@ func (u *SystemNotificationRuleUsecase) Fetch(ctx context.Context, organizationI return res, nil } -func (u *SystemNotificationRuleUsecase) Delete(ctx context.Context, dto model.SystemNotificationRule) (err error) { - return nil +func (u *SystemNotificationRuleUsecase) Delete(ctx context.Context, systemNotificationRuleId uuid.UUID) (err error) { + systemNotificationRule, err := u.repo.Get(ctx, systemNotificationRuleId) + if err != nil { + return err + } + + user, ok := request.UserFrom(ctx) + if !ok { + return httpErrors.NewBadRequestError(fmt.Errorf("Invalid token"), "", "") + } + userId := user.GetUserId() + systemNotificationRule.UpdatorId = &userId + + err = u.repo.Delete(ctx, systemNotificationRule) + if err != nil { + return err + } + return } diff --git a/internal/usecase/system-notification-template.go b/internal/usecase/system-notification-template.go index 6516eb77..ebfd6cd7 100644 --- a/internal/usecase/system-notification-template.go +++ b/internal/usecase/system-notification-template.go @@ -22,24 +22,26 @@ type ISystemNotificationTemplateUsecase interface { FetchWithOrganization(ctx context.Context, organizationId string, pg *pagination.Pagination) ([]model.SystemNotificationTemplate, error) Create(ctx context.Context, dto model.SystemNotificationTemplate) (systemNotificationTemplate uuid.UUID, err error) Update(ctx context.Context, dto model.SystemNotificationTemplate) error - Delete(ctx context.Context, dto model.SystemNotificationTemplate) error + Delete(ctx context.Context, systemNotificationTemplateId uuid.UUID) error AddOrganizationSystemNotificationTemplates(ctx context.Context, organizationId string, systemNotificationTemplateIds []string) error RemoveOrganizationSystemNotificationTemplates(ctx context.Context, organizationId string, systemNotificationTemplateIds []string) error } type SystemNotificationTemplateUsecase struct { - repo repository.ISystemNotificationTemplateRepository - clusterRepo repository.IClusterRepository - organizationRepo repository.IOrganizationRepository - appGroupRepo repository.IAppGroupRepository + repo repository.ISystemNotificationTemplateRepository + clusterRepo repository.IClusterRepository + organizationRepo repository.IOrganizationRepository + appGroupRepo repository.IAppGroupRepository + systemNotificationRuleRepo repository.ISystemNotificationRuleRepository } func NewSystemNotificationTemplateUsecase(r repository.Repository) ISystemNotificationTemplateUsecase { return &SystemNotificationTemplateUsecase{ - repo: r.SystemNotificationTemplate, - clusterRepo: r.Cluster, - appGroupRepo: r.AppGroup, - organizationRepo: r.Organization, + repo: r.SystemNotificationTemplate, + clusterRepo: r.Cluster, + appGroupRepo: r.AppGroup, + organizationRepo: r.Organization, + systemNotificationRuleRepo: r.SystemNotificationRule, } } @@ -89,10 +91,10 @@ func (u *SystemNotificationTemplateUsecase) Update(ctx context.Context, dto mode return nil } -func (u *SystemNotificationTemplateUsecase) Get(ctx context.Context, systemNotificationTemplate uuid.UUID) (alert model.SystemNotificationTemplate, err error) { - alert, err = u.repo.Get(ctx, systemNotificationTemplate) +func (u *SystemNotificationTemplateUsecase) Get(ctx context.Context, systemNotificationTemplateId uuid.UUID) (systemNotificationTemplate model.SystemNotificationTemplate, err error) { + systemNotificationTemplate, err = u.repo.Get(ctx, systemNotificationTemplateId) if err != nil { - return alert, err + return systemNotificationTemplate, err } return } @@ -125,8 +127,36 @@ func (u *SystemNotificationTemplateUsecase) FetchWithOrganization(ctx context.Co return res, nil } -func (u *SystemNotificationTemplateUsecase) Delete(ctx context.Context, dto model.SystemNotificationTemplate) (err error) { - return nil +func (u *SystemNotificationTemplateUsecase) Delete(ctx context.Context, systemNotificationTemplateId uuid.UUID) (err error) { + systemNotificationTemplate, err := u.repo.Get(ctx, systemNotificationTemplateId) + if err != nil { + return err + } + + user, ok := request.UserFrom(ctx) + if !ok { + return httpErrors.NewBadRequestError(fmt.Errorf("Invalid token"), "", "") + } + userId := user.GetUserId() + systemNotificationTemplate.UpdatorId = &userId + + // check if used + // system_notification_rules + pg := pagination.NewPaginationWithFilter("system_notification_template_id", "", "$eq", []string{systemNotificationTemplateId.String()}) + res, err := u.systemNotificationRuleRepo.Fetch(ctx, pg) + if err != nil { + return err + } + if len(res) > 0 { + return httpErrors.NewBadRequestError(fmt.Errorf("Failed to delete systemNotificationTemplate %s", systemNotificationTemplateId.String()), "SNT_FAILED_DELETE_EXIST_RULES", "") + } + + err = u.repo.Delete(ctx, systemNotificationTemplate) + if err != nil { + return err + } + + return } func (u *SystemNotificationTemplateUsecase) UpdateOrganizations(ctx context.Context, dto model.SystemNotificationTemplate) error { diff --git a/pkg/httpErrors/errorCode.go b/pkg/httpErrors/errorCode.go index 63fe9dfd..9f0e39f0 100644 --- a/pkg/httpErrors/errorCode.go +++ b/pkg/httpErrors/errorCode.go @@ -14,6 +14,7 @@ var errorMap = map[ErrorCode]string{ "C_INVALID_CLOUD_ACCOUNT_ID": "유효하지 않은 클라우드어카운트 아이디입니다. 클라우드어카운트 아이디를 확인하세요.", "C_INVALID_STACK_TEMPLATE_ID": "유효하지 않은 스택템플릿 아이디입니다. 스택템플릿 아이디를 확인하세요.", "C_INVALID_SYSTEM_NOTIFICATION_TEMPLATE_ID": "유효하지 않은 알림템플릿 아이디입니다. 알림템플릿 아이디를 확인하세요.", + "C_INVALID_SYSTEM_NOTIFICATION_RULE_ID": "유효하지 않은 알림설정 아이디입니다. 알림설정 아이디를 확인하세요.", "C_INVALID_ASA_ID": "유효하지 않은 앱서빙앱 아이디입니다. 앱서빙앱 아이디를 확인하세요.", "C_INVALID_ASA_TASK_ID": "유효하지 않은 테스크 아이디입니다. 테스크 아이디를 확인하세요.", "C_INVALID_CLOUD_SERVICE": "유효하지 않은 클라우드서비스입니다.", @@ -87,6 +88,7 @@ var errorMap = map[ErrorCode]string{ "SNT_FAILED_FETCH_ALERT_TEMPLATE": "알림템플릿을 가져오는데 실패했습니다.", "SNT_FAILED_UPDATE_ORGANIZATION": "알림템플릿에 조직을 설정하는데 실패했습니다.", "SNT_NOT_EXISTED_ALERT_TEMPLATE": "업데이트할 알림템플릿이 존재하지 않습니다.", + "SNT_FAILED_DELETE_EXIST_RULES": "알림템플릿을 사용하고 있는 알림 설정이 있습니다. 알림 설정을 삭제하세요.", // SystemNotificationRule "SNR_CREATE_ALREADY_EXISTED_NAME": "알림 설정에 이미 존재하는 이름입니다.", @@ -110,6 +112,7 @@ var errorMap = map[ErrorCode]string{ "ST_FAILED_REMOVE_ORGANIZATION_STACK_TEMPLATE": "조직에서 스택템플릿을 삭제하는데 실패하였습니다.", "ST_FAILED_ADD_ORGANIZATION_SYSTEM_NOTIFICATION_TEMPLATE": "조직에 시스템알람템플릿을 추가하는데 실패하였습니다.", "ST_FAILED_REMOVE_ORGANIZATION_SYSTEM_NOTIFICATION_TEMPLATE": "조직에서 시스템알람템플릿을 삭제하는데 실패하였습니다.", + "ST_FAILED_DELETE_EXIST_CLUSTERS": "스택템플릿을 사용하고 있는 스택이 있습니다. 스택을 삭제하세요.", // PolicyTemplate "PT_CREATE_ALREADY_EXISTED_NAME": "정첵 템플릿에 이미 존재하는 이름입니다.",