aboutsummaryrefslogtreecommitdiff
path: root/pkg/view/settings.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/view/settings.go')
-rw-r--r--pkg/view/settings.go42
1 files changed, 32 insertions, 10 deletions
diff --git a/pkg/view/settings.go b/pkg/view/settings.go
index 746dee4..e5acb1b 100644
--- a/pkg/view/settings.go
+++ b/pkg/view/settings.go
@@ -5,28 +5,50 @@ import (
"git.sr.ht/~gabrielgio/img"
"git.sr.ht/~gabrielgio/img/pkg/components/settings"
+ "git.sr.ht/~gabrielgio/img/pkg/components/user"
"git.sr.ht/~gabrielgio/img/pkg/ext"
)
-type SettingsView struct {
- // there is not need to create a controller for this
- repository settings.Repository
-}
+type (
+ SettingsView struct {
+ // there is not need to create a controller for this
+ settingsRepository settings.Repository
+ userRepository user.Repository
+ }
+
+ SettingsPage struct {
+ Settings *settings.Settings
+ Users []*user.User
+ }
+)
-func NewSettingsView(respository settings.Repository) *SettingsView {
+func NewSettingsView(
+ settingsRespository settings.Repository,
+ userRepository user.Repository,
+) *SettingsView {
return &SettingsView{
- repository: respository,
+ settingsRepository: settingsRespository,
+ userRepository: userRepository,
}
}
func (self *SettingsView) Index(ctx *fasthttp.RequestCtx) error {
- s, err := self.repository.Load(ctx)
+ s, err := self.settingsRepository.Load(ctx)
if err != nil {
return err
}
- return img.Render(ctx, "settings.html", &img.HTMLView[*settings.Settings]{
+
+ users, err := self.userRepository.List(ctx)
+ if err != nil {
+ return err
+ }
+
+ return img.Render(ctx, "settings.html", &img.HTMLView[*SettingsPage]{
Title: "Settings",
- Data: s,
+ Data: &SettingsPage{
+ Settings: s,
+ Users: users,
+ },
})
}
@@ -36,7 +58,7 @@ func (self *SettingsView) Save(ctx *fasthttp.RequestCtx) error {
showOwner = string(ctx.FormValue("showOwner")) == "on"
)
- err := self.repository.Save(ctx, &settings.Settings{
+ err := self.settingsRepository.Save(ctx, &settings.Settings{
ShowMode: showMode,
ShowOwner: showOwner,
})