models

package
v0.0.0-...-82454b5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Street  string `json:"street" bson:"street" validate:"required,min=1,max=200"`
	City    string `json:"city" bson:"city" validate:"required,min=1,max=100"`
	State   string `json:"state" bson:"state" validate:"required,min=1,max=100"`
	ZipCode string `json:"zip_code" bson:"zip_code" validate:"required,min=1,max=20"`
	Country string `json:"country" bson:"country" validate:"required,min=1,max=100"`
}

Address represents a physical address

type BaseModel

type BaseModel struct {
	ID        string        `json:"id" bson:"id"`
	MongoID   bson.ObjectID `json:"-" bson:"_id,omitempty"`
	CreatedAt time.Time     `json:"created_at" bson:"created_at"`
	UpdatedAt time.Time     `json:"updated_at" bson:"updated_at"`
}

BaseModel contains common fields for all models.

type Condition

type Condition string

Condition represents record condition grading

const (
	ConditionMint    Condition = "mint"
	ConditionNMMinus Condition = "nm-"
	ConditionNM      Condition = "nm"
	ConditionVGPlus  Condition = "vg+"
	ConditionVG      Condition = "vg"
	ConditionGPlus   Condition = "g+"
)

type Format

type Format string

Format represents vinyl record formats

const (
	FormatLP   Format = "lp"
	Format7In  Format = "7in"
	Format10In Format = "10in"
	Format12In Format = "12in"
)

type Genre

type Genre string

Genre represents music genres

const (
	GenreJazz       Genre = "jazz"
	GenreRock       Genre = "rock"
	GenreElectronic Genre = "electronic"
	GenreHipHop     Genre = "hip-hop"
	GenreClassical  Genre = "classical"
	GenreSoul       Genre = "soul"
	GenreFunk       Genre = "funk"
	GenreBlues      Genre = "blues"
)

type Order

type Order struct {
	BaseModel       `bson:",inline"`
	UserID          string      `json:"user_id" bson:"user_id"`
	Items           []OrderItem `json:"items" bson:"items"`
	Total           float64     `json:"total" bson:"total"`
	Status          OrderStatus `json:"status" bson:"status"`
	ShippingAddress Address     `json:"shipping_address" bson:"shipping_address"`
}

Order represents a customer order.

func NewOrder

func NewOrder(p OrderParams) *Order

NewOrder creates a new order with generated ID, calculated total, and timestamps.

type OrderItem

type OrderItem struct {
	RecordID string  `json:"record_id" bson:"record_id"`
	Title    string  `json:"title" bson:"title"`
	Artist   string  `json:"artist" bson:"artist"`
	Price    float64 `json:"price" bson:"price"`
	Quantity int     `json:"quantity" bson:"quantity"`
}

OrderItem represents a single item in an order

type OrderParams

type OrderParams struct {
	UserID          string
	Items           []OrderItem
	ShippingAddress Address
}

OrderParams contains parameters for creating a new order.

type OrderStatus

type OrderStatus string

OrderStatus represents the status of an order

const (
	OrderStatusPending   OrderStatus = "pending"
	OrderStatusConfirmed OrderStatus = "confirmed"
	OrderStatusShipped   OrderStatus = "shipped"
	OrderStatusDelivered OrderStatus = "delivered"
	OrderStatusCancelled OrderStatus = "cancelled"
)

type Record

type Record struct {
	BaseModel     `bson:",inline"`
	Title         string    `json:"title" bson:"title" validate:"required,min=1,max=200"`
	Artist        string    `json:"artist" bson:"artist" validate:"required,min=1,max=100"`
	Year          int       `json:"year" bson:"year" validate:"min=1900,max=2100"`
	Label         string    `json:"label" bson:"label"`
	CatalogNumber string    `json:"catalog_number" bson:"catalog_number"`
	Format        Format    `json:"format" bson:"format" validate:"required,oneof=lp 7in 10in 12in"`
	Genre         Genre     `json:"genre" bson:"genre" validate:"required,oneof=jazz rock electronic hip-hop classical soul funk blues"`
	Condition     Condition `json:"condition" bson:"condition" validate:"required,oneof=mint nm- nm vg+ vg g+"`
	Price         float64   `json:"price" bson:"price" validate:"required,min=0"`
	Stock         int       `json:"stock" bson:"stock" validate:"min=0"`
	Description   string    `json:"description" bson:"description"`
	Archived      bool      `json:"archived" bson:"archived"`
}

Record represents a vinyl record in the catalog.

func NewRecord

func NewRecord(p RecordParams) *Record

NewRecord creates a new record with generated ID and timestamps.

type RecordParams

type RecordParams struct {
	Title         string
	Artist        string
	Year          int
	Label         string
	CatalogNumber string
	Format        Format
	Genre         Genre
	Condition     Condition
	Price         float64
	Stock         int
	Description   string
}

RecordParams contains parameters for creating a new record.

type Role

type Role string

Role represents user roles for auth

const (
	RoleUser  Role = "user"
	RoleAdmin Role = "admin"
)

type User

type User struct {
	BaseModel    `bson:",inline"`
	Email        string  `json:"email" bson:"email" validate:"required,email,lowercase"`
	Name         string  `json:"name" bson:"name" validate:"required,min=2,max=100"`
	PasswordHash string  `json:"-" bson:"password_hash"`
	Address      Address `json:"address" bson:"address"`
	Active       bool    `json:"active" bson:"active"`
	Role         Role    `json:"role" bson:"role"`
}

User represents a store user.

func NewUser

func NewUser(p UserParams) (*User, error)

NewUser creates a new user with generated ID, hashed password, and timestamps.

func (*User) Deactivate

func (u *User) Deactivate()

Deactivate deactivates the user account.

func (*User) Update

func (u *User) Update(name string, address Address)

Update updates the user's profile information.

func (*User) VerifyPassword

func (u *User) VerifyPassword(password string) bool

VerifyPassword checks if the provided password matches the stored hash.

type UserParams

type UserParams struct {
	Email    string
	Name     string
	Password string
	Role     Role
	Address  Address
}

UserParams contains parameters for creating a new user.

Jump to

Keyboard shortcuts

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