Documentation
¶
Index ¶
- func DollarPlaceholders(fragment string, start int) (string, int)
- func LanguageFilter(alias string, sibling string, languages []string, conjuncts []SiblingConjunct) (string, []any)
- func MarshalCustomFields(fields map[string]any) (any, error)
- func SortDirectionSQL(sortOrder string) string
- func SplitCSV(s string) []string
- type BlockedEmail
- type BlockedEmailRepo
- type BlockedEmailRepository
- type EmailUpdateTokenRepo
- type EmailUpdateTokenRepository
- func (r *EmailUpdateTokenRepository) CleanUpExpiredTokens(ctx context.Context) error
- func (r *EmailUpdateTokenRepository) CreateToken(ctx context.Context, token string, userID int, newEmail string) error
- func (r *EmailUpdateTokenRepository) DeleteToken(ctx context.Context, tokenID int) error
- func (r *EmailUpdateTokenRepository) GetToken(ctx context.Context, token string) (*userdomain.EmailUpdateToken, error)
- type FailedLoginAttemptRepository
- func (r *FailedLoginAttemptRepository) Create(ctx context.Context, attempt *authdomain.FailedLoginAttempt) error
- func (r *FailedLoginAttemptRepository) Delete(ctx context.Context, userID int) error
- func (r *FailedLoginAttemptRepository) GetByUserID(ctx context.Context, userID int) (*authdomain.FailedLoginAttempt, error)
- func (r *FailedLoginAttemptRepository) IncrementAttempts(ctx context.Context, userID int) error
- func (r *FailedLoginAttemptRepository) IsLocked(ctx context.Context, userID int) (bool, *time.Time, error)
- func (r *FailedLoginAttemptRepository) LockAccount(ctx context.Context, userID int, lockoutDuration time.Duration) error
- func (r *FailedLoginAttemptRepository) ResetAttempts(ctx context.Context, userID int) error
- func (r *FailedLoginAttemptRepository) ShouldSendLockoutEmail(ctx context.Context, userID int, minInterval time.Duration) (bool, error)
- func (r *FailedLoginAttemptRepository) UpdateLastEmailSent(ctx context.Context, userID int) error
- type InMemoryNotificationRepository
- type MFAChallengeRepository
- func (r *MFAChallengeRepository) Consume(ctx context.Context, id int) (bool, error)
- func (r *MFAChallengeRepository) Create(ctx context.Context, challenge *authdomain.MFAChallenge) error
- func (r *MFAChallengeRepository) Delete(ctx context.Context, id int) error
- func (r *MFAChallengeRepository) DeleteExpired(ctx context.Context) error
- func (r *MFAChallengeRepository) DeleteUserChallenges(ctx context.Context, userID int) error
- func (r *MFAChallengeRepository) FindByTokenHash(ctx context.Context, tokenHash string) (*authdomain.MFAChallenge, error)
- func (r *MFAChallengeRepository) IncrementAttempts(ctx context.Context, id, maxAttempts int) (bool, error)
- type Notification
- type NotificationRepo
- type NotificationType
- type PasswordResetTokenRepository
- func (r *PasswordResetTokenRepository) CreateToken(ctx context.Context, token *authdomain.PasswordResetToken) error
- func (r *PasswordResetTokenRepository) DeleteUserTokens(ctx context.Context, userID int) error
- func (r *PasswordResetTokenRepository) FindValidToken(ctx context.Context, tokenHash string) (*authdomain.PasswordResetToken, error)
- type SiblingConjunct
- type SoftDeleteRepo
- type SoftDeleteRepository
- func (r *SoftDeleteRepository) GetSoftDeletedContentByID(ctx context.Context, id int) (*SoftDeletedContent, error)
- func (r *SoftDeleteRepository) GetSoftDeletedContentByUser(ctx context.Context, userID int) ([]*SoftDeletedContent, error)
- func (r *SoftDeleteRepository) PermanentDeleteContent(ctx context.Context, contentType string, contentID int) error
- func (r *SoftDeleteRepository) RestoreContent(ctx context.Context, contentType string, contentID int) error
- func (r *SoftDeleteRepository) SoftDeleteContent(ctx context.Context, contentType string, contentID int, userID int, ...) error
- type SoftDeletedContent
- type UserDataExportRepo
- type UserDataExportRepository
- func (r *UserDataExportRepository) GetUserComments(ctx context.Context, userID int) ([]*userdomain.UserCommentItem, error)
- func (r *UserDataExportRepository) GetUserContent(ctx context.Context, userID int) ([]*userdomain.UserContentItem, error)
- func (r *UserDataExportRepository) GetUserDataForExport(ctx context.Context, userID int) (*userdomain.UserDataExport, error)
- func (r *UserDataExportRepository) GetUserMedia(ctx context.Context, userID int) ([]*userdomain.UserMediaItem, error)
- type UserDeletionRepo
- type UserDeletionRepository
- func (r *UserDeletionRepository) CountUsersByRoleAndStatus(ctx context.Context, role, status string) (int, error)
- func (r *UserDeletionRepository) DeleteAllUserData(ctx context.Context, userID int) error
- func (r *UserDeletionRepository) DeleteUserAccount(ctx context.Context, userID int) error
- func (r *UserDeletionRepository) DeleteUserComments(ctx context.Context, userID int) error
- func (r *UserDeletionRepository) DeleteUserContent(ctx context.Context, userID int) error
- func (r *UserDeletionRepository) DeleteUserMedia(ctx context.Context, userID int) error
- func (r *UserDeletionRepository) DeleteUserTokens(ctx context.Context, userID int) error
- type UserRepo
- type UserRepository
- func (r *UserRepository) CheckEmailExists(ctx context.Context, email string) (bool, error)
- func (r *UserRepository) CheckEmailExistsForOtherUser(ctx context.Context, userID int, email string) (bool, error)
- func (r *UserRepository) CheckUsernameExists(ctx context.Context, username string) (bool, error)
- func (r *UserRepository) CountUsers(ctx context.Context, status string) (int, error)
- func (r *UserRepository) CreateUser(ctx context.Context, user *userdomain.User) error
- func (r *UserRepository) DeleteProfilePicture(ctx context.Context, userID int) error
- func (r *UserRepository) DeleteUser(ctx context.Context, userID int) error
- func (r *UserRepository) GetAdminUser(ctx context.Context) (*userdomain.User, error)
- func (r *UserRepository) GetAllUsers(ctx context.Context, status string, limit int, offset int) ([]*userdomain.User, error)
- func (r *UserRepository) GetPendingUsers(ctx context.Context, limit int, offset int) ([]*userdomain.User, error)
- func (r *UserRepository) GetUserByEmail(ctx context.Context, email string) (*userdomain.User, error)
- func (r *UserRepository) GetUserByID(ctx context.Context, userID int) (*userdomain.User, error)
- func (r *UserRepository) GetUserByUsername(ctx context.Context, username string) (*userdomain.User, error)
- func (r *UserRepository) GetUserStatus(ctx context.Context, userID int) (string, error)
- func (r *UserRepository) RevokeSessions(ctx context.Context, userID int) error
- func (r *UserRepository) SetEmailVerified(ctx context.Context, userID int, emailVerified bool) error
- func (r *UserRepository) SoftDeleteUser(ctx context.Context, userID int) error
- func (r *UserRepository) SuspendUser(ctx context.Context, userID int) error
- func (r *UserRepository) UnsuspendUser(ctx context.Context, userID int) error
- func (r *UserRepository) UpdateAdminPasswordAndEmail(ctx context.Context, passwordHash, email, currentPasswordHash string) error
- func (r *UserRepository) UpdateCustomFields(ctx context.Context, userID int, customFields map[string]any) error
- func (r *UserRepository) UpdateEmail(ctx context.Context, userID int, email string) error
- func (r *UserRepository) UpdateLastLoginAt(ctx context.Context, userID int) error
- func (r *UserRepository) UpdateName(ctx context.Context, userID int, name string) error
- func (r *UserRepository) UpdatePassword(ctx context.Context, userID int, currentPasswordHash, newPasswordHash string) error
- func (r *UserRepository) UpdatePasswordByUserID(ctx context.Context, userID int, newPasswordHash string) error
- func (r *UserRepository) UpdateProfile(ctx context.Context, userID int, name string, email string, role string, ...) error
- func (r *UserRepository) UpdateProfilePicture(ctx context.Context, userID int, profilePicture string) error
- func (r *UserRepository) UpdateUserStatus(ctx context.Context, userID int, status string) error
- func (r *UserRepository) UpdateUserStatusIfCurrentStatus(ctx context.Context, userID int, currentStatus string, newStatus string) error
- type VerificationTokenRepository
- func (r *VerificationTokenRepository) CreateToken(ctx context.Context, token *authdomain.VerificationToken) error
- func (r *VerificationTokenRepository) DeleteExpiredTokens(ctx context.Context) error
- func (r *VerificationTokenRepository) DeleteUserTokens(ctx context.Context, userID int) error
- func (r *VerificationTokenRepository) FindValidToken(ctx context.Context, tokenHash string) (*authdomain.VerificationToken, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DollarPlaceholders ¶ added in v0.11.0
DollarPlaceholders rewrites every ? placeholder in fragment into $N positional placeholders numbered from start, returning the rewritten fragment and the next unused number. PostgreSQL drivers need this because LanguageFilter emits portable ? placeholders while the pg queries number their bind args; arg order is untouched, so the slice returned by LanguageFilter keeps working as-is.
func LanguageFilter ¶ added in v0.11.0
func LanguageFilter(alias string, sibling string, languages []string, conjuncts []SiblingConjunct) (string, []any)
LanguageFilter renders the language restriction for public listings against a priority-ordered languages slice, plus the bind args in SQL order. It implements Hugo-style language fallback:
- empty slice: no restriction — every language is returned.
- single element: restricted to exactly that language.
- multiple elements: each translation group is represented once by its best-ranked available language. A row survives only when no higher-priority published sibling exists in the same translation group (COALESCE(translation_group_id, id) identifies the group).
The predicate is meant to be appended to the outer WHERE clause before ORDER BY/LIMIT/OFFSET so pagination stays exact under deduplication. alias is the outer content_items table alias and sibling the alias used inside the NOT EXISTS subquery; both must differ from every other table alias in the query.
func MarshalCustomFields ¶ added in v0.5.0
MarshalCustomFields serialises a custom-fields map into the JSON string shape persisted in content_items.custom_fields. A nil map maps to a nil parameter (SQL NULL); any other map is JSON-marshalled to a string.
It returns the value as `any` so the result can be passed directly as a SQL driver argument (either nil or a string). Shared across the sqlite, mysql, and postgresql repositories.
func SortDirectionSQL ¶ added in v0.7.0
SortDirectionSQL returns the SQL keyword ("ASC" or "DESC") for the given domain SortOrder string. An empty or unrecognised value yields "DESC" — the safer default for "top N" ranking patterns. The handler layer is expected to validate the order string before constructing the filter, but the repository stays defensive in case it is bypassed.
This helper is shared across the sqlite, postgresql, and mysql driver packages so the defensive default behaviour stays consistent. The string it returns is safe to inline into SQL because it can only be one of two hardcoded constants — never caller-controlled input.
func SplitCSV ¶ added in v0.5.0
SplitCSV splits a comma-separated string (typically the output of a SQL GROUP_CONCAT / STRING_AGG(DISTINCT …) aggregation) into a clean []string, dropping empty entries. It returns a non-nil empty slice for blank input so callers always get a slice that serialises to JSON as [] rather than null.
It is shared across the sqlite, mysql, and postgresql content repositories, which all produce the same comma-joined shape for aggregated columns.
Types ¶
type BlockedEmail ¶
BlockedEmail represents a blocked email entry
type BlockedEmailRepo ¶
type BlockedEmailRepo interface {
BlockEmail(ctx context.Context, email string, reason string) error
IsEmailBlocked(ctx context.Context, email string) (bool, error)
UnblockEmail(ctx context.Context, email string) error
}
BlockedEmailRepo defines the interface for blocked email repository operations
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 ¶
BlockEmail adds an email to the blocked list
func (*BlockedEmailRepository) IsEmailBlocked ¶
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 EmailUpdateTokenRepo ¶
type EmailUpdateTokenRepo interface {
CreateToken(ctx context.Context, token string, userID int, newEmail string) error
GetToken(ctx context.Context, token string) (*userdomain.EmailUpdateToken, error)
DeleteToken(ctx context.Context, tokenID int) error
CleanUpExpiredTokens(ctx context.Context) error
}
EmailUpdateTokenRepo defines the interface for email update token repository operations
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 ¶
func (r *EmailUpdateTokenRepository) GetToken(ctx context.Context, token string) (*userdomain.EmailUpdateToken, error)
GetToken retrieves an email update token by token value
type FailedLoginAttemptRepository ¶
type FailedLoginAttemptRepository struct {
// contains filtered or unexported fields
}
FailedLoginAttemptRepository handles failed login attempt data operations
func NewFailedLoginAttemptRepository ¶
func NewFailedLoginAttemptRepository(db *sql.DB) *FailedLoginAttemptRepository
NewFailedLoginAttemptRepository creates a new failed login attempt repository
func (*FailedLoginAttemptRepository) Create ¶
func (r *FailedLoginAttemptRepository) Create(ctx context.Context, attempt *authdomain.FailedLoginAttempt) error
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) (*authdomain.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 InMemoryNotificationRepository ¶
type InMemoryNotificationRepository struct {
// contains filtered or unexported fields
}
InMemoryNotificationRepository stores notifications in memory for MVP
func NewInMemoryNotificationRepository ¶
func NewInMemoryNotificationRepository() *InMemoryNotificationRepository
NewInMemoryNotificationRepository creates a new in-memory notification repository
func (*InMemoryNotificationRepository) CreateNotification ¶
func (r *InMemoryNotificationRepository) CreateNotification(ctx context.Context, notificationType NotificationType, message string) error
CreateNotification creates a new notification
func (*InMemoryNotificationRepository) GetNotifications ¶
func (r *InMemoryNotificationRepository) GetNotifications(ctx context.Context, limit int) ([]Notification, error)
GetNotifications retrieves notifications in reverse chronological order
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
Consume deletes the challenge and reports whether this caller removed it.
func (*MFAChallengeRepository) Create ¶ added in v1.1.0
func (r *MFAChallengeRepository) Create(ctx context.Context, challenge *authdomain.MFAChallenge) error
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 format and zone (datetime('now') compares against a UTC string and misfires on local time).
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 Notification ¶
type Notification struct {
ID int
Type NotificationType
Message string
CreatedAt time.Time
}
Notification represents an admin notification
type NotificationRepo ¶
type NotificationRepo interface {
CreateNotification(ctx context.Context, notificationType NotificationType, message string) error
GetNotifications(ctx context.Context, limit int) ([]Notification, error)
}
NotificationRepo defines the interface for notification operations
type NotificationType ¶
type NotificationType string
NotificationType represents the type of notification
const ( NotificationTypeUserRegistered NotificationType = "user_registered" NotificationTypeUserVerified NotificationType = "user_verified" )
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 ¶
func (r *PasswordResetTokenRepository) CreateToken(ctx context.Context, token *authdomain.PasswordResetToken) error
CreateToken creates a new password reset token
func (*PasswordResetTokenRepository) DeleteUserTokens ¶
func (r *PasswordResetTokenRepository) DeleteUserTokens(ctx context.Context, userID int) error
DeleteUserTokens deletes all password reset tokens for a user
func (*PasswordResetTokenRepository) FindValidToken ¶
func (r *PasswordResetTokenRepository) FindValidToken(ctx context.Context, tokenHash string) (*authdomain.PasswordResetToken, error)
FindValidToken finds a valid (non-expired) password reset token by hash
type SiblingConjunct ¶ added in v0.11.0
SiblingConjunct is one extra WHERE conjunct applied to the sibling subquery of LanguageFilter's fallback predicate. Use it to keep the dedup inside the listing's own scope — e.g. the sibling must share the outer query's status, post type, author, or tag for it to outrank the candidate row. The SQL must reference columns through the sibling alias passed to LanguageFilter.
type SoftDeleteRepo ¶
type SoftDeleteRepo interface {
SoftDeleteContent(ctx context.Context, contentType string, contentID int, userID int, deletedBy int, reason string) error
GetSoftDeletedContentByUser(ctx context.Context, userID int) ([]*SoftDeletedContent, error)
GetSoftDeletedContentByID(ctx context.Context, id int) (*SoftDeletedContent, error)
RestoreContent(ctx context.Context, contentType string, contentID int) error
PermanentDeleteContent(ctx context.Context, contentType string, contentID int) error
}
SoftDeleteRepo defines the interface for soft delete repository operations
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 (for Story 1.8) This method is a placeholder for future implementation
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
type SoftDeletedContent ¶
type SoftDeletedContent struct {
ID int
ContentType string
ContentID int
UserID int
DeletedAt string
DeletedBy int
Reason sql.NullString
IsPermanent bool
}
SoftDeletedContent represents a soft deleted content item
type UserDataExportRepo ¶
type UserDataExportRepo interface {
GetUserContent(ctx context.Context, userID int) ([]*userdomain.UserContentItem, error)
GetUserComments(ctx context.Context, userID int) ([]*userdomain.UserCommentItem, error)
GetUserMedia(ctx context.Context, userID int) ([]*userdomain.UserMediaItem, error)
GetUserDataForExport(ctx context.Context, userID int) (*userdomain.UserDataExport, error)
}
UserDataExportRepo defines the interface for user data export repository operations
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) ([]*userdomain.UserCommentItem, error)
GetUserComments retrieves all comments posted by a user
func (*UserDataExportRepository) GetUserContent ¶
func (r *UserDataExportRepository) GetUserContent(ctx context.Context, userID int) ([]*userdomain.UserContentItem, error)
GetUserContent retrieves all content items (posts/pages) created by a user
func (*UserDataExportRepository) GetUserDataForExport ¶
func (r *UserDataExportRepository) GetUserDataForExport(ctx context.Context, userID int) (*userdomain.UserDataExport, error)
GetUserDataForExport aggregates all user data for export
func (*UserDataExportRepository) GetUserMedia ¶
func (r *UserDataExportRepository) GetUserMedia(ctx context.Context, userID int) ([]*userdomain.UserMediaItem, error)
GetUserMedia retrieves all media files uploaded by a user
type UserDeletionRepo ¶
type UserDeletionRepo interface {
DeleteUserAccount(ctx context.Context, userID int) error
DeleteUserTokens(ctx context.Context, userID int) error
DeleteUserContent(ctx context.Context, userID int) error
DeleteUserComments(ctx context.Context, userID int) error
DeleteUserMedia(ctx context.Context, userID int) error
CountUsersByRoleAndStatus(ctx context.Context, role, status string) (int, error)
DeleteAllUserData(ctx context.Context, userID int) error
}
UserDeletionRepo defines the interface for user deletion operations
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 Note: This is a placeholder for future functionality
func (*UserDeletionRepository) DeleteUserContent ¶
func (r *UserDeletionRepository) DeleteUserContent(ctx context.Context, userID int) error
DeleteUserContent deletes all content (posts, pages) created by a user Note: This is a placeholder for future functionality
func (*UserDeletionRepository) DeleteUserMedia ¶
func (r *UserDeletionRepository) DeleteUserMedia(ctx context.Context, userID int) error
DeleteUserMedia deletes all media files uploaded by a user Note: This is a placeholder for future functionality
func (*UserDeletionRepository) DeleteUserTokens ¶
func (r *UserDeletionRepository) DeleteUserTokens(ctx context.Context, userID int) error
DeleteUserTokens deletes all tokens associated with a user
type UserRepo ¶
type UserRepo interface {
UpdateAdminPasswordAndEmail(ctx context.Context, passwordHash, email, currentPasswordHash string) error
GetAdminUser(ctx context.Context) (*userdomain.User, error)
CreateUser(ctx context.Context, user *userdomain.User) error
CheckUsernameExists(ctx context.Context, username string) (bool, error)
CheckEmailExists(ctx context.Context, email string) (bool, error)
UpdateUserStatus(ctx context.Context, userID int, status string) error
UpdateUserStatusIfCurrentStatus(ctx context.Context, userID int, currentStatus string, newStatus string) error
SetEmailVerified(ctx context.Context, userID int, emailVerified bool) error
GetUserByID(ctx context.Context, userID int) (*userdomain.User, error)
GetUserByEmail(ctx context.Context, email string) (*userdomain.User, error)
GetUserByUsername(ctx context.Context, username string) (*userdomain.User, error)
GetPendingUsers(ctx context.Context, limit int, offset int) ([]*userdomain.User, error)
DeleteUser(ctx context.Context, userID int) error
SuspendUser(ctx context.Context, userID int) error
UnsuspendUser(ctx context.Context, userID int) error
SoftDeleteUser(ctx context.Context, userID int) error
GetAllUsers(ctx context.Context, status string, limit int, offset int) ([]*userdomain.User, error)
// CountUsers returns the total number of users, optionally filtered by status — mirrors
// GetAllUsers' WHERE clause so a list's total always matches its rows.
CountUsers(ctx context.Context, status string) (int, error)
GetUserStatus(ctx context.Context, userID int) (string, error)
UpdateEmail(ctx context.Context, userID int, email string) error
UpdateName(ctx context.Context, userID int, name string) error
UpdatePassword(ctx context.Context, userID int, currentPasswordHash, newPasswordHash string) error
UpdateLastLoginAt(ctx context.Context, userID int) error
UpdatePasswordByUserID(ctx context.Context, userID int, newPasswordHash string) error
RevokeSessions(ctx context.Context, userID int) error
UpdateProfile(ctx context.Context, userID int, name string, email string, role string, customFields map[string]any) error
UpdateCustomFields(ctx context.Context, userID int, customFields map[string]any) error
CheckEmailExistsForOtherUser(ctx context.Context, userID int, email string) (bool, error)
UpdateProfilePicture(ctx context.Context, userID int, profilePicture string) error
DeleteProfilePicture(ctx context.Context, userID int) error
}
UserRepo defines the interface for user repository operations
type UserRepository ¶
type UserRepository struct {
// contains filtered or unexported fields
}
UserRepository handles user data operations
func NewUserRepository ¶
func NewUserRepository(db *sql.DB) *UserRepository
NewUserRepository creates a new user repository
func (*UserRepository) CheckEmailExists ¶
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 ¶
CheckUsernameExists checks if a username already exists (case-insensitive)
func (*UserRepository) CountUsers ¶ added in v0.8.0
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 *userdomain.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) (*userdomain.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) ([]*userdomain.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) ([]*userdomain.User, error)
GetPendingUsers retrieves all users with pending status
func (*UserRepository) GetUserByEmail ¶
func (r *UserRepository) GetUserByEmail(ctx context.Context, email string) (*userdomain.User, error)
GetUserByEmail retrieves a user by email
func (*UserRepository) GetUserByID ¶
func (r *UserRepository) GetUserByID(ctx context.Context, userID int) (*userdomain.User, error)
GetUserByID retrieves a user by ID
func (*UserRepository) GetUserByUsername ¶
func (r *UserRepository) GetUserByUsername(ctx context.Context, username string) (*userdomain.User, error)
GetUserByUsername retrieves a user by username (case-insensitive)
func (*UserRepository) GetUserStatus ¶
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 by updating their status to 'soft_deleted'
func (*UserRepository) SuspendUser ¶
func (r *UserRepository) SuspendUser(ctx context.Context, userID int) error
SuspendUser suspends a user by updating their status to 'suspended'
func (*UserRepository) UnsuspendUser ¶
func (r *UserRepository) UnsuspendUser(ctx context.Context, userID int) error
UnsuspendUser unsuspends a user by updating their status to 'active'
func (*UserRepository) UpdateAdminPasswordAndEmail ¶
func (r *UserRepository) UpdateAdminPasswordAndEmail(ctx context.Context, passwordHash, email, currentPasswordHash string) error
UpdateAdminPasswordAndEmail updates the admin user's password and email. Uses optimistic locking via currentPasswordHash to prevent concurrent setup completion.
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 ¶
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
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 ¶
UpdateUserStatus updates a user's status
func (*UserRepository) UpdateUserStatusIfCurrentStatus ¶
func (r *UserRepository) UpdateUserStatusIfCurrentStatus(ctx context.Context, userID int, currentStatus string, newStatus string) error
UpdateUserStatusIfCurrentStatus atomically updates a user's status only if they currently have the specified status This prevents TOCTOU race conditions by performing the check and update in a single atomic operation
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 ¶
func (r *VerificationTokenRepository) CreateToken(ctx context.Context, token *authdomain.VerificationToken) error
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) (*authdomain.VerificationToken, error)
FindValidToken finds a valid (non-expired) verification token by hash