Fixed site ownership

This commit is contained in:
Leon Mika 2025-02-01 10:56:59 +11:00
parent cb54057305
commit 50f7e9632e
20 changed files with 192 additions and 78 deletions

View file

@ -160,7 +160,6 @@ type Site struct {
OwnerUserID int64
Name string
Title string
Url string
Theme string
Props []byte
}

View file

@ -10,7 +10,7 @@ import (
)
const getSiteWithID = `-- name: GetSiteWithID :one
SELECT id, owner_user_id, name, title, url, theme, props FROM sites WHERE id = $1 LIMIT 1
SELECT id, owner_user_id, name, title, theme, props FROM sites WHERE id = $1 LIMIT 1
`
func (q *Queries) GetSiteWithID(ctx context.Context, id int64) (Site, error) {
@ -21,7 +21,6 @@ func (q *Queries) GetSiteWithID(ctx context.Context, id int64) (Site, error) {
&i.OwnerUserID,
&i.Name,
&i.Title,
&i.Url,
&i.Theme,
&i.Props,
)
@ -29,7 +28,7 @@ func (q *Queries) GetSiteWithID(ctx context.Context, id int64) (Site, error) {
}
const listSites = `-- name: ListSites :one
SELECT id, owner_user_id, name, title, url, theme, props FROM sites
SELECT id, owner_user_id, name, title, theme, props FROM sites
`
func (q *Queries) ListSites(ctx context.Context) (Site, error) {
@ -40,7 +39,6 @@ func (q *Queries) ListSites(ctx context.Context) (Site, error) {
&i.OwnerUserID,
&i.Name,
&i.Title,
&i.Url,
&i.Theme,
&i.Props,
)
@ -52,10 +50,9 @@ INSERT INTO sites (
name,
owner_user_id,
title,
url,
theme,
props
) VALUES ($1, $2, $3, $4, $5, $6)
) VALUES ($1, $2, $3, $4, $5)
RETURNING id
`
@ -63,7 +60,6 @@ type NewSiteParams struct {
Name string
OwnerUserID int64
Title string
Url string
Theme string
Props []byte
}
@ -73,7 +69,6 @@ func (q *Queries) NewSite(ctx context.Context, arg NewSiteParams) (int64, error)
arg.Name,
arg.OwnerUserID,
arg.Title,
arg.Url,
arg.Theme,
arg.Props,
)

View file

@ -9,6 +9,29 @@ import (
"context"
)
const getTargetOfSiteRole = `-- name: GetTargetOfSiteRole :one
SELECT id, site_id, role, target_type, url, target_ref FROM publish_targets WHERE site_id = $1 AND role = $2 LIMIT 1
`
type GetTargetOfSiteRoleParams struct {
SiteID int64
Role TargetRole
}
func (q *Queries) GetTargetOfSiteRole(ctx context.Context, arg GetTargetOfSiteRoleParams) (PublishTarget, error) {
row := q.db.QueryRow(ctx, getTargetOfSiteRole, arg.SiteID, arg.Role)
var i PublishTarget
err := row.Scan(
&i.ID,
&i.SiteID,
&i.Role,
&i.TargetType,
&i.Url,
&i.TargetRef,
)
return i, err
}
const insertPublishTarget = `-- name: InsertPublishTarget :one
INSERT INTO publish_targets (
site_id,
@ -41,12 +64,12 @@ func (q *Queries) InsertPublishTarget(ctx context.Context, arg InsertPublishTarg
return id, err
}
const listPublishTargetsOfRole = `-- name: ListPublishTargetsOfRole :many
SELECT id, site_id, role, target_type, url, target_ref FROM publish_targets WHERE site_id = $1 AND role = 'production'
const listTargetsOfSite = `-- name: ListTargetsOfSite :many
SELECT id, site_id, role, target_type, url, target_ref FROM publish_targets WHERE site_id = $1
`
func (q *Queries) ListPublishTargetsOfRole(ctx context.Context, siteID int64) ([]PublishTarget, error) {
rows, err := q.db.Query(ctx, listPublishTargetsOfRole, siteID)
func (q *Queries) ListTargetsOfSite(ctx context.Context, siteID int64) ([]PublishTarget, error) {
rows, err := q.db.Query(ctx, listTargetsOfSite, siteID)
if err != nil {
return nil, err
}