Skip to content

Commit

Permalink
render
Browse files Browse the repository at this point in the history
  • Loading branch information
mstgnz committed Aug 19, 2024
1 parent 85a4ba7 commit 9a515b6
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
3 changes: 2 additions & 1 deletion handler/web/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions handler/web/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion handler/web/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion handler/web/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion handler/web/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion handler/web/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions handler/web/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/mstgnz/cronjob/models"
"github.com/mstgnz/cronjob/pkg/load"
"github.com/mstgnz/cronjob/services"
)

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion handler/web/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion services/render.go → pkg/load/render.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package services
package load

import (
"fmt"
Expand Down

0 comments on commit 9a515b6

Please sign in to comment.