anor

package module
v0.0.0-...-990eb5e Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 5 Imported by: 0

README

anor

Anor is a fullstack ecommerce app built with go/htmx (still in heavy development process).

Getting started

Make sure you have docker/docker compose, sqlc, goose and task installed in your machine

First start Postgres and Typesense:

    task compose-up

Then, run database migrations:

    task goose-up

and import sample data into database using:

    task import-dataset

Now you can start the app:

    export CONFIG_FILEPATH=./config.dev.yaml
    go run cmd/anor/*.go

Project starts on port 8008 by default.

Testing

Coming soon

Documentation

Index

Constants

View Source
const (
	EINTERNALMSG = "Something went wrong. Please try again later."
)

Variables

View Source
var (
	ErrNotFound   = errors.New("not found")
	ErrUserExists = errors.New("user exists")
)

Functions

func NewContextWithUser

func NewContextWithUser(ctx context.Context, u *User) context.Context

NewContextWithUser NewContext returns a new Context that carries value u.

Types

type AuthService

type AuthService interface {
	Signup(ctx context.Context, name, email, password string) error
	SignupConfirm(ctx context.Context, otp, email string) error
	Signin(ctx context.Context, email, password string) (int64, error)
	ResendOTP(ctx context.Context, email string) error
	SendResetPasswordLink(ctx context.Context, email string) error
	VerifyResetPasswordToken(ctx context.Context, token string) (bool, error)
	ResetPassword(ctx context.Context, token string, password string) error
}

type BaseProduct

type BaseProduct struct {
	ID           int64
	StoreID      int32
	CategoryID   int32
	Name         string
	Brand        string
	Slug         string
	ShortInfo    []string
	ThumbImg     string // thumbnail image link
	ThumbImgUrls map[string]string
	ImageLinks   map[int]string
	Specs        map[string]string // product item specifications, e.g. Ebay
	Status       ProductStatus
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type Category

type Category struct {
	ID       int32
	Category string
	Slug     string
	ParentID int32

	IsLeafCategory bool
}

func (Category) IsLeaf

func (c Category) IsLeaf() bool

func (Category) IsRoot

func (c Category) IsRoot() bool

type CategoryService

type CategoryService interface {
	GetCategory(ctx context.Context, id int32) (Category, error)
	GetAncestorCategories(ctx context.Context, id int32) ([]Category, error)
	GetSiblingCategories(ctx context.Context, id int32) ([]Category, error)
	GetChildCategories(ctx context.Context, id int32) ([]Category, error)
}

type FilterOption

type FilterOption struct {
	Rating     int
	PriceRange [2]float32
	Brands     []string
	Colors     []string
	Sizes      []string
}

type GetProductsByCategoryParams

type GetProductsByCategoryParams struct {
	FilterOption FilterOption
	SortOption   SortOption
	Offset       int
	Limit        int
}

type Product

type Product struct {
	BaseProduct
	Store     SellerStore
	Category  Category
	SKUs      []SKU
	Pricing   ProductPricing
	Rating    Rating          // Rating is calculated using Reviews (in the future, using also some statistical method)
	Reviews   []ProductRating // Product Reviews
	SoldCount int
	LeftCount int

	Attributes map[string][]string // attributes with their values, e.g. color, size
}

type ProductPricing

type ProductPricing struct {
	ProductID        int64
	BasePrice        decimal.Decimal
	CurrencyCode     string
	DiscountLevel    decimal.Decimal
	DiscountedAmount decimal.Decimal
	IsOnSale         bool
}

type ProductRating

type ProductRating struct {
	ID         int64
	ProductID  int64
	UserID     int64
	Rating     int16
	Review     string
	ImageLinks []string
	CreatedAt  time.Time
}

type ProductService

type ProductService interface {
	GetProduct(ctx context.Context, id int64) (*Product, error)
	GetProductsByLeafCategoryID(ctx context.Context, categoryID int32, params GetProductsByCategoryParams) ([]Product, int64, error)
	GetProductsByNonLeafCategoryID(ctx context.Context, categoryID int32, params GetProductsByCategoryParams) ([]Product, int64, error)
}

type ProductStatus

type ProductStatus string
const (
	ProductStatusDraft           ProductStatus = "Draft"
	ProductStatusPendingApproval ProductStatus = "PendingApproval"
	ProductStatusActive          ProductStatus = "Active"
)

type Rating

type Rating struct {
	Rating      float32
	RatingCount int
}

type Role

type Role string
const (
	RoleCustomer Role = "user"
	RoleSeller   Role = "seller"
	RoleAdmin    Role = "admin"
)

type SKU

type SKU struct {
	ID              int64
	SKU             string
	QuantityInStock int32
	HasSepPricing   bool
	ImageRefs       []int16
	Attributes      map[string]string
	Pricing         SKUPricing
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

type SKUPricing

type SKUPricing struct {
	SkuID            int64
	BasePrice        decimal.Decimal
	CurrencyCode     string
	DiscountLevel    decimal.Decimal
	DiscountedAmount decimal.Decimal
	IsOnSale         bool
}

type SellerStore

type SellerStore struct {
	ID          int32
	PublicID    string
	SellerID    int64
	Name        string
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type SortOption

type SortOption string
const (
	SortOptionBestMatch      SortOption = "BestMatch"
	SortOptionPriceHighToLow SortOption = "PriceHighToLow"
	SortOptionPriceLowToHigh SortOption = "PriceLowToHigh"
	SortOptionHighestRated   SortOption = "HighestRated"
	SortOptionNewArrivals    SortOption = "NewArrivals"
	SortOptionBestSellers    SortOption = "BestSellers"
)

type User

type User struct {
	ID          int64
	Email       string
	Password    string
	PhoneNumber string
	FullName    string
	Status      UserStatus
	OTP         string
	OTPExpiry   int64
	CreatedAt   time.Time
	UpdatedAt   time.Time

	Roles []Role
}

func UserFromContext

func UserFromContext(ctx context.Context) (*User, bool)

UserFromContext FromContext returns the User value stored in ctx, if any.

func (User) GetFirstname

func (u User) GetFirstname() string

type UserService

type UserService interface {
	CreateUser(ctx context.Context, user User) error
	GetUser(ctx context.Context, id int64) (User, error)
	GetUserByEmail(ctx context.Context, email string) (User, error)
	UpdateUserStatus(ctx context.Context, status UserStatus, id int64) error
	UpdateUserOTP(ctx context.Context, id int64, otp string, otpExpiry int64) error
	UpdateUserPassword(ctx context.Context, id int64, password string) error
}

type UserStatus

type UserStatus string
const (
	UserStatusBlocked             UserStatus = "Blocked"
	UserStatusRegistrationPending UserStatus = "RegistrationPending"
	UserStatusActive              UserStatus = "Active"
	UserStatusInactive            UserStatus = "Inactive"
)

Jump to

Keyboard shortcuts

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