postgresql

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyRepository

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

APIKeyRepository persists API keys using PostgreSQL syntax. Implements apikey.Repository.

func NewAPIKeyRepository

func NewAPIKeyRepository(db *sql.DB) *APIKeyRepository

NewAPIKeyRepository creates a new PostgreSQL API key repository.

func (*APIKeyRepository) CountByUserAndName

func (r *APIKeyRepository) CountByUserAndName(ctx context.Context, userID int, name string) (int, error)

CountByUserAndName returns the number of non-revoked keys for a user with the given name. Used by the domain service to prevent duplicate key names.

func (*APIKeyRepository) Create

func (r *APIKeyRepository) Create(ctx context.Context, key *apikey.APIKey) error

Create inserts a new API key record and populates key.ID via RETURNING id.

func (*APIKeyRepository) FindByIDAndUserID

func (r *APIKeyRepository) FindByIDAndUserID(ctx context.Context, id, userID int) (*apikey.APIKey, error)

FindByIDAndUserID returns the single key matching (id, userID), or apikey.ErrKeyNotFound when no such row exists (covers nonexistent AND not-owned — identity scoping is enforced by the WHERE user_id predicate).

func (*APIKeyRepository) FindByKeyID

func (r *APIKeyRepository) FindByKeyID(ctx context.Context, keyID string) (*apikey.APIKey, error)

FindByKeyID returns the key matching the public lookup prefix keyID, INCLUDING revoked and expired rows, or apikey.ErrKeyNotFound if none. The deliberate absence of a revoked_at IS NULL filter lets the Service distinguish a verified-but-revoked key from an unknown keyID.

func (*APIKeyRepository) ListByUserID

func (r *APIKeyRepository) ListByUserID(ctx context.Context, userID int) ([]*apikey.APIKey, error)

ListByUserID returns all API keys owned by userID, newest-first. Returns an empty (non-nil) slice when the user has no keys.

func (*APIKeyRepository) RevokeByIDAndUserID

func (r *APIKeyRepository) RevokeByIDAndUserID(ctx context.Context, id, userID int, now time.Time) error

RevokeByIDAndUserID sets revoked_at = now for the matching (id, userID) row. No rows-affected check is performed — the Service guards via FindByIDAndUserID first.

func (*APIKeyRepository) UpdateLastUsed

func (r *APIKeyRepository) UpdateLastUsed(ctx context.Context, id int, now time.Time, ip string) error

UpdateLastUsed sets last_used_at = now and last_used_ip = ip for the key id. Best-effort: no rows-affected check (the key was just verified to exist).

type BlockedEmail

type BlockedEmail struct {
	ID        int
	Email     string
	CreatedAt time.Time
	Reason    string
}

BlockedEmail represents a blocked email entry

type BlockedEmailRepository

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

BlockedEmailRepository handles blocked email data operations

func NewBlockedEmailRepository

func NewBlockedEmailRepository(db *sql.DB) *BlockedEmailRepository

NewBlockedEmailRepository creates a new blocked email repository

func (*BlockedEmailRepository) BlockEmail

func (r *BlockedEmailRepository) BlockEmail(ctx context.Context, email string, reason string) error

BlockEmail adds an email to the blocked list

func (*BlockedEmailRepository) IsEmailBlocked

func (r *BlockedEmailRepository) IsEmailBlocked(ctx context.Context, email string) (bool, error)

IsEmailBlocked checks if an email is in the blocked list

func (*BlockedEmailRepository) UnblockEmail

func (r *BlockedEmailRepository) UnblockEmail(ctx context.Context, email string) error

UnblockEmail removes an email from the blocked list

type ContentItem

type ContentItem struct {
	ID                 int           `json:"id"`
	UserID             int           `json:"userId"`
	Title              string        `json:"title"`
	Slug               string        `json:"slug"`
	Content            string        `json:"content"`
	Tags               string        `json:"tags"`
	Status             string        `json:"status"`
	Format             string        `json:"format"`
	PostType           string        `json:"postType"`
	MetaDescription    *string       `json:"metaDescription"`
	OGTitle            *string       `json:"ogTitle"`
	OGDescription      *string       `json:"ogDescription"`
	FeaturedImage      *string       `json:"featuredImage"`
	AllowComments      bool          `json:"allowComments"`
	CustomFields       *string       `json:"customFields"`
	Language           string        `json:"language"`
	TranslationGroupID sql.NullInt64 `json:"translationGroupId"`
	CreatedAt          time.Time     `json:"createdAt"`
	UpdatedAt          time.Time     `json:"updatedAt"`
}

ContentItem represents a content item in the database

type ContentRepository

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

ContentRepository handles content data operations

func NewContentRepository

func NewContentRepository(db *sql.DB) *ContentRepository

NewContentRepository creates a new content repository

func (*ContentRepository) AuthorExists

func (r *ContentRepository) AuthorExists(ctx context.Context, username string) (bool, error)

func (*ContentRepository) CheckSlugUnique

func (r *ContentRepository) CheckSlugUnique(ctx context.Context, slug string, language string) (bool, error)

func (*ContentRepository) Count added in v0.8.0

func (r *ContentRepository) Count(ctx context.Context, userID int, filters contentdomain.ContentFilters) (int, error)

Count returns the number of content items matching the filters, using the same WHERE clause as ListByFilters (see buildContentFilterWhereClause). userID <= 0 counts across all users.

func (*ContentRepository) Create

func (r *ContentRepository) Create(ctx context.Context, content *contentdomain.Content) error

func (*ContentRepository) Delete

func (r *ContentRepository) Delete(ctx context.Context, id int, userID int) error

func (*ContentRepository) DeleteByID

func (r *ContentRepository) DeleteByID(ctx context.Context, id int) error

func (*ContentRepository) GetAll

func (r *ContentRepository) GetAll(ctx context.Context, limit int, offset int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetByID

func (*ContentRepository) GetBySlug

func (r *ContentRepository) GetBySlug(ctx context.Context, slug string, language string) (*contentdomain.Content, error)

func (*ContentRepository) GetByUser

func (r *ContentRepository) GetByUser(ctx context.Context, userID int, limit int, offset int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetLatestByPostType added in v0.4.0

func (r *ContentRepository) GetLatestByPostType(ctx context.Context, excludeID int, postType string, language string, limit int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetPublished

func (r *ContentRepository) GetPublished(ctx context.Context, limit int, offset int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetPublishedArchive added in v0.6.0

func (r *ContentRepository) GetPublishedArchive(ctx context.Context, postType string, languages []string) ([]*contentdomain.ArchiveMonth, error)

func (*ContentRepository) GetPublishedAuthor added in v0.7.0

func (r *ContentRepository) GetPublishedAuthor(ctx context.Context, username string) (*contentdomain.PublishedAuthor, error)

func (*ContentRepository) GetPublishedAuthors added in v0.5.0

func (*ContentRepository) GetPublishedByAuthorUsername

func (r *ContentRepository) GetPublishedByAuthorUsername(ctx context.Context, username string, languages []string, limit int, offset int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetPublishedByPostType

func (r *ContentRepository) GetPublishedByPostType(ctx context.Context, postType string, languages []string, year int, month int, limit int, offset int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetPublishedBySlug

func (r *ContentRepository) GetPublishedBySlug(ctx context.Context, slug string, language string) (*contentdomain.Content, error)

func (*ContentRepository) GetPublishedBySlugAny

func (r *ContentRepository) GetPublishedBySlugAny(ctx context.Context, slug string) (*contentdomain.Content, error)

func (*ContentRepository) GetPublishedByTag

func (r *ContentRepository) GetPublishedByTag(ctx context.Context, tag string, languages []string, year int, month int, limit int, offset int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetPublishedCustomPostTypes

func (r *ContentRepository) GetPublishedCustomPostTypes(ctx context.Context) ([]string, error)

func (*ContentRepository) GetPublishedPages

func (r *ContentRepository) GetPublishedPages(ctx context.Context) ([]*contentdomain.Content, error)

func (*ContentRepository) GetPublishedTags added in v0.5.0

func (r *ContentRepository) GetPublishedTags(ctx context.Context) ([]string, error)

func (*ContentRepository) GetRelatedByTags added in v0.4.0

func (r *ContentRepository) GetRelatedByTags(ctx context.Context, excludeID int, tags []string, postType string, language string, limit int) ([]*contentdomain.Content, error)

func (*ContentRepository) GetTranslations

func (r *ContentRepository) GetTranslations(ctx context.Context, translationGroupID int, excludeID int) ([]*contentdomain.Content, error)

func (*ContentRepository) ListByCursor

func (r *ContentRepository) ListByCursor(ctx context.Context, userID int, limit int, beforeID int, filters contentdomain.ContentFilters) ([]*contentdomain.Content, error)

func (*ContentRepository) ListByFilters

func (r *ContentRepository) ListByFilters(ctx context.Context, userID int, filters contentdomain.ContentFilters) ([]*contentdomain.Content, error)

func (*ContentRepository) SearchPublished

func (r *ContentRepository) SearchPublished(ctx context.Context, query string, postTypes []string, limit int) ([]*contentdomain.Content, error)

func (*ContentRepository) TranslationGroupExists

func (r *ContentRepository) TranslationGroupExists(ctx context.Context, id int) (bool, error)

func (*ContentRepository) Update

func (r *ContentRepository) Update(ctx context.Context, content *contentdomain.Content) error

type DashboardRepository

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

DashboardRepository handles dashboard data operations

func NewDashboardRepository

func NewDashboardRepository(db *sql.DB) *DashboardRepository

NewDashboardRepository creates a new dashboard repository

func (*DashboardRepository) GetStats

func (r *DashboardRepository) GetStats(ctx context.Context, userID int) (*dashboard.Stats, error)

GetStats retrieves aggregated statistics for the dashboard. userID <= 0 means "all users" (admin scope) and yields unfiltered content/media counts.

type EmailUpdateToken

type EmailUpdateToken = userdomain.EmailUpdateToken

type EmailUpdateTokenRepository

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

EmailUpdateTokenRepository handles email update token data operations

func NewEmailUpdateTokenRepository

func NewEmailUpdateTokenRepository(db *sql.DB) *EmailUpdateTokenRepository

NewEmailUpdateTokenRepository creates a new email update token repository

func (*EmailUpdateTokenRepository) CleanUpExpiredTokens

func (r *EmailUpdateTokenRepository) CleanUpExpiredTokens(ctx context.Context) error

CleanUpExpiredTokens deletes all expired email update tokens

func (*EmailUpdateTokenRepository) CreateToken

func (r *EmailUpdateTokenRepository) CreateToken(ctx context.Context, token string, userID int, newEmail string) error

CreateToken creates a new email update token

func (*EmailUpdateTokenRepository) DeleteToken

func (r *EmailUpdateTokenRepository) DeleteToken(ctx context.Context, tokenID int) error

DeleteToken deletes an email update token by ID

func (*EmailUpdateTokenRepository) GetToken

GetToken retrieves an email update token by token value

type FailedLoginAttempt

type FailedLoginAttempt = authdomain.FailedLoginAttempt

FailedLoginAttempt is a type alias for authdomain.FailedLoginAttempt.

type FailedLoginAttemptRepository

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

FailedLoginAttemptRepository handles failed login attempt data operations with PostgreSQL syntax. Implements repository.FailedLoginAttemptRepo.

func NewFailedLoginAttemptRepository

func NewFailedLoginAttemptRepository(db *sql.DB) *FailedLoginAttemptRepository

NewFailedLoginAttemptRepository creates a new failed login attempt repository.

func (*FailedLoginAttemptRepository) Create

Create creates a new failed login attempt record.

func (*FailedLoginAttemptRepository) Delete

func (r *FailedLoginAttemptRepository) Delete(ctx context.Context, userID int) error

Delete removes the failed login attempt record for a user.

func (*FailedLoginAttemptRepository) GetByUserID

func (r *FailedLoginAttemptRepository) GetByUserID(ctx context.Context, userID int) (*FailedLoginAttempt, error)

GetByUserID retrieves failed login attempt record by user ID.

func (*FailedLoginAttemptRepository) IncrementAttempts

func (r *FailedLoginAttemptRepository) IncrementAttempts(ctx context.Context, userID int) error

IncrementAttempts increments the failed attempt counter for a user.

func (*FailedLoginAttemptRepository) IsLocked

func (r *FailedLoginAttemptRepository) IsLocked(ctx context.Context, userID int) (bool, *time.Time, error)

IsLocked checks if a user account is currently locked.

func (*FailedLoginAttemptRepository) LockAccount

func (r *FailedLoginAttemptRepository) LockAccount(ctx context.Context, userID int, lockoutDuration time.Duration) error

LockAccount locks an account for a specified duration.

func (*FailedLoginAttemptRepository) ResetAttempts

func (r *FailedLoginAttemptRepository) ResetAttempts(ctx context.Context, userID int) error

ResetAttempts resets the failed attempt counter for a user.

func (*FailedLoginAttemptRepository) ShouldSendLockoutEmail

func (r *FailedLoginAttemptRepository) ShouldSendLockoutEmail(ctx context.Context, userID int, minInterval time.Duration) (bool, error)

ShouldSendLockoutEmail checks if enough time has passed since the last email was sent.

func (*FailedLoginAttemptRepository) UpdateLastEmailSent

func (r *FailedLoginAttemptRepository) UpdateLastEmailSent(ctx context.Context, userID int) error

UpdateLastEmailSent updates the timestamp when the last lockout email was sent.

type MFAChallengeRepository added in v1.1.0

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

MFAChallengeRepository handles login MFA challenge data operations.

func NewMFAChallengeRepository added in v1.1.0

func NewMFAChallengeRepository(db *sql.DB) *MFAChallengeRepository

NewMFAChallengeRepository creates a new login MFA challenge repository.

func (*MFAChallengeRepository) Consume added in v1.1.0

func (r *MFAChallengeRepository) Consume(ctx context.Context, id int) (bool, error)

Consume deletes the challenge and reports whether this caller removed it.

func (*MFAChallengeRepository) Create added in v1.1.0

Create stores a new login challenge.

func (*MFAChallengeRepository) Delete added in v1.1.0

func (r *MFAChallengeRepository) Delete(ctx context.Context, id int) error

Delete removes one challenge.

func (*MFAChallengeRepository) DeleteExpired added in v1.1.0

func (r *MFAChallengeRepository) DeleteExpired(ctx context.Context) error

DeleteExpired removes expired challenges. The cutoff is bound as a time.Time so it matches the driver's stored timestamp zone.

func (*MFAChallengeRepository) DeleteUserChallenges added in v1.1.0

func (r *MFAChallengeRepository) DeleteUserChallenges(ctx context.Context, userID int) error

DeleteUserChallenges removes every challenge for a user.

func (*MFAChallengeRepository) FindByTokenHash added in v1.1.0

func (r *MFAChallengeRepository) FindByTokenHash(ctx context.Context, tokenHash string) (*authdomain.MFAChallenge, error)

FindByTokenHash returns the challenge for a token hash, expired or not. The service owns expiry decisions so it can distinguish expired from unknown.

func (*MFAChallengeRepository) IncrementAttempts added in v1.1.0

func (r *MFAChallengeRepository) IncrementAttempts(ctx context.Context, id, maxAttempts int) (bool, error)

IncrementAttempts spends one attempt while the challenge is below the cap and reports whether the attempt was spent.

type PasswordResetToken

type PasswordResetToken = authdomain.PasswordResetToken

type PasswordResetTokenRepository

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

PasswordResetTokenRepository handles password reset token data operations

func NewPasswordResetTokenRepository

func NewPasswordResetTokenRepository(db *sql.DB) *PasswordResetTokenRepository

NewPasswordResetTokenRepository creates a new password reset token repository

func (*PasswordResetTokenRepository) CreateToken

CreateToken creates a new password reset token

func (*PasswordResetTokenRepository) DeleteUserTokens

func (r *PasswordResetTokenRepository) DeleteUserTokens(ctx context.Context, userID int) error

DeleteUserTokens deletes all tokens for a user

func (*PasswordResetTokenRepository) FindValidToken

func (r *PasswordResetTokenRepository) FindValidToken(ctx context.Context, tokenHash string) (*PasswordResetToken, error)

FindValidToken finds a valid (non-expired) password reset token by hash

type SoftDeleteRepository

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

SoftDeleteRepository handles soft delete data operations

func NewSoftDeleteRepository

func NewSoftDeleteRepository(db *sql.DB) *SoftDeleteRepository

NewSoftDeleteRepository creates a new soft delete repository

func (*SoftDeleteRepository) GetSoftDeletedContentByID

func (r *SoftDeleteRepository) GetSoftDeletedContentByID(ctx context.Context, id int) (*SoftDeletedContent, error)

GetSoftDeletedContentByID retrieves a soft deleted content item by its ID

func (*SoftDeleteRepository) GetSoftDeletedContentByUser

func (r *SoftDeleteRepository) GetSoftDeletedContentByUser(ctx context.Context, userID int) ([]*SoftDeletedContent, error)

GetSoftDeletedContentByUser retrieves all soft deleted content for a user

func (*SoftDeleteRepository) PermanentDeleteContent

func (r *SoftDeleteRepository) PermanentDeleteContent(ctx context.Context, contentType string, contentID int) error

PermanentDeleteContent permanently deletes content

func (*SoftDeleteRepository) RestoreContent

func (r *SoftDeleteRepository) RestoreContent(ctx context.Context, contentType string, contentID int) error

RestoreContent restores soft deleted content by removing it from the soft delete table

func (*SoftDeleteRepository) SoftDeleteContent

func (r *SoftDeleteRepository) SoftDeleteContent(ctx context.Context, contentType string, contentID int, userID int, deletedBy int, reason string) error

SoftDeleteContent marks content as deleted

type SoftDeletedContent

type SoftDeletedContent = repository.SoftDeletedContent

type User

type User = userdomain.User

User is a type alias for userdomain.User.

type UserCommentItem

type UserCommentItem = userdomain.UserCommentItem

type UserContentItem

type UserContentItem = userdomain.UserContentItem

type UserDataExport

type UserDataExport = userdomain.UserDataExport

type UserDataExportRepository

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

UserDataExportRepository handles user data export operations

func NewUserDataExportRepository

func NewUserDataExportRepository(db *sql.DB) *UserDataExportRepository

NewUserDataExportRepository creates a new user data export repository

func (*UserDataExportRepository) GetUserComments

func (r *UserDataExportRepository) GetUserComments(ctx context.Context, userID int) ([]*UserCommentItem, error)

GetUserComments retrieves all comments posted by a user

func (*UserDataExportRepository) GetUserContent

func (r *UserDataExportRepository) GetUserContent(ctx context.Context, userID int) ([]*UserContentItem, error)

GetUserContent retrieves all content items created by a user

func (*UserDataExportRepository) GetUserDataForExport

func (r *UserDataExportRepository) GetUserDataForExport(ctx context.Context, userID int) (*UserDataExport, error)

GetUserDataForExport aggregates all user data for export

func (*UserDataExportRepository) GetUserMedia

func (r *UserDataExportRepository) GetUserMedia(ctx context.Context, userID int) ([]*UserMediaItem, error)

GetUserMedia retrieves all media files uploaded by a user

type UserDeletionRepository

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

UserDeletionRepository handles user deletion data operations

func NewUserDeletionRepository

func NewUserDeletionRepository(db *sql.DB) *UserDeletionRepository

NewUserDeletionRepository creates a new user deletion repository

func (*UserDeletionRepository) CountUsersByRoleAndStatus

func (r *UserDeletionRepository) CountUsersByRoleAndStatus(ctx context.Context, role, status string) (int, error)

CountUsersByRoleAndStatus counts users by role and status

func (*UserDeletionRepository) DeleteAllUserData

func (r *UserDeletionRepository) DeleteAllUserData(ctx context.Context, userID int) error

DeleteAllUserData performs a hard delete of all user data within a single transaction

func (*UserDeletionRepository) DeleteUserAccount

func (r *UserDeletionRepository) DeleteUserAccount(ctx context.Context, userID int) error

DeleteUserAccount performs a hard delete of a user account

func (*UserDeletionRepository) DeleteUserComments

func (r *UserDeletionRepository) DeleteUserComments(ctx context.Context, userID int) error

DeleteUserComments deletes all comments posted by a user

func (*UserDeletionRepository) DeleteUserContent

func (r *UserDeletionRepository) DeleteUserContent(ctx context.Context, userID int) error

DeleteUserContent deletes all content created by a user

func (*UserDeletionRepository) DeleteUserMedia

func (r *UserDeletionRepository) DeleteUserMedia(ctx context.Context, userID int) error

DeleteUserMedia deletes all media files uploaded by a user

func (*UserDeletionRepository) DeleteUserTokens

func (r *UserDeletionRepository) DeleteUserTokens(ctx context.Context, userID int) error

DeleteUserTokens deletes all tokens associated with a user

type UserMediaItem

type UserMediaItem = userdomain.UserMediaItem

type UserRepository

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

UserRepository handles user data operations with PostgreSQL syntax. Implements repository.UserRepo.

func NewUserRepository

func NewUserRepository(db *sql.DB) *UserRepository

NewUserRepository creates a new user repository.

func (*UserRepository) CheckEmailExists

func (r *UserRepository) CheckEmailExists(ctx context.Context, email string) (bool, error)

CheckEmailExists checks if an email already exists (case-insensitive).

func (*UserRepository) CheckEmailExistsForOtherUser

func (r *UserRepository) CheckEmailExistsForOtherUser(ctx context.Context, userID int, email string) (bool, error)

CheckEmailExistsForOtherUser checks if an email is already in use by a different user

func (*UserRepository) CheckUsernameExists

func (r *UserRepository) CheckUsernameExists(ctx context.Context, username string) (bool, error)

CheckUsernameExists checks if a username already exists (case-insensitive).

func (*UserRepository) CountUsers added in v0.8.0

func (r *UserRepository) CountUsers(ctx context.Context, status string) (int, error)

CountUsers returns the total number of users, optionally filtered by status. It mirrors GetAllUsers' WHERE clause so a list's total always matches its rows.

func (*UserRepository) CreateUser

func (r *UserRepository) CreateUser(ctx context.Context, user *User) error

CreateUser creates a new user in the database.

func (*UserRepository) DeleteProfilePicture

func (r *UserRepository) DeleteProfilePicture(ctx context.Context, userID int) error

DeleteProfilePicture clears a user's profile picture column.

func (*UserRepository) DeleteUser

func (r *UserRepository) DeleteUser(ctx context.Context, userID int) error

DeleteUser deletes a user by ID.

func (*UserRepository) GetAdminUser

func (r *UserRepository) GetAdminUser(ctx context.Context) (*User, error)

GetAdminUser retrieves the admin user from the database.

func (*UserRepository) GetAllUsers

func (r *UserRepository) GetAllUsers(ctx context.Context, status string, limit int, offset int) ([]*User, error)

GetAllUsers retrieves all users with optional status filtering and pagination.

func (*UserRepository) GetPendingUsers

func (r *UserRepository) GetPendingUsers(ctx context.Context, limit int, offset int) ([]*User, error)

GetPendingUsers retrieves pending users with pagination.

func (*UserRepository) GetUserByEmail

func (r *UserRepository) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail retrieves a user by their email (case-insensitive).

func (*UserRepository) GetUserByID

func (r *UserRepository) GetUserByID(ctx context.Context, userID int) (*User, error)

GetUserByID retrieves a user by their ID.

func (*UserRepository) GetUserByUsername

func (r *UserRepository) GetUserByUsername(ctx context.Context, username string) (*User, error)

GetUserByUsername retrieves a user by their username (case-insensitive).

func (*UserRepository) GetUserStatus

func (r *UserRepository) GetUserStatus(ctx context.Context, userID int) (string, error)

GetUserStatus retrieves the current status of a user.

func (*UserRepository) RevokeSessions added in v1.1.0

func (r *UserRepository) RevokeSessions(ctx context.Context, userID int) error

RevokeSessions invalidates every session for a user by bumping the stored token version. The auth middleware rejects any token whose embedded version no longer matches, so previously issued Bearers and session cookies stop working on the next request.

func (*UserRepository) SetEmailVerified added in v0.10.0

func (r *UserRepository) SetEmailVerified(ctx context.Context, userID int, emailVerified bool) error

SetEmailVerified sets a user's email address verification state. It is separate from the user's status: in admin-approval mode a "pending" user may have an already-verified email while still awaiting admin activation, and changing a user's email address clears the flag until the new address is proven again.

func (*UserRepository) SoftDeleteUser

func (r *UserRepository) SoftDeleteUser(ctx context.Context, userID int) error

SoftDeleteUser soft-deletes a user.

func (*UserRepository) SuspendUser

func (r *UserRepository) SuspendUser(ctx context.Context, userID int) error

SuspendUser suspends a user.

func (*UserRepository) UnsuspendUser

func (r *UserRepository) UnsuspendUser(ctx context.Context, userID int) error

UnsuspendUser unsuspends a user.

func (*UserRepository) UpdateAdminPasswordAndEmail

func (r *UserRepository) UpdateAdminPasswordAndEmail(ctx context.Context, passwordHash, email, currentPasswordHash string) error

UpdateAdminPasswordAndEmail updates the admin user's password and email.

func (*UserRepository) UpdateCustomFields

func (r *UserRepository) UpdateCustomFields(
	ctx context.Context,
	userID int,
	customFields map[string]any,
) error

UpdateCustomFields updates only the custom_fields JSON column for a user

func (*UserRepository) UpdateEmail

func (r *UserRepository) UpdateEmail(ctx context.Context, userID int, email string) error

UpdateEmail updates a user's email address.

func (*UserRepository) UpdateLastLoginAt

func (r *UserRepository) UpdateLastLoginAt(ctx context.Context, userID int) error

UpdateLastLoginAt updates the last login timestamp for a user.

func (*UserRepository) UpdateName added in v0.2.0

func (r *UserRepository) UpdateName(ctx context.Context, userID int, name string) error

UpdateName updates a user's display name.

func (*UserRepository) UpdatePassword

func (r *UserRepository) UpdatePassword(ctx context.Context, userID int, currentPasswordHash, newPasswordHash string) error

UpdatePassword updates a user's password, validating the current password first.

func (*UserRepository) UpdatePasswordByUserID

func (r *UserRepository) UpdatePasswordByUserID(ctx context.Context, userID int, newPasswordHash string) error

UpdatePasswordByUserID updates a user's password by user ID (no current password check).

func (*UserRepository) UpdateProfile

func (r *UserRepository) UpdateProfile(
	ctx context.Context,
	userID int,
	name string,
	email string,
	role string,
	customFields map[string]any,
) error

UpdateProfile updates a user's profile fields (name, email, role, custom_fields)

func (*UserRepository) UpdateProfilePicture

func (r *UserRepository) UpdateProfilePicture(ctx context.Context, userID int, profilePicture string) error

UpdateProfilePicture updates a user's profile picture filename.

func (*UserRepository) UpdateUserStatus

func (r *UserRepository) UpdateUserStatus(ctx context.Context, userID int, status string) error

UpdateUserStatus updates a user's status.

func (*UserRepository) UpdateUserStatusIfCurrentStatus

func (r *UserRepository) UpdateUserStatusIfCurrentStatus(ctx context.Context, userID int, currentStatus string, newStatus string) error

UpdateUserStatusIfCurrentStatus updates a user's status only if it matches the expected current status.

type VerificationToken

type VerificationToken = authdomain.VerificationToken

type VerificationTokenRepository

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

VerificationTokenRepository handles verification token data operations

func NewVerificationTokenRepository

func NewVerificationTokenRepository(db *sql.DB) *VerificationTokenRepository

NewVerificationTokenRepository creates a new verification token repository

func (*VerificationTokenRepository) CreateToken

CreateToken creates a new verification token

func (*VerificationTokenRepository) DeleteExpiredTokens

func (r *VerificationTokenRepository) DeleteExpiredTokens(ctx context.Context) error

DeleteExpiredTokens deletes all expired tokens

func (*VerificationTokenRepository) DeleteUserTokens

func (r *VerificationTokenRepository) DeleteUserTokens(ctx context.Context, userID int) error

DeleteUserTokens deletes all tokens for a user

func (*VerificationTokenRepository) FindValidToken

func (r *VerificationTokenRepository) FindValidToken(ctx context.Context, tokenHash string) (*VerificationToken, error)

FindValidToken finds a valid (non-expired) verification token by hash

Jump to

Keyboard shortcuts

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