Added a site setting section

This commit is contained in:
Leon Mika 2026-03-09 21:47:02 +11:00
parent 499c0d8568
commit 0bd91de234
17 changed files with 856 additions and 36 deletions

View file

@ -47,6 +47,7 @@ type Site struct {
Title string
Tagline string
CreatedAt int64
Timezone string
}
type Upload struct {

View file

@ -27,8 +27,9 @@ INSERT INTO sites (
guid,
title,
tagline,
timezone,
created_at
) VALUES (?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?)
RETURNING id
`
@ -37,6 +38,7 @@ type InsertSiteParams struct {
Guid string
Title string
Tagline string
Timezone string
CreatedAt int64
}
@ -46,6 +48,7 @@ func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64,
arg.Guid,
arg.Title,
arg.Tagline,
arg.Timezone,
arg.CreatedAt,
)
var id int64
@ -98,7 +101,7 @@ func (q *Queries) SelectAllSitesWithOwners(ctx context.Context) ([]SelectAllSite
}
const selectSiteByGUID = `-- name: SelectSiteByGUID :one
SELECT id, owner_id, guid, title, tagline, created_at FROM sites WHERE guid = ?
SELECT id, owner_id, guid, title, tagline, created_at, timezone FROM sites WHERE guid = ?
`
func (q *Queries) SelectSiteByGUID(ctx context.Context, guid string) (Site, error) {
@ -111,12 +114,13 @@ func (q *Queries) SelectSiteByGUID(ctx context.Context, guid string) (Site, erro
&i.Title,
&i.Tagline,
&i.CreatedAt,
&i.Timezone,
)
return i, err
}
const selectSiteByID = `-- name: SelectSiteByID :one
SELECT id, owner_id, guid, title, tagline, created_at FROM sites WHERE id = ?
SELECT id, owner_id, guid, title, tagline, created_at, timezone FROM sites WHERE id = ?
`
func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
@ -129,12 +133,13 @@ func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
&i.Title,
&i.Tagline,
&i.CreatedAt,
&i.Timezone,
)
return i, err
}
const selectSitesOwnedByUser = `-- name: SelectSitesOwnedByUser :many
SELECT id, owner_id, guid, title, tagline, created_at FROM sites WHERE owner_id = ? ORDER BY title ASC
SELECT id, owner_id, guid, title, tagline, created_at, timezone FROM sites WHERE owner_id = ? ORDER BY title ASC
`
func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]Site, error) {
@ -153,6 +158,7 @@ func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]
&i.Title,
&i.Tagline,
&i.CreatedAt,
&i.Timezone,
); err != nil {
return nil, err
}
@ -166,3 +172,24 @@ func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]
}
return items, nil
}
const updateSite = `-- name: UpdateSite :exec
UPDATE sites SET title = ?, tagline = ?, timezone = ? WHERE id = ?
`
type UpdateSiteParams struct {
Title string
Tagline string
Timezone string
ID int64
}
func (q *Queries) UpdateSite(ctx context.Context, arg UpdateSiteParams) error {
_, err := q.db.ExecContext(ctx, updateSite,
arg.Title,
arg.Tagline,
arg.Timezone,
arg.ID,
)
return err
}