Documentation
¶
Overview ¶
Package ds (Data Structure) All data models belonging to the app are stored here. Global functions should not be created here. Methods on types are welcome.
Index ¶
- Constants
- Variables
- type Action
- type AuthToken
- type Book
- type ChangeEmailRequest
- type EmailConfirmation
- type Entity
- type EntityChangeLog
- type EntityStatus
- type EntityType
- type EntityVisibility
- type FilterDT
- type ID
- type OAuthUserAccount
- type PasswordResetToken
- type User
- type UserActivityLog
- type UserSession
- type UsersFilter
Constants ¶
const ( // PerPageDefault ... PerPageDefault = 25 // PerPageMax ... PerPageMax = 100 )
const ( // CleanupDeletedUserAfter ... CleanupDeletedUserAfter = 30 * 24 * time.Hour )
Variables ¶
var EntityTypes = []EntityType{ EntityTypeBook, }
EntityTypes ...
var EntityVisibilities = []EntityVisibility{ EntityVisibilityPublic, EntityVisibilityPrivate, EntityVisibilityUnlisted, }
EntityVisibilities ...
var ErrInvalidIDFormat = errors.New("invalid UUID format")
ErrInvalidIDFormat ...
var IDInputRules = z.CustomFunc(func(val *ID, _ z.Ctx) bool { if val == nil || *val == NilID { return false } return true }, z.Message("Invalid UUID"))
IDInputRules ...
var NilID = ID(uuid.Nil)
NilID is an empty UUID, all zeros.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action string
Action represents the type of operation performed on an entity.
const ( // ActionCreate indicates the initial creation of an entity. ActionCreate Action = "create" // ActionUpdate indicates a modification to an existing entity. ActionUpdate Action = "update" // ActionPublish indicates the entity was made publicly visible. ActionPublish Action = "publish" // ActionDelete indicates the entity was moved to a deleted state. ActionDelete Action = "delete" // ActionRestore indicates a previously deleted entity was recovered. ActionRestore Action = "restore" )
type AuthToken ¶
type AuthToken struct {
ID ID
UserID int64
User *User
ClientName string
ClientIP string
UserAgent string
Token string
CreatedAt time.Time
ExpiresAt time.Time
}
AuthToken represents container for authentication-related data.
type Book ¶
type Book struct {
Entity
Description string `json:"description"`
AuthorName string `json:"author_name"`
AuthorLink string `json:"author_link"`
Homepage string `json:"homepage"`
ReleaseDate string `json:"release_date"`
CoverImage string `json:"cover_image"`
}
Book defines the data structure for a book.
func (*Book) CreateRules ¶
CreateRules provides the validation map used when saving a new book.
func (*Book) UpdateRules ¶
UpdateRules provides the validation map used when editing an existing book.
type ChangeEmailRequest ¶
type ChangeEmailRequest struct {
ID ID `json:"-"`
UserID ID `json:"-"`
NewEmail string `json:"-"`
Token string `json:"-"`
ExpiresAt time.Time `json:"-"`
CreatedAt time.Time `json:"-"`
}
ChangeEmailRequest represents a record in the change_email_requests table. It stores a single-use token for a user to confirm a change to their email address.
func (*ChangeEmailRequest) Invalid ¶
func (r *ChangeEmailRequest) Invalid() bool
Invalid returns true if token has expired.
type EmailConfirmation ¶
type EmailConfirmation struct {
ID ID
UserID ID
Code string
CreatedAt time.Time
ExpiresAt time.Time
ConfirmedAt *time.Time
}
EmailConfirmation represents a record used to verify a user's email address after registration or a change request.
func (*EmailConfirmation) Invalid ¶
func (c *EmailConfirmation) Invalid() bool
Invalid checks if the confirmation record is expired. Returns true if the token is no longer valid, false otherwise.
type Entity ¶
type Entity struct {
ID ID `json:"id"`
OwnerID ID `json:"owner_id"`
Type EntityType `json:"-"`
URLName string `json:"url_name"`
Title string `json:"title"`
Visibility EntityVisibility `json:"visibility"`
Status EntityStatus `json:"status"`
PublishedAt *time.Time `json:"published_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
DeletedAt *time.Time `json:"-"`
}
Entity represents the base metadata for any user-content in the system.
func (*Entity) CreateRules ¶
CreateRules returns the validation schema for creating a new entity.
func (*Entity) UpdateRules ¶
UpdateRules returns the validation schema for updating an existing entity.
type EntityChangeLog ¶
type EntityChangeLog struct {
ID ID `json:"id"`
EntityID ID `json:"entity_id"`
UserID ID `json:"user_id"`
Action Action `json:"action"`
Diff map[string]any `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
EntityChangeLog records a history of actions performed on an entity for auditing purposes.
type EntityStatus ¶
type EntityStatus string
EntityStatus defines the moderation state of an entity.
const ( // EntityStatusUnderReview means the entity is awaiting moderation. EntityStatusUnderReview EntityStatus = "review" // EntityStatusApproved means the entity is live and approved. EntityStatusApproved EntityStatus = "approved" // EntityStatusRejected means the entity failed moderation. EntityStatusRejected EntityStatus = "rejected" )
type EntityType ¶
type EntityType string
EntityType defines the type of the entity content.
const ( // EntityTypeBook ... EntityTypeBook EntityType = "book" )
type EntityVisibility ¶
type EntityVisibility string
EntityVisibility controls how the entity is accessed in listings and search results.
const ( // EntityVisibilityPublic means the entity is visible to everyone and indexed. EntityVisibilityPublic EntityVisibility = "public" // EntityVisibilityPrivate means the entity is restricted to the owner and collaborators. EntityVisibilityPrivate EntityVisibility = "private" // EntityVisibilityUnlisted means the entity is accessible only via direct link. EntityVisibilityUnlisted EntityVisibility = "unlisted" )
type ID ¶
ID is a domain-specific type for UUID v7.
func NewID ¶
func NewID() ID
NewID generates a new UUID v7. It panics if the system clock is severely misconfigured.
func (ID) MarshalJSON ¶
MarshalJSON uses the built-in MarshalText from google/uuid.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON uses the built-in UnmarshalText.
func (*ID) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface.
type OAuthUserAccount ¶
type OAuthUserAccount struct {
ID ID `json:"id"`
UserID ID `json:"user_id"`
Provider provider.Type `json:"provider"`
ProviderUserID string `json:"provider_user_id"`
CreatedAt time.Time `json:"created_at"`
}
OAuthUserAccount links a local user to their external identity provider credentials.
type PasswordResetToken ¶
type PasswordResetToken struct {
ID ID `json:"-"`
UserID ID `json:"-"`
Token string `json:"-"`
ExpiresAt time.Time `json:"-"`
CreatedAt time.Time `json:"-"`
}
PasswordResetToken represents a record in the password_reset_tokens table. It stores a single-use token for a user to reset their password.
func (*PasswordResetToken) Invalid ¶
func (t *PasswordResetToken) Invalid() bool
Invalid returns true if the password reset token has expired.
type User ¶
type User struct {
ID ID `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
EmailConfirmed bool `json:"-"`
Password string `json:"-"`
CreatedAt time.Time `json:"-"`
UpdatedAt *time.Time `json:"-"`
DeletedAt *time.Time `json:"-"`
// IsAdmin is true if the user's ID is in the admin list from the config file.
// This field is set by the auth middleware.
IsAdmin bool `json:"-"`
}
User ...
func UserFromContext ¶
UserFromContext attempts to retrieve user object from the context.
type UserActivityLog ¶
type UserActivityLog struct {
ID ID `json:"id"`
UserID ID `json:"user_id"`
ActionType useractivity.Type `json:"action_type"`
IsPublic bool `json:"is_public"`
EntityType sql.NullString `json:"entity_type"`
EntityID sql.NullInt64 `json:"entity_id"`
Meta json.RawMessage `json:"meta,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
UserActivityLog represents a single entry in the user_activity_logs table.
type UserSession ¶
type UserSession struct {
ID ID `json:"id"`
UserID ID `json:"user_id"`
CreatedAt time.Time `json:"-"`
UpdatedAt *time.Time `json:"-"`
ExpiresAt time.Time `json:"-"`
}
UserSession represents an active session for a logged-in user.
func UserSessionFromContext ¶
func UserSessionFromContext(ctx context.Context) *UserSession
UserSessionFromContext attempts to retrieve the user session object from the context.