From 998ff009f592017348e3809e6f0d254dd52dd6c6 Mon Sep 17 00:00:00 2001 From: Diptesh Choudhuri Date: Tue, 24 Jan 2023 13:41:12 +0000 Subject: [PATCH] chore(settings): remove duplicated code --- routes/settings.go | 27 +-------------------------- views/settings.tpl.html | 10 ++++------ 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/routes/settings.go b/routes/settings.go index 6ed8ea4..1f13753 100644 --- a/routes/settings.go +++ b/routes/settings.go @@ -140,8 +140,6 @@ func (h *SettingsHandler) dispatchAction(action string) action { return h.actionDeleteAlias case "add_alias": return h.actionAddAlias - case "add_project_to_label": - return h.addProjectToLabel case "add_label": return h.actionAddLabel case "delete_label": @@ -382,30 +380,7 @@ func (h *SettingsHandler) actionAddLabel(w http.ResponseWriter, r *http.Request) return http.StatusBadRequest, "", "invalid input" } - return http.StatusOK, "label added successfully", "" -} - -func (h *SettingsHandler) addProjectToLabel(w http.ResponseWriter, r *http.Request) (int, string, string) { - if h.config.IsDev() { - loadTemplates() - } - user := middlewares.GetPrincipal(r) - label := &models.ProjectLabel{ - UserID: user.ID, - ProjectKey: r.PostFormValue("project"), - Label: r.PostFormValue("label"), - } - - if !label.IsValid() { - return http.StatusBadRequest, "", "invalid input" - } - - if _, err := h.projectLabelSrvc.Create(label); err != nil { - // TODO: distinguish between bad request, conflict and server error - return http.StatusBadRequest, "", "invalid input" - } - - return http.StatusOK, "added project to label successfully", "" + return http.StatusOK, "label added to project successfully", "" } func (h *SettingsHandler) actionDeleteLabel(w http.ResponseWriter, r *http.Request) (int, string, string) { diff --git a/views/settings.tpl.html b/views/settings.tpl.html index d1ad1f5..0323edd 100644 --- a/views/settings.tpl.html +++ b/views/settings.tpl.html @@ -272,13 +272,11 @@ {{ end }} {{ end }}
- - - + +