stores

package
v0.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureContentOverlay added in v0.24.0

func EnsureContentOverlay(ctx context.Context, db *bun.DB) error

EnsureContentOverlay applies the admin content overlay (views + media table).

func NewFilteredContentRepository

func NewFilteredContentRepository(content admin.CMSContentService, contentType string) *admin.CMSContentRepository

NewFilteredContentRepository wraps CMSContentService to enforce a fixed content_type.

func NewPageRecordRepository

func NewPageRecordRepository(db *bun.DB, opts ...repository.Option) repository.Repository[*PageRecord]

NewPageRecordRepository builds a repository for CMS-backed page records.

func NewPostRecordRepository

func NewPostRecordRepository(db *bun.DB, opts ...repository.Option) repository.Repository[*PostRecord]

NewPostRecordRepository builds a repository for CMS-backed post records.

func PageRecordToMap added in v0.24.0

func PageRecordToMap(record *PageRecord) map[string]any

func ResolveContentDSN

func ResolveContentDSN() string

ResolveContentDSN returns the SQLite DSN for content persistence. It checks CONTENT_DATABASE_DSN first, then CMS_DATABASE_DSN, and finally falls back to a shared temp-file path to keep parity with the CMS/users examples.

func SanitizeSQLiteMigrations

func SanitizeSQLiteMigrations(src fs.FS) fs.FS

func SetupContentDatabase

func SetupContentDatabase(ctx context.Context, dsn string, opts ...persistence.ClientOption) (*bun.DB, error)

SetupContentDatabase opens a SQLite connection, applies the content migrations, and returns a Bun DB handle.

Types

type AdminPageStoreAdapter added in v0.24.0

type AdminPageStoreAdapter struct {
	// contains filtered or unexported fields
}

AdminPageStoreAdapter exposes admin read/write services backed by the page repository/store.

func NewAdminPageStoreAdapter added in v0.24.0

func NewAdminPageStoreAdapter(repo repository.Repository[*PageRecord], store PageRepository, defaultLocale string) *AdminPageStoreAdapter

NewAdminPageStoreAdapter wires repo/store-backed admin page services.

func (*AdminPageStoreAdapter) Create added in v0.24.0

func (s *AdminPageStoreAdapter) Create(ctx context.Context, payload map[string]any) (*admin.AdminPageRecord, error)

Create inserts a page record via the store.

func (*AdminPageStoreAdapter) Delete added in v0.24.0

func (s *AdminPageStoreAdapter) Delete(ctx context.Context, id string) error

Delete removes a page record via the store.

func (*AdminPageStoreAdapter) Get added in v0.24.0

Get returns a single admin page record using the CMS-backed store when available.

func (*AdminPageStoreAdapter) List added in v0.24.0

List returns admin page records using the view-backed repository when available.

func (*AdminPageStoreAdapter) Publish added in v0.24.0

func (s *AdminPageStoreAdapter) Publish(ctx context.Context, id string, payload map[string]any) (*admin.AdminPageRecord, error)

Publish applies publish updates via the store.

func (*AdminPageStoreAdapter) Unpublish added in v0.24.0

func (s *AdminPageStoreAdapter) Unpublish(ctx context.Context, id string, payload map[string]any) (*admin.AdminPageRecord, error)

Unpublish applies draft updates via the store.

func (*AdminPageStoreAdapter) Update added in v0.24.0

func (s *AdminPageStoreAdapter) Update(ctx context.Context, id string, payload map[string]any) (*admin.AdminPageRecord, error)

Update modifies a page record via the store.

type CMSPageStore

type CMSPageStore struct {
	// contains filtered or unexported fields
}

CMSPageStore adapts a CMSContentService-backed page repository to the panel/store contract.

func NewCMSPageStore

func NewCMSPageStore(content admin.CMSContentService, defaultLocale string) *CMSPageStore

NewCMSPageStore builds a go-cms-backed page store. Returns nil when no content service is provided.

func (*CMSPageStore) Create

func (s *CMSPageStore) Create(ctx context.Context, record map[string]any) (map[string]any, error)

Create inserts a page into the CMS backend.

func (*CMSPageStore) Delete

func (s *CMSPageStore) Delete(ctx context.Context, id string) error

Delete removes a page.

func (*CMSPageStore) Get

func (s *CMSPageStore) Get(ctx context.Context, id string) (map[string]any, error)

Get returns a single page.

func (*CMSPageStore) List

func (s *CMSPageStore) List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)

List returns CMS pages filtered by locale/search.

func (*CMSPageStore) Publish

func (s *CMSPageStore) Publish(ctx context.Context, ids []string) ([]map[string]any, error)

Publish marks matching pages as published.

func (*CMSPageStore) Seed

func (s *CMSPageStore) Seed()

Seed inserts sample pages when the CMS backend is empty.

func (*CMSPageStore) Unpublish

func (s *CMSPageStore) Unpublish(ctx context.Context, ids []string) ([]map[string]any, error)

Unpublish marks matching pages as drafts.

func (*CMSPageStore) Update

func (s *CMSPageStore) Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)

Update modifies an existing page.

func (*CMSPageStore) WithActivitySink

func (s *CMSPageStore) WithActivitySink(sink admin.ActivitySink)

WithActivitySink wires an activity sink for CRUD events.

type CMSPostStore

type CMSPostStore struct {
	// contains filtered or unexported fields
}

CMSPostStore adapts go-cms content to the post store contract.

func NewCMSPostStore

func NewCMSPostStore(content admin.CMSContentService, defaultLocale string) *CMSPostStore

NewCMSPostStore builds a content-backed post store. Returns nil when no content service is provided.

func (*CMSPostStore) Archive

func (s *CMSPostStore) Archive(ctx context.Context, ids []string) ([]map[string]any, error)

Archive marks matching posts as archived.

func (*CMSPostStore) Create

func (s *CMSPostStore) Create(ctx context.Context, record map[string]any) (map[string]any, error)

Create inserts a post into the CMS backend.

func (*CMSPostStore) Delete

func (s *CMSPostStore) Delete(ctx context.Context, id string) error

Delete removes a post.

func (*CMSPostStore) Get

func (s *CMSPostStore) Get(ctx context.Context, id string) (map[string]any, error)

Get returns a post by id.

func (*CMSPostStore) List

func (s *CMSPostStore) List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)

List returns CMS posts filtered by content_type, locale, and search.

func (*CMSPostStore) Publish

func (s *CMSPostStore) Publish(ctx context.Context, ids []string) ([]map[string]any, error)

Publish marks matching posts as published and stamps published_at.

func (*CMSPostStore) Schedule

func (s *CMSPostStore) Schedule(ctx context.Context, ids []string, publishAt time.Time) ([]map[string]any, error)

Schedule marks matching posts as scheduled with a publish time (defaults to now when missing).

func (*CMSPostStore) Seed

func (s *CMSPostStore) Seed()

Seed inserts sample posts when the CMS backend is empty.

func (*CMSPostStore) Unpublish

func (s *CMSPostStore) Unpublish(ctx context.Context, ids []string) ([]map[string]any, error)

Unpublish marks matching posts as drafts and clears publish time.

func (*CMSPostStore) Update

func (s *CMSPostStore) Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)

Update modifies an existing post.

func (*CMSPostStore) WithActivitySink

func (s *CMSPostStore) WithActivitySink(sink admin.ActivitySink)

WithActivitySink wires an activity sink for CRUD events.

type DataStores

type DataStores struct {
	Users        *UserStore
	UserProfiles *UserProfileStore
	Pages        PageRepository
	Posts        PostRepository
	Templates    *TemplateStore
	Media        *MediaStore
	Stats        *StatsStore
	PageRecords  repository.Repository[*PageRecord]
	PostRecords  repository.Repository[*PostRecord]
	MediaRecords repository.Repository[*MediaRecord]
}

DataStores holds all in-memory or CMS-backed data stores.

func Initialize

func Initialize(contentSvc admin.CMSContentService, defaultLocale string, userDeps UserDependencies, repoOptions ...repository.Option) (*DataStores, error)

Initialize creates all data stores backed by the CMS content service (pages/posts) and Bun for user/media data.

func InitializeWithOptions added in v0.15.0

func InitializeWithOptions(contentSvc admin.CMSContentService, defaultLocale string, userDeps UserDependencies, opts InitOptions) (*DataStores, error)

InitializeWithOptions creates data stores with persistence options applied.

type InitOptions added in v0.15.0

type InitOptions struct {
	RepoOptions        []repository.Option
	PersistenceOptions []persistence.ClientOption
}

InitOptions configures initialization for data stores.

type MediaRecord

type MediaRecord struct {
	bun.BaseModel `bun:"table:media,alias:m" crud:"resource:media"`

	ID         uuid.UUID      `json:"id" bun:"id,pk,type:uuid"`
	Filename   string         `json:"filename" bun:"filename"`
	URL        string         `json:"url" bun:"url"`
	Type       string         `json:"type" bun:"type"`
	MimeType   string         `json:"mime_type,omitempty" bun:"mime_type"`
	Size       int64          `json:"size" bun:"size"`
	Metadata   map[string]any `json:"metadata,omitempty" bun:"metadata,type:jsonb"`
	UploadedBy string         `json:"uploaded_by,omitempty" bun:"uploaded_by"`
	CreatedAt  *time.Time     `json:"created_at,omitempty" bun:"created_at,nullzero,default:current_timestamp"`
	UpdatedAt  *time.Time     `json:"updated_at,omitempty" bun:"updated_at,nullzero,default:current_timestamp"`
}

MediaRecord represents media assets in go-crud responses.

type MediaStore

type MediaStore struct {
	// contains filtered or unexported fields
}

MediaStore manages media files backed by SQLite/Bun.

func NewMediaStore

func NewMediaStore(db *bun.DB, opts ...repository.Option) (*MediaStore, error)

NewMediaStore creates a new MediaStore instance.

func (*MediaStore) Create

func (s *MediaStore) Create(ctx context.Context, record map[string]any) (map[string]any, error)

Create creates a new media file.

func (*MediaStore) Delete

func (s *MediaStore) Delete(ctx context.Context, id string) error

Delete deletes a media file by ID.

func (*MediaStore) DeleteMany

func (s *MediaStore) DeleteMany(ctx context.Context, ids []string) ([]map[string]any, error)

DeleteMany removes multiple media files in one pass.

func (*MediaStore) Get

func (s *MediaStore) Get(ctx context.Context, id string) (map[string]any, error)

Get returns a single media file by ID.

func (*MediaStore) List

func (s *MediaStore) List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)

List returns a list of media files matching the given options.

func (*MediaStore) Repository

func (s *MediaStore) Repository() repository.Repository[*MediaRecord]

Repository exposes the underlying go-repository-bun repository.

func (*MediaStore) Seed

func (s *MediaStore) Seed()

Seed populates the MediaStore with initial data when empty.

func (*MediaStore) Update

func (s *MediaStore) Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)

Update updates an existing media file.

func (*MediaStore) WithActivitySink

func (s *MediaStore) WithActivitySink(sink admin.ActivitySink)

WithActivitySink enables activity emission on CRUD operations.

type PageRecord

type PageRecord struct {
	bun.BaseModel `bun:"table:admin_page_records,alias:pr" crud:"resource:page"`

	ID                 uuid.UUID  `json:"id" bun:"id,pk,type:uuid"`
	ContentID          uuid.UUID  `json:"content_id" bun:"content_id,type:uuid"`
	TranslationGroupID *uuid.UUID `json:"translation_group_id,omitempty" bun:"translation_group_id,type:uuid"`
	TemplateID         uuid.UUID  `json:"template_id" bun:"template_id,type:uuid"`
	Title              string     `json:"title" bun:"title"`
	Slug               string     `json:"slug" bun:"slug"`
	Path               string     `json:"path" bun:"path"`
	Locale             string     `json:"locale" bun:"locale"`
	PrimaryLocale      string     `json:"primary_locale,omitempty" bun:"primary_locale"`
	AvailableLocales   string     `json:"available_locales,omitempty" bun:"available_locales"`
	Status             string     `json:"status" bun:"status"`
	ParentID           *uuid.UUID `json:"parent_id,omitempty" bun:"parent_id"`
	MetaTitle          string     `json:"meta_title,omitempty" bun:"meta_title"`
	MetaDescription    string     `json:"meta_description,omitempty" bun:"meta_description"`
	Summary            *string    `json:"summary,omitempty" bun:"summary"`
	Content            string     `json:"content,omitempty" bun:"content"`
	Tags               []string   `json:"tags,omitempty" bun:"tags,type:jsonb"`
	Blocks             any        `json:"blocks,omitempty" bun:"-"`
	PreviewURL         string     `json:"preview_url,omitempty" bun:"preview_url"`
	PublishedAt        *time.Time `json:"published_at,omitempty" bun:"published_at,nullzero"`
	CreatedAt          *time.Time `json:"created_at,omitempty" bun:"created_at,nullzero,default:current_timestamp"`
	UpdatedAt          *time.Time `json:"updated_at,omitempty" bun:"updated_at,nullzero,default:current_timestamp"`
}

PageRecord maps CMS-backed page records used by admin content tooling.

func PageRecordFromMap added in v0.24.0

func PageRecordFromMap(record map[string]any) *PageRecord

type PageRepository

type PageRepository interface {
	Seed()
	WithActivitySink(admin.ActivitySink)
	List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)
	Get(ctx context.Context, id string) (map[string]any, error)
	Create(ctx context.Context, record map[string]any) (map[string]any, error)
	Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)
	Delete(ctx context.Context, id string) error
	Publish(ctx context.Context, ids []string) ([]map[string]any, error)
	Unpublish(ctx context.Context, ids []string) ([]map[string]any, error)
}

PageRepository represents the operations needed by panels, search, and commands.

type PageStore

type PageStore struct {
	// contains filtered or unexported fields
}

PageStore manages pages backed by SQLite/Bun.

func NewPageStore

func NewPageStore(db *bun.DB, opts ...repository.Option) (*PageStore, error)

NewPageStore creates a new page store.

func (*PageStore) Create

func (s *PageStore) Create(ctx context.Context, record map[string]any) (map[string]any, error)

Create creates a new page.

func (*PageStore) Delete

func (s *PageStore) Delete(ctx context.Context, id string) error

Delete deletes a page by ID.

func (*PageStore) Get

func (s *PageStore) Get(ctx context.Context, id string) (map[string]any, error)

Get returns a single page by ID.

func (*PageStore) List

func (s *PageStore) List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)

List returns a list of pages matching the given options.

func (*PageStore) Publish

func (s *PageStore) Publish(ctx context.Context, ids []string) ([]map[string]any, error)

Publish sets the status to published for matching pages (or all when ids are empty).

func (*PageStore) Repository

func (s *PageStore) Repository() repository.Repository[*PageRecord]

Repository exposes the underlying go-repository-bun repository.

func (*PageStore) Seed

func (s *PageStore) Seed()

Seed populates the store with sample data when empty.

func (*PageStore) Unpublish

func (s *PageStore) Unpublish(ctx context.Context, ids []string) ([]map[string]any, error)

Unpublish marks matching pages as drafts.

func (*PageStore) Update

func (s *PageStore) Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)

Update updates an existing page.

func (*PageStore) WithActivitySink

func (s *PageStore) WithActivitySink(sink admin.ActivitySink)

WithActivitySink enables activity emission on CRUD operations.

type PostRecord

type PostRecord struct {
	bun.BaseModel `bun:"table:admin_post_records,alias:apr" crud:"resource:post"`

	ID                 uuid.UUID  `json:"id" bun:"id,pk,type:uuid"`
	Title              string     `json:"title" bun:"title"`
	Slug               string     `json:"slug" bun:"slug"`
	Status             string     `json:"status" bun:"status"`
	Locale             string     `json:"locale" bun:"locale"`
	TranslationGroupID *uuid.UUID `json:"translation_group_id,omitempty" bun:"translation_group_id,type:uuid"`
	PrimaryLocale      string     `json:"primary_locale,omitempty" bun:"primary_locale"`
	AvailableLocales   string     `json:"available_locales,omitempty" bun:"available_locales"`
	Path               string     `json:"path" bun:"path"`
	Author             string     `json:"author,omitempty" bun:"author"`
	Excerpt            string     `json:"excerpt,omitempty" bun:"excerpt"`
	Content            string     `json:"content,omitempty" bun:"content"`
	Category           string     `json:"category,omitempty" bun:"category"`
	FeaturedImage      string     `json:"featured_image,omitempty" bun:"featured_image"`
	Tags               []string   `json:"tags,omitempty" bun:"tags,type:jsonb"`
	MetaTitle          string     `json:"meta_title,omitempty" bun:"meta_title"`
	MetaDescription    string     `json:"meta_description,omitempty" bun:"meta_description"`
	PublishedAt        *time.Time `json:"published_at,omitempty" bun:"published_at,nullzero"`
	CreatedAt          *time.Time `json:"created_at,omitempty" bun:"created_at,nullzero,default:current_timestamp"`
	UpdatedAt          *time.Time `json:"updated_at,omitempty" bun:"updated_at,nullzero,default:current_timestamp"`
}

PostRecord represents posts used by admin content tooling.

type PostRepository

type PostRepository interface {
	Seed()
	WithActivitySink(admin.ActivitySink)
	List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)
	Get(ctx context.Context, id string) (map[string]any, error)
	Create(ctx context.Context, record map[string]any) (map[string]any, error)
	Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)
	Delete(ctx context.Context, id string) error
	Publish(ctx context.Context, ids []string) ([]map[string]any, error)
	Unpublish(ctx context.Context, ids []string) ([]map[string]any, error)
	Schedule(ctx context.Context, ids []string, publishAt time.Time) ([]map[string]any, error)
	Archive(ctx context.Context, ids []string) ([]map[string]any, error)
}

PostRepository captures blog post operations plus publish/archive actions.

type PostStore

type PostStore struct {
	// contains filtered or unexported fields
}

PostStore manages blog posts backed by SQLite/Bun.

func NewPostStore

func NewPostStore(db *bun.DB, opts ...repository.Option) (*PostStore, error)

NewPostStore creates a new PostStore instance.

func (*PostStore) Archive

func (s *PostStore) Archive(ctx context.Context, ids []string) ([]map[string]any, error)

Archive marks matching posts as archived.

func (*PostStore) Create

func (s *PostStore) Create(ctx context.Context, record map[string]any) (map[string]any, error)

Create creates a new post.

func (*PostStore) Delete

func (s *PostStore) Delete(ctx context.Context, id string) error

Delete deletes a post by ID.

func (*PostStore) Get

func (s *PostStore) Get(ctx context.Context, id string) (map[string]any, error)

Get returns a single post by ID.

func (*PostStore) List

func (s *PostStore) List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)

List returns a list of posts matching the given options.

func (*PostStore) Publish

func (s *PostStore) Publish(ctx context.Context, ids []string) ([]map[string]any, error)

Publish sets matching posts to published and stamps published_at when missing.

func (*PostStore) Repository

func (s *PostStore) Repository() repository.Repository[*PostRecord]

Repository exposes the underlying go-repository-bun repository.

func (*PostStore) Schedule

func (s *PostStore) Schedule(ctx context.Context, ids []string, publishAt time.Time) ([]map[string]any, error)

Schedule sets posts to scheduled with a publish time (defaults to now when empty).

func (*PostStore) Seed

func (s *PostStore) Seed()

Seed populates the PostStore with initial data when empty.

func (*PostStore) Unpublish

func (s *PostStore) Unpublish(ctx context.Context, ids []string) ([]map[string]any, error)

Unpublish marks matching posts as drafts and clears publish time.

func (*PostStore) Update

func (s *PostStore) Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)

Update updates an existing post.

func (*PostStore) WithActivitySink

func (s *PostStore) WithActivitySink(sink admin.ActivitySink)

WithActivitySink enables activity emission on CRUD operations.

type StatsStore

type StatsStore struct {
	// contains filtered or unexported fields
}

StatsStore manages statistics

func NewStatsStore

func NewStatsStore() *StatsStore

NewStatsStore creates a new StatsStore instance

func (*StatsStore) GetContentStats

func (s *StatsStore) GetContentStats() map[string]any

GetContentStats returns content statistics

func (*StatsStore) GetStorageStats

func (s *StatsStore) GetStorageStats() map[string]any

GetStorageStats returns storage statistics

func (*StatsStore) GetUserStats

func (s *StatsStore) GetUserStats() map[string]any

GetUserStats returns user statistics

func (*StatsStore) Seed

func (s *StatsStore) Seed()

Seed initializes the StatsStore (stats are computed dynamically)

type TemplateOption added in v0.24.0

type TemplateOption struct {
	ID           string `json:"id"`
	Label        string `json:"label"`
	Name         string `json:"name,omitempty"`
	Slug         string `json:"slug,omitempty"`
	TemplatePath string `json:"template_path,omitempty"`
}

TemplateOption is a minimal payload for relationship selectors.

type TemplateStore added in v0.24.0

type TemplateStore struct {
	// contains filtered or unexported fields
}

TemplateStore provides read access to CMS templates for relationship selectors.

func NewTemplateStore added in v0.24.0

func NewTemplateStore(db *bun.DB) *TemplateStore

NewTemplateStore returns a store backed by the CMS content database.

func (*TemplateStore) List added in v0.24.0

func (s *TemplateStore) List(ctx context.Context, query string, ids []string, limit int) ([]TemplateOption, error)

List returns templates filtered by optional ids or query.

type User

type User struct {
	bun.BaseModel   `bun:"table:users,alias:u"`
	ID              uuid.UUID `json:"id" bun:"id,pk,type:uuid"`
	Username        string    `json:"username" bun:"username"`
	Email           string    `json:"email" bun:"email"`
	Label           string    `json:"label" bun:"-"`
	FirstName       string    `json:"first_name" bun:"first_name"`
	LastName        string    `json:"last_name" bun:"last_name"`
	PhoneNumber     string    `json:"phone_number" bun:"phone_number"`
	IsEmailVerified bool      `json:"is_email_verified" bun:"is_email_verified"`
	Role            string    `json:"role" bun:"role"`
	Status          string    `json:"status" bun:"status"`
	CreatedAt       time.Time `json:"created_at" bun:"created_at"`
	UpdatedAt       time.Time `json:"updated_at" bun:"updated_at"`
	LastLogin       time.Time `json:"last_login" bun:"last_login"`
}

User mirrors the JSON shape expected by go-crud.

type UserDependencies

type UserDependencies struct {
	DB             *bun.DB
	RepoManager    auth.RepositoryManager
	AuthRepo       types.AuthRepository
	InventoryRepo  types.UserInventoryRepository
	RoleRegistry   types.RoleRegistry
	ActivitySink   types.ActivitySink
	ActivityRepo   types.ActivityRepository
	ProfileRepo    types.ProfileRepository
	PreferenceRepo types.PreferenceRepository
	SecureLinks    types.SecureLinkManager
	UserTokenRepo  types.UserTokenRepository
	ResetRepo      types.PasswordResetRepository
}

UserDependencies wires DB-backed user storage and related services.

type UserProfile

type UserProfile struct {
	bun.BaseModel `bun:"table:user_profiles,alias:up"`

	ID          uuid.UUID `json:"id" bun:"user_id,pk,type:uuid"`
	DisplayName string    `json:"display_name" bun:"display_name"`
	AvatarURL   string    `json:"avatar_url" bun:"avatar_url"`
	Email       string    `json:"email" bun:"email"`
	Locale      string    `json:"locale" bun:"locale"`
	Timezone    string    `json:"timezone" bun:"timezone"`
	Bio         string    `json:"bio" bun:"bio"`
	CreatedAt   time.Time `json:"created_at" bun:"created_at"`
	UpdatedAt   time.Time `json:"updated_at" bun:"updated_at"`
}

UserProfile mirrors the JSON shape expected by go-crud/DataGrid. Note: bun tags are used by go-crud query parsing; the store does not rely on Bun scans for this model.

type UserProfileStore

type UserProfileStore struct {
	// contains filtered or unexported fields
}

UserProfileStore manages profile data through the go-users profile repository.

func NewUserProfileStore

func NewUserProfileStore(deps UserDependencies) (*UserProfileStore, error)

NewUserProfileStore provisions a DB-backed profile store for the example.

func (*UserProfileStore) Create

func (s *UserProfileStore) Create(ctx context.Context, record map[string]any) (map[string]any, error)

Create adds a new profile (keyed by the user id).

func (*UserProfileStore) Delete

func (s *UserProfileStore) Delete(ctx context.Context, id string) error

Delete removes a profile by user id.

func (*UserProfileStore) Get

func (s *UserProfileStore) Get(ctx context.Context, id string) (map[string]any, error)

Get returns a single profile by user id (record id).

func (*UserProfileStore) List

func (s *UserProfileStore) List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)

List returns user profiles honoring search/filters/pagination.

func (*UserProfileStore) Repository

Repository exposes a go-crud compatible repository adapter.

func (*UserProfileStore) Update

func (s *UserProfileStore) Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)

Update modifies an existing profile (user id is immutable).

type UserStore

type UserStore struct {
	// contains filtered or unexported fields
}

UserStore manages user data through a go-users-compatible repository.

func NewUserStore

func NewUserStore(deps UserDependencies) (*UserStore, error)

NewUserStore provisions a DB-backed go-users repository for the example.

func (*UserStore) Create

func (s *UserStore) Create(ctx context.Context, record map[string]any) (map[string]any, error)

Create adds a new user.

func (*UserStore) Delete

func (s *UserStore) Delete(ctx context.Context, id string) error

Delete removes a user.

func (*UserStore) Get

func (s *UserStore) Get(ctx context.Context, id string) (map[string]any, error)

Get returns a single user by ID.

func (*UserStore) List

func (s *UserStore) List(ctx context.Context, opts admin.ListOptions) ([]map[string]any, int, error)

List returns users honoring search/filters/pagination.

func (*UserStore) Repository

func (s *UserStore) Repository() repository.Repository[*User]

Repository exposes a go-crud compatible repository adapter.

func (*UserStore) Seed

func (s *UserStore) Seed()

Seed populates the store with sample data.

func (*UserStore) Teardown

func (s *UserStore) Teardown()

Teardown clears all user records (used by tests/fixtures).

func (*UserStore) Update

func (s *UserStore) Update(ctx context.Context, id string, record map[string]any) (map[string]any, error)

Update modifies an existing user.

func (*UserStore) WithActivitySink

func (s *UserStore) WithActivitySink(sink admin.ActivitySink)

WithActivitySink enables activity emission on create/update/delete operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL