ds

package
v0.0.0-...-59778e0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
const (
	// PerPageDefault ...
	PerPageDefault = 25
	// PerPageMax ...
	PerPageMax = 100
)
View Source
const (

	// CleanupDeletedUserAfter ...
	CleanupDeletedUserAfter = 30 * 24 * time.Hour
)

Variables

View Source
var EntityTypes = []EntityType{
	EntityTypeBook,
}

EntityTypes ...

EntityVisibilities ...

View Source
var ErrInvalidIDFormat = errors.New("invalid UUID format")

ErrInvalidIDFormat ...

View Source
var IDInputRules = z.CustomFunc(func(val *ID, _ z.Ctx) bool {
	if val == nil || *val == NilID {
		return false
	}

	return true
}, z.Message("Invalid UUID"))

IDInputRules ...

View Source
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

func (b *Book) CreateRules() z.Shape

CreateRules provides the validation map used when saving a new book.

func (*Book) UpdateRules

func (b *Book) UpdateRules() z.Shape

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

func (e *Entity) CreateRules() z.Shape

CreateRules returns the validation schema for creating a new entity.

func (*Entity) UpdateRules

func (e *Entity) UpdateRules() z.Shape

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"
)

func (EntityType) Valid

func (t EntityType) Valid() bool

Valid ...

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"
)

func (EntityVisibility) Is

Is ...

func (EntityVisibility) Not

func (v EntityVisibility) Not(v2 ...EntityVisibility) bool

Not ...

func (EntityVisibility) Valid

func (v EntityVisibility) Valid() bool

Valid ...

type FilterDT

type FilterDT struct {
	DT   *time.Time
	From *time.Time
	To   *time.Time
}

FilterDT ...

func DtAfter

func DtAfter(t time.Time) *FilterDT

DtAfter ...

func DtAt

func DtAt(t time.Time) *FilterDT

DtAt ...

func DtBefore

func DtBefore(t time.Time) *FilterDT

DtBefore ...

func DtBetween

func DtBetween(from, to time.Time) *FilterDT

DtBetween ...

type ID

type ID uuid.UUID //nolint:recvcheck

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 ParseID

func ParseID(s string) (ID, error)

ParseID converts a string into a ds.ID. It supports standard UUID formats.

func (ID) IsNil

func (id ID) IsNil() bool

IsNil ...

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON uses the built-in MarshalText from google/uuid.

func (*ID) Scan

func (id *ID) Scan(src any) error

Scan implements sql.Scanner to allow reading UUID from the database into ID.

func (ID) String

func (id ID) String() string

String returns the standard UUID string representation.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON uses the built-in UnmarshalText.

func (*ID) UnmarshalYAML

func (id *ID) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value implements driver.Valuer to allow ID to be used in SQL queries.

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

func UserFromContext(ctx context.Context) *User

UserFromContext attempts to retrieve user object from the context.

func (*User) Deleted

func (u *User) Deleted() bool

Deleted ...

func (*User) ToContext

func (u *User) ToContext(ctx context.Context) context.Context

ToContext adds the given user object to the provided 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.

func (*UserSession) ToContext

func (s *UserSession) ToContext(ctx context.Context) context.Context

ToContext adds the given user session object to the provided context.

type UsersFilter

type UsersFilter struct {
	Page           int
	PerPage        int
	WithCount      bool
	CreatedAt      *FilterDT
	DeletedAt      *FilterDT
	Deleted        bool
	OrderBy        string
	OrderDirection string
}

UsersFilter is used to filter and paginate user queries.

Directories

Path Synopsis
Package useractivity ...
Package useractivity ...

Jump to

Keyboard shortcuts

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