ad

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 19 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

View Source
const DescriptionAdditionLabel = "Description Addition"

DescriptionAdditionLabel is the legacy append-via-edit history marker.

View Source
const DescriptionChangeLabel = "Description change"

DescriptionChangeLabel is the history label for a description rewrite.

View Source
const OriginalLabel = "original"

Variables

This section is empty.

Functions

func Activate

func Activate(id int) error

Activate restores an inactive ad to live listings and renews expires_at.

func AdLocationDisplay

func AdLocationDisplay(a Ad) string

AdLocationDisplay returns the location line for cards, detail, and flyers.

func AppendHistoryEntry

func AppendHistoryEntry(desc, label, body string, at time.Time,
	tz *time.Location) string

AppendHistoryEntry prepends a labeled, timestamped history block (newest first).

func BuildFieldChangeEntries

func BuildFieldChangeEntries(oldAd Ad, newTitle string, newLocationText string,
	newFacets map[string]facet.Value, category Category) []struct {
	label string
	body  string
}

BuildFieldChangeEntries returns history entry bodies for changed ad fields.

func ComputeExpiresAt

func ComputeExpiresAt(now time.Time) time.Time

ComputeExpiresAt is the listing lifetime measured from now.

func ConfirmImages

func ConfirmImages(userID, adID, newCount int, tz *time.Location) error

ConfirmImages sets image_count after client uploads succeed. newCount must be >= current count and <= MaxImagesPerAd.

func CountActiveAdsByUser

func CountActiveAdsByUser(userID int) (int, error)

CountActiveAdsByUser returns the number of live ads for a user

func CreateAd

func CreateAd(input CreateInput) (int, error)

func DefaultCategoryID

func DefaultCategoryID() int

func DisplayDescription

func DisplayDescription(desc string) string

DisplayDescription renders stored description as plain text for display.

func EncodeSuggestionFormValue

func EncodeSuggestionFormValue(label, value string) string

func EnsureDescriptionFits

func EnsureDescriptionFits(desc string, at time.Time,
	tz *time.Location) (string, error)

EnsureDescriptionFits compresses description text until it fits MaxAdDescriptionLength.

func FormalFacetLines

func FormalFacetLines(category Category, values map[string]facet.Value) []string

FormalFacetLines formats all formal facet fields for the suggestions prompt, including empty ones so the model knows which fields exist on the form.

func FormatTagUpdates

func FormatTagUpdates(old, new []Suggestion) string

FormatTagUpdates describes added and removed tag pills.

func GetAdsWithoutVectors

func GetAdsWithoutVectors() ([]int, error)

func GetCategoryIDByName

func GetCategoryIDByName(name string) (int, error)

GetCategoryIDByName returns the ID of a category by its name

func GetCategoryImageFile

func GetCategoryImageFile(categoryID int) (string, error)

func GetCategoryName

func GetCategoryName(categoryID int) (string, error)

func GetUserAdIDs

func GetUserAdIDs(userID int, filterType string) ([]int, error)

GetUserAdIDs returns ad IDs for a user based on filter type filterType: "bookmarked", "active", "inactive", or "deleted"

func HasLocationFacet

func HasLocationFacet(category Category) bool

HasLocationFacet reports whether the category uses a location facet.

func IncrementAdClickForUser

func IncrementAdClickForUser(adID, userID int) error

func IncrementAdImageClickForUser

func IncrementAdImageClickForUser(adID, userID, imageIndex int) error

func LoadCategories

func LoadCategories() error

func LoadTags

func LoadTags(a *Ad) error

LoadTags reads tags JSON for one ad (detail page only).

func LocationFacetKey

func LocationFacetKey(category Category) string

LocationFacetKey returns the facet key used for geo lookup on this category.

func LocationTextFromFacets

func LocationTextFromFacets(category Category,
	facets map[string]facet.Value) string

LocationTextFromFacets returns trimmed location text from facets.

func ParseCategory

func ParseCategory(categoryStr string) int

func ParseImageOrder added in v0.0.23

func ParseImageOrder(raw string, n int) ([]int, error)

ParseImageOrder parses a comma-separated 1-based permutation of 1..n. Empty input means no reorder (nil, nil).

func ParseSuggestionFormValue

func ParseSuggestionFormValue(raw string) (label, value string, ok bool)

func Pause

func Pause(id int) error

Pause hides an ad from listings; the owner can activate it again.

func PermanentlyDelete

func PermanentlyDelete(id int) error

PermanentlyDelete soft-deletes an ad as a zombie that cannot be restored.

func PermanentlyDeleteByUser

func PermanentlyDeleteByUser(userID int) ([]int, error)

PermanentlyDeleteByUser soft-deletes all non-zombie ads owned by userID.

func RemapDescriptionImageIndices added in v0.0.23

func RemapDescriptionImageIndices(desc string, order []int) string

RemapDescriptionImageIndices rewrites "Images Added" history bodies so each stored index follows the same permutation as ReorderAdImages.

func Renew

func Renew(id int) error

Renew sets an active ad's expires_at to now + AdExpireMonths.

func RenewEligible

func RenewEligible(expiresAt, now time.Time) bool

RenewEligible is true when expires_at is within AdExpireRenewWithinMonths.

func SanitizeAdText

func SanitizeAdText(s string) string

SanitizeAdText normalizes common paste artifacts and removes invisible or control characters unsuitable for stored ad title/description.

func SplitDescription

func SplitDescription(desc string) (original, history string)

SplitDescription separates the original body from server history.

func TagsJSON

func TagsJSON(suggestions []Suggestion) string

TagsJSON serializes tags for storage in ads.tags.

func TitleContainsEmoji

func TitleContainsEmoji(s string) bool

TitleContainsEmoji reports whether s includes emoji or other pictographs unsuitable for ad titles (e.g. flag or warning icons).

func UpdateAd

func UpdateAd(input UpdateInput) error

func WrapDescription

func WrapDescription(body string, at time.Time, tz *time.Location) string

WrapDescription stores plain body text as the original entry.

Types

type Ad struct {
	// Core database fields
	ID          int        `db:"id"`
	CategoryID  int        `db:"category_id"`
	Title       string     `db:"title"`
	Description string     `db:"description"`
	CreatedAt   time.Time  `db:"created_at"`
	ExpiresAt   time.Time  `db:"expires_at"`
	InactiveAt  *time.Time `db:"inactive_at"`
	DeletedAt   *time.Time `db:"deleted_at"`
	UserID      int        `db:"user_id"`
	ImageCount  int        `db:"image_count"`
	LocationID  *int       `db:"location_id"`

	// Location fields from join
	City        string `db:"city"`
	AdminArea   string `db:"admin_area"`
	Country     string `db:"country"`
	RawLocation string `db:"raw_location"`

	// Computed fields
	Bookmarked bool `db:"bookmarked"`
	FlagCount  int  `db:"flag_count"`

	// Category-specific facet values
	Facets map[string]facet.Value

	// Tags selected for the ad; loaded lazily on ad detail (ads.tags JSON)
	Tags []Suggestion
}

func GetAd

func GetAd(userID int, id int, tz *time.Location) (Ad, error)

func GetAds

func GetAds(userID int, ids []int, tz *time.Location) ([]Ad, error)

func (Ad) IsActive

func (a Ad) IsActive() bool

func (Ad) IsDeleted

func (a Ad) IsDeleted() bool

func (Ad) IsInactive

func (a Ad) IsInactive() bool

func (Ad) PriceValue

func (a Ad) PriceValue() (amount int, currency string, ok bool)

PriceValue returns the ad's price amount and currency, if a price facet is set.

type Category

type Category struct {
	ID        int      `json:"id"`
	Name      string   `json:"name"`
	ImageFile string   `json:"image_file"`
	FacetKeys []string `json:"facets"`
}

func GetCategories

func GetCategories() ([]Category, error)

func GetCategory

func GetCategory(categoryID int) Category

func (Category) Facets

func (c Category) Facets() []facet.Def

Facets returns the facet definitions this category uses, in declared order.

type ClickSummary

type ClickSummary struct {
	UsersWithClicks int
	AdsClicked      int
	AdDetailViews   int
	ImageNavClicks  int
	ActiveLast7Days int
}

func GetClickSummary

func GetClickSummary() (ClickSummary, error)

type CreateInput

type CreateInput struct {
	CategoryID   int
	UserID       int
	Title        string
	Description  string
	LocationText string
	Facets       map[string]facet.Value
	Suggestions  []Suggestion
	ImageCount   int
}

type DescriptionDisplay

type DescriptionDisplay struct {
	// Original is the current listing text.
	Original string
	// Body is the current listing text (same as Original).
	Body    string
	History []HistoryEntryDisplay
}

DescriptionDisplay holds original ad text and edit history for display.

func ParseDescriptionForDisplay

func ParseDescriptionForDisplay(desc string) DescriptionDisplay

ParseDescriptionForDisplay splits stored description into original and history.

type DescriptionLink struct {
	Text string
	URL  string
}

DescriptionLink is a validated https URL rendered as link text.

type DescriptionSegment

type DescriptionSegment struct {
	Text string
	Link *DescriptionLink
}

DescriptionSegment is plain text or a link within a description.

func SplitDescriptionLinks(s string) []DescriptionSegment

SplitDescriptionLinks splits s into text and auto-detected https URL segments.

type DueExpire

type DueExpire struct {
	ID     int `db:"id"`
	UserID int `db:"user_id"`
}

DueExpire holds an active ad past its expires_at.

func ListAdsDueToExpire

func ListAdsDueToExpire() ([]DueExpire, error)

ListAdsDueToExpire returns active ads whose expires_at is in the past.

type EmbeddingInput

type EmbeddingInput struct {
	ID          int
	CategoryID  int
	Title       string
	Description string
	TagLabels   []string
	City        string
	AdminArea   string
	Country     string
	Latitude    float64
	Longitude   float64
	HasLocation bool
	FlagCount   int
	Facets      map[string]facet.Value
	FacetDefs   []facet.Def
}

func GetForEmbedding

func GetForEmbedding(adID int) (EmbeddingInput, error)

func (EmbeddingInput) PriceValue

func (in EmbeddingInput) PriceValue() (amount int, currency string, ok bool)

type EmbeddingStats

type EmbeddingStats struct {
	Embedded int
	Missing  int
}

func GetEmbeddingStats

func GetEmbeddingStats() (EmbeddingStats, error)

type HistoryEntryDisplay

type HistoryEntryDisplay struct {
	Header       string
	Body         string
	ImageIndices []int
}

HistoryEntryDisplay is one parsed edit-history block for UI rendering.

type MissingEmbedding

type MissingEmbedding struct {
	ID           int    `db:"id"`
	Title        string `db:"title"`
	CategoryID   int    `db:"category_id"`
	CategoryName string `db:"category_name"`
}

func ListMissingEmbeddings

func ListMissingEmbeddings(limit int) ([]MissingEmbedding, error)

type MonthlyFunStat

type MonthlyFunStat struct {
	Month              time.Time `db:"month"`
	RegisteredUsers    int       `db:"registered_users"`
	UsersWithActiveAds int       `db:"users_with_active_ads"`
	ActiveAds          int       `db:"active_ads"`
}

MonthlyFunStat is a month-end snapshot of public site totals.

func MonthlyFunStats

func MonthlyFunStats() ([]MonthlyFunStat, error)

MonthlyFunStats returns one row per calendar month from the earliest user or ad through the current month. Counts are as-of the end of each past month (or now for the current month): a user or ad is included if it already existed and had not yet been deleted or inactivated.

type RecentClick

type RecentClick struct {
	LastClickedAt time.Time `db:"last_clicked_at"`
	UserID        int       `db:"user_id"`
	AdID          int       `db:"ad_id"`
	Title         string    `db:"title"`
	ClickType     string    `db:"click_type"`
	ImageIndex    *int      `db:"image_index"`
	ClickCount    int       `db:"click_count"`
}

func GetRecentClickActivity

func GetRecentClickActivity(limit int) ([]RecentClick, error)

type SuggestInput

type SuggestInput struct {
	CategoryID      int
	CategoryName    string
	Title           string
	Description     string
	Location        string
	Facets          map[string]string // formal facet key -> display label
	FormalFacets    []string          // filled formal fields, e.g. "Condition: Used - Good"
	AlreadySelected []Suggestion
}

type Suggestion

type Suggestion struct {
	Label string
	Value string
}

func GenerateSuggestions

func GenerateSuggestions(in SuggestInput) ([]Suggestion, error)

func ParseFormSuggestion

func ParseFormSuggestion(raw string) (Suggestion, bool)

ParseFormSuggestion parses an encoded form checkbox value into a normalized suggestion.

func (Suggestion) Display

func (s Suggestion) Display() string

func (Suggestion) Key

func (s Suggestion) Key() string

func (Suggestion) PromptDisplay

func (s Suggestion) PromptDisplay() string

PromptDisplay formats a suggestion for LLM context (includes ": yes" for binary).

type TopAdClick

type TopAdClick struct {
	AdID         int        `db:"ad_id"`
	Title        string     `db:"title"`
	CategoryName string     `db:"category_name"`
	UserCount    int        `db:"user_count"`
	AdViews      int        `db:"ad_views"`
	ImageClicks  int        `db:"image_clicks"`
	LastActivity *time.Time `db:"last_activity"`
}

func GetTopAdsByClicks

func GetTopAdsByClicks(limit int) ([]TopAdClick, error)

type TopImageClick

type TopImageClick struct {
	AdID          int        `db:"ad_id"`
	Title         string     `db:"title"`
	ImageIndex    int        `db:"image_index"`
	UserCount     int        `db:"user_count"`
	Clicks        int        `db:"clicks"`
	LastClickedAt *time.Time `db:"last_clicked_at"`
}

func GetTopImagesByClicks

func GetTopImagesByClicks(limit int) ([]TopImageClick, error)

type TopUserClick

type TopUserClick struct {
	UserID      int        `db:"user_id"`
	AdClicks    int        `db:"ad_clicks"`
	ImageClicks int        `db:"image_clicks"`
	LastActive  *time.Time `db:"last_active"`
}

func GetTopUsersByClicks

func GetTopUsersByClicks(limit int) ([]TopUserClick, error)

type UpdateInput

type UpdateInput struct {
	AdID         int
	UserID       int
	Title        string
	Description  string
	LocationText string
	Facets       map[string]facet.Value
	Suggestions  []Suggestion
	ImagesAdded  int
	ImageOrder   []int
	ImageStore   imagestore.Store
	Tz           *time.Location
	Now          time.Time
}

Jump to

Keyboard shortcuts

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