From 9a515b61ae5e13c9b172269e9ebfeefea0bdf812 Mon Sep 17 00:00:00 2001 From: Mesut GENEZ Date: Mon, 19 Aug 2024 20:51:17 +0300 Subject: [PATCH] render --- handler/web/group.go | 3 ++- handler/web/home.go | 4 ++-- handler/web/notification.go | 3 ++- handler/web/request.go | 3 ++- handler/web/schedule.go | 3 ++- handler/web/setting.go | 3 ++- handler/web/user.go | 11 ++++++----- handler/web/webhook.go | 3 ++- {services => pkg/load}/render.go | 2 +- 9 files changed, 21 insertions(+), 14 deletions(-) rename {services => pkg/load}/render.go (98%) diff --git a/handler/web/group.go b/handler/web/group.go index 2bc8137..d4501d9 100644 --- a/handler/web/group.go +++ b/handler/web/group.go @@ -10,6 +10,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/mstgnz/cronjob/models" "github.com/mstgnz/cronjob/pkg/config" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/pkg/response" "github.com/mstgnz/cronjob/services" ) @@ -20,7 +21,7 @@ type GroupHandler struct { func (h *GroupHandler) HomeHandler(w http.ResponseWriter, r *http.Request) error { _, data := h.ListService(w, r) - return services.Render(w, r, "group", map[string]any{"lists": data.Data}, "group/list", "group/new") + return load.Render(w, r, "group", map[string]any{"lists": data.Data}, "group/list", "group/new") } func (h *GroupHandler) CreateHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/handler/web/home.go b/handler/web/home.go index 8b22a6f..96b979a 100644 --- a/handler/web/home.go +++ b/handler/web/home.go @@ -3,14 +3,14 @@ package web import ( "net/http" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/pkg/response" - "github.com/mstgnz/cronjob/services" ) type HomeHandler struct{} func (h *HomeHandler) HomeHandler(w http.ResponseWriter, r *http.Request) error { - return services.Render(w, r, "home", map[string]any{}) + return load.Render(w, r, "home", map[string]any{}) } func (h *HomeHandler) TriggerHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/handler/web/notification.go b/handler/web/notification.go index 7e6407b..f702222 100644 --- a/handler/web/notification.go +++ b/handler/web/notification.go @@ -11,6 +11,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/mstgnz/cronjob/models" "github.com/mstgnz/cronjob/pkg/config" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/pkg/response" "github.com/mstgnz/cronjob/services" ) @@ -23,7 +24,7 @@ type NotificationHandler struct { func (h *NotificationHandler) HomeHandler(w http.ResponseWriter, r *http.Request) error { _, notification := h.notify.ListService(w, r) - return services.Render(w, r, "notification", map[string]any{"lists": notification.Data}, "notification/list", "notification/email", "notification/message", "notification/new") + return load.Render(w, r, "notification", map[string]any{"lists": notification.Data}, "notification/list", "notification/email", "notification/message", "notification/new") } func (h *NotificationHandler) CreateHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/handler/web/request.go b/handler/web/request.go index d594fa2..ae42e97 100644 --- a/handler/web/request.go +++ b/handler/web/request.go @@ -11,6 +11,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/mstgnz/cronjob/models" "github.com/mstgnz/cronjob/pkg/config" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/pkg/response" "github.com/mstgnz/cronjob/services" ) @@ -22,7 +23,7 @@ type RequestHandler struct { func (h *RequestHandler) HomeHandler(w http.ResponseWriter, r *http.Request) error { _, requests := h.request.ListService(w, r) - return services.Render(w, r, "request", map[string]any{"lists": requests.Data}, "request/list", "request/header", "request/new") + return load.Render(w, r, "request", map[string]any{"lists": requests.Data}, "request/list", "request/header", "request/new") } func (h *RequestHandler) CreateHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/handler/web/schedule.go b/handler/web/schedule.go index ec42989..2679d92 100644 --- a/handler/web/schedule.go +++ b/handler/web/schedule.go @@ -10,6 +10,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/mstgnz/cronjob/models" "github.com/mstgnz/cronjob/pkg/config" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/pkg/response" "github.com/mstgnz/cronjob/services" ) @@ -26,7 +27,7 @@ func (h *ScheduleHandler) HomeHandler(w http.ResponseWriter, r *http.Request) er _, requests := h.request.ListService(w, r) _, schedules := h.schedule.ListService(w, r) _, notifications := h.notification.ListService(w, r) - return services.Render(w, r, "schedule", map[string]any{"lists": schedules.Data, "groups": group.Data, "requests": requests.Data, "notifications": notifications.Data}, "schedule/list", "schedule/log", "schedule/new") + return load.Render(w, r, "schedule", map[string]any{"lists": schedules.Data, "groups": group.Data, "requests": requests.Data, "notifications": notifications.Data}, "schedule/list", "schedule/log", "schedule/new") } func (h *ScheduleHandler) CreateHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/handler/web/setting.go b/handler/web/setting.go index 364f335..0f43b69 100644 --- a/handler/web/setting.go +++ b/handler/web/setting.go @@ -9,6 +9,7 @@ import ( "github.com/mstgnz/cronjob/models" "github.com/mstgnz/cronjob/pkg/config" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/pkg/response" "github.com/mstgnz/cronjob/services" ) @@ -18,7 +19,7 @@ type SettingHandler struct { } func (h *SettingHandler) HomeHandler(w http.ResponseWriter, r *http.Request) error { - return services.Render(w, r, "setting", map[string]any{}, "setting/user-list", "setting/user-new", "setting/app-log") + return load.Render(w, r, "setting", map[string]any{}, "setting/user-list", "setting/user-new", "setting/app-log") } func (h *SettingHandler) UserSignUpHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/handler/web/user.go b/handler/web/user.go index 051b612..581cd8a 100644 --- a/handler/web/user.go +++ b/handler/web/user.go @@ -6,6 +6,7 @@ import ( "time" "github.com/mstgnz/cronjob/models" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/services" ) @@ -16,7 +17,7 @@ type UserHandler struct { func (h *UserHandler) LoginHandler(w http.ResponseWriter, r *http.Request) error { switch r.Method { case http.MethodGet: - return services.Render(w, r, "login", map[string]any{}) + return load.Render(w, r, "login", map[string]any{}) case http.MethodPost: code, response := h.LoginService(w, r) if response.Status && code == http.StatusOK { @@ -39,7 +40,7 @@ func (h *UserHandler) LoginHandler(w http.ResponseWriter, r *http.Request) error func (h *UserHandler) RegisterHandler(w http.ResponseWriter, r *http.Request) error { switch r.Method { case http.MethodGet: - return services.Render(w, r, "register", map[string]any{}) + return load.Render(w, r, "register", map[string]any{}) case http.MethodPost: code, response := h.RegisterService(w, r) if response.Status && code == http.StatusCreated { @@ -60,15 +61,15 @@ func (h *UserHandler) RegisterHandler(w http.ResponseWriter, r *http.Request) er } func (h *UserHandler) HomeHandler(w http.ResponseWriter, r *http.Request) error { - return services.Render(w, r, "home", map[string]any{}) + return load.Render(w, r, "home", map[string]any{}) } func (h *UserHandler) ListHandler(w http.ResponseWriter, r *http.Request) error { - return services.Render(w, r, "schedule", map[string]any{}) + return load.Render(w, r, "schedule", map[string]any{}) } func (h *UserHandler) ProfileHandler(w http.ResponseWriter, r *http.Request) error { - return services.Render(w, r, "profile", map[string]any{}) + return load.Render(w, r, "profile", map[string]any{}) } func (h *UserHandler) LogoutHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/handler/web/webhook.go b/handler/web/webhook.go index e6801e8..44cc456 100644 --- a/handler/web/webhook.go +++ b/handler/web/webhook.go @@ -11,6 +11,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/mstgnz/cronjob/models" "github.com/mstgnz/cronjob/pkg/config" + "github.com/mstgnz/cronjob/pkg/load" "github.com/mstgnz/cronjob/pkg/response" "github.com/mstgnz/cronjob/services" ) @@ -20,7 +21,7 @@ type WebhookHandler struct { } func (h *WebhookHandler) HomeHandler(w http.ResponseWriter, r *http.Request) error { - return services.Render(w, r, "webhook", map[string]any{}, "webhook/list", "webhook/new") + return load.Render(w, r, "webhook", map[string]any{}, "webhook/list", "webhook/new") } func (h *WebhookHandler) CreateHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/services/render.go b/pkg/load/render.go similarity index 98% rename from services/render.go rename to pkg/load/render.go index 4d1fefb..e5319a3 100644 --- a/services/render.go +++ b/pkg/load/render.go @@ -1,4 +1,4 @@ -package services +package load import ( "fmt"