Add persistent dark mode and server-assigned content IDs
This commit is contained in:
@@ -30,8 +30,16 @@ type CatalogChange struct {
|
||||
EffectSetIDs []string `json:"effectSetIds,omitempty"`
|
||||
}
|
||||
type CatalogResult struct {
|
||||
Version int64 `json:"version"`
|
||||
Version int64 `json:"version"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// Explicit definition IDs are reserved for trusted seed/import code. Browser
|
||||
// publications omit them; the server assigns an ID after resolving request replay.
|
||||
func (c CatalogChange) HasDefinitionID() bool {
|
||||
return (c.Title != nil && c.Title.ID != "") || (c.Item != nil && c.Item.ID != "") || (c.RequirementSet != nil && c.RequirementSet.ID != "") || (c.EffectSet != nil && c.EffectSet.ID != "")
|
||||
}
|
||||
|
||||
type CatalogAudit struct {
|
||||
ID string `json:"id"`
|
||||
Actor string `json:"actor"`
|
||||
@@ -168,7 +176,7 @@ func (d *DB) PublishCatalog(ctx context.Context, actor string, change CatalogCha
|
||||
}
|
||||
var previousActor, previousRequest string
|
||||
var result CatalogResult
|
||||
err = tx.QueryRowContext(ctx, d.q(`SELECT actor,request_json,result_version FROM catalog_changes WHERE id=?`), change.ID).Scan(&previousActor, &previousRequest, &result.Version)
|
||||
err = tx.QueryRowContext(ctx, d.q(`SELECT actor,request_json,result_version,target FROM catalog_changes WHERE id=?`), change.ID).Scan(&previousActor, &previousRequest, &result.Version, &result.ID)
|
||||
if err == nil {
|
||||
if previousActor != actor || previousRequest != string(request) {
|
||||
return CatalogResult{}, ErrCatalogRequest
|
||||
@@ -207,7 +215,7 @@ func (d *DB) PublishCatalog(ctx context.Context, actor string, change CatalogCha
|
||||
if err = tx.Commit(); err != nil {
|
||||
return CatalogResult{}, err
|
||||
}
|
||||
return CatalogResult{Version: catalog.Version}, nil
|
||||
return CatalogResult{Version: catalog.Version, ID: target}, nil
|
||||
}
|
||||
func (d *DB) CatalogChanges(ctx context.Context) ([]CatalogAudit, error) {
|
||||
rows, err := d.sql.QueryContext(ctx, `SELECT id,actor,op,target,reason,result_version,created_at FROM catalog_changes ORDER BY result_version DESC LIMIT 100`)
|
||||
|
||||
Reference in New Issue
Block a user