Added a suite GUID

This commit is contained in:
Leon Mika 2026-02-28 09:49:43 +11:00
parent 30d99eeb9e
commit 329de2f953
11 changed files with 44 additions and 41 deletions

View file

@ -31,6 +31,7 @@ type PublishTarget struct {
type Site struct {
ID int64
OwnerID int64
Guid string
Title string
Tagline string
CreatedAt int64

View file

@ -24,15 +24,17 @@ func (q *Queries) HasUsersAndSites(ctx context.Context) (sql.NullBool, error) {
const insertSite = `-- name: InsertSite :one
INSERT INTO sites (
owner_id,
guid,
title,
tagline,
created_at
) VALUES (?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?)
RETURNING id
`
type InsertSiteParams struct {
OwnerID int64
Guid string
Title string
Tagline string
CreatedAt int64
@ -41,6 +43,7 @@ type InsertSiteParams struct {
func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertSite,
arg.OwnerID,
arg.Guid,
arg.Title,
arg.Tagline,
arg.CreatedAt,
@ -51,7 +54,7 @@ func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64,
}
const selectSiteByID = `-- name: SelectSiteByID :one
SELECT id, owner_id, title, tagline, created_at FROM sites WHERE id = ?
SELECT id, owner_id, guid, title, tagline, created_at FROM sites WHERE id = ?
`
func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
@ -60,6 +63,7 @@ func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
err := row.Scan(
&i.ID,
&i.OwnerID,
&i.Guid,
&i.Title,
&i.Tagline,
&i.CreatedAt,
@ -68,7 +72,7 @@ func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) {
}
const selectSitesOwnedByUser = `-- name: SelectSitesOwnedByUser :many
SELECT id, owner_id, title, tagline, created_at FROM sites WHERE owner_id = ? ORDER BY title ASC
SELECT id, owner_id, guid, title, tagline, created_at FROM sites WHERE owner_id = ? ORDER BY title ASC
`
func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]Site, error) {
@ -83,6 +87,7 @@ func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]
if err := rows.Scan(
&i.ID,
&i.OwnerID,
&i.Guid,
&i.Title,
&i.Tagline,
&i.CreatedAt,

View file

@ -14,13 +14,7 @@ func (db *Provider) SelectSiteByID(ctx context.Context, id int64) (models.Site,
return models.Site{}, err
}
return models.Site{
ID: row.ID,
OwnerID: row.OwnerID,
Title: row.Title,
Tagline: row.Tagline,
Created: time.Unix(row.CreatedAt, 0).UTC(),
}, nil
return dbSiteToSite(row), nil
}
func (db *Provider) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]models.Site, error) {
@ -31,13 +25,7 @@ func (db *Provider) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) (
sites := make([]models.Site, len(rows))
for i, row := range rows {
sites[i] = models.Site{
ID: row.ID,
OwnerID: row.OwnerID,
Title: row.Title,
Tagline: row.Tagline,
Created: time.Unix(row.CreatedAt, 0).UTC(),
}
sites[i] = dbSiteToSite(row)
}
return sites, nil
}
@ -46,6 +34,7 @@ func (db *Provider) SaveSite(ctx context.Context, site *models.Site) error {
if site.ID == 0 {
newID, err := db.queries.InsertSite(ctx, sqlgen.InsertSiteParams{
OwnerID: site.OwnerID,
Guid: site.GUID,
Title: site.Title,
Tagline: site.Tagline,
CreatedAt: timeToInt(site.Created),
@ -68,3 +57,14 @@ func (db *Provider) HasUsersAndSites(ctx context.Context) (bool, error) {
}
return nullBool.Valid && nullBool.Bool, nil
}
func dbSiteToSite(row sqlgen.Site) models.Site {
return models.Site{
ID: row.ID,
OwnerID: row.OwnerID,
GUID: row.Guid,
Title: row.Title,
Tagline: row.Tagline,
Created: time.Unix(row.CreatedAt, 0).UTC(),
}
}