diff options
| author | 2025-10-28 23:15:23 +0700 | |
|---|---|---|
| committer | 2025-10-28 23:15:23 +0700 | |
| commit | bda4faeeed4d9859cfe8afd7952a751683d74bd8 (patch) | |
| tree | 464c18fed0c21b63b65425f48a3a790229461058 /internal/router/handlers/lang-user-unsubscribe.go | |
| parent | dd69b45d3a41be2b5c38892c3b107770a0f859f2 (diff) | |
| parent | 1862f232eb70105340a91e74a5630c233a411bca (diff) | |
| download | web-0.11.1.tar.gz web-0.11.1.zip | |
v0.11.1 (#18)v0.11.1
- refactor: make structurized implementation of routes + separate
identity of router
- feat: update go to 1.25
- feat: update all dependencies
- debug: display routes when debug logs turned on
Diffstat (limited to 'internal/router/handlers/lang-user-unsubscribe.go')
| -rw-r--r-- | internal/router/handlers/lang-user-unsubscribe.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/router/handlers/lang-user-unsubscribe.go b/internal/router/handlers/lang-user-unsubscribe.go new file mode 100644 index 0000000..4fbd244 --- /dev/null +++ b/internal/router/handlers/lang-user-unsubscribe.go @@ -0,0 +1,68 @@ +package handlers + +import ( + "log/slog" + + "github.com/SayaAndy/saya-today-web/internal/router" + "github.com/gofiber/fiber/v2" +) + +type UnsubscribeHandler struct { + router.BasicHandler +} + +func init() { + router.Routes = append(router.Routes, &UnsubscribeHandler{}) +} + +func (r *UnsubscribeHandler) Filter() (method string, path string) { + return "GET", "/:lang/user/unsubscribe" +} + +func (r *UnsubscribeHandler) IsTemplated() bool { + return false +} + +func (r *UnsubscribeHandler) TemplatesToInject() []string { + return []string{"views/pages/unsubscribe-page.html"} +} + +func (r *UnsubscribeHandler) ToValidateLang() router.LangSetting { + return router.InPath +} + +func (r *UnsubscribeHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) { + var statusEmoji, statusText, statusColor string + var status int + + unsubscribeCode := c.FormValue("code") + if unsubscribeCode == "" { + statusColor = "0, 0, 255" + statusEmoji = "(╭ರ_•́)" + statusText = supplements.Localization[lang].UnsubscribePage.UnsetCode + status = fiber.ErrBadRequest.Code + } else if clientError, serverError := supplements.Mailer.Unsubscribe(unsubscribeCode); clientError != nil { + slog.Info("got a client error when unsubscribing", slog.String("error", clientError.Error())) + statusColor = "255, 0, 0" + statusEmoji = "(͠≖~≖ ͡ )" + statusText = supplements.Localization[lang].UnsubscribePage.InvalidCode + status = fiber.ErrBadRequest.Code + } else if serverError != nil { + slog.Error("got a server error when unsubscribing", slog.String("error", serverError.Error())) + statusColor = "255, 128, 0" + statusEmoji = "( ˶°ㅁ°) !!" + statusText = supplements.Localization[lang].UnsubscribePage.OnServerError + status = fiber.ErrInternalServerError.Code + } else { + statusColor = "0, 255, 0" + statusEmoji = "♡⸜(˶˃ ᵕ ˂˶)⸝♡" + statusText = supplements.Localization[lang].UnsubscribePage.Success + status = fiber.StatusOK + } + + templateMap["StatusColor"] = statusColor + templateMap["StatusEmoji"] = statusEmoji + templateMap["StatusText"] = statusText + + return status, nil +} |