domain

package
v0.0.0-...-6f8c8e2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Product

type Product struct {
	ID   int
	Name string
}

Product represents a simple product information model

type ProductRepository

type ProductRepository interface {
	List(ctx context.Context) ([]*Product, error)
	Get(ctx context.Context, id int) (*Product, error)
}

ProductRepository can retrieve product information

type Rating

type Rating struct {
	ID        int       `db:"id"`
	UserName  string    `db:"name"`
	ProductID int       `db:"product_id"`
	CreatedAt time.Time `db:"created_at"`
	Title     string    `db:"title"`
	Text      string    `db:"text"`
	Stars     int       `db:"stars"`
}

Rating represents a single product rating

type RatingAmounts

type RatingAmounts map[int]int

RatingAmounts represents the number of ratings by product ID

type RatingAverage

type RatingAverage struct {
	Value  float64
	Amount int
	Max    int
	Stars  int
}

RatingAverage represents the mean of a set of ratings

type RatingBreakdown

type RatingBreakdown struct {
	Stars      int
	Amount     int
	Total      int
	Percentage float64
}

RatingBreakdown represents the amount of n-stars ratings for a set of ratings

type RatingRepository

type RatingRepository interface {
	Count(ctx context.Context) (int64, error)
	CountByProductID(ctx context.Context, pid int) (int64, error)
	List(ctx context.Context) ([]*Rating, error)
	ListByProductID(ctx context.Context, pid int) ([]*Rating, error)
	Get(ctx context.Context, id int) (*Rating, error)
	Save(ctx context.Context, rating *Rating) error
	Delete(ctx context.Context, rating *Rating) error
	Amounts(ctx context.Context) (*RatingAmounts, error)
	Average(ctx context.Context) (*RatingAverage, error)
	AverageByProductID(ctx context.Context, pid int) (*RatingAverage, error)
	Breakdown(ctx context.Context) ([]*RatingBreakdown, error)
	BreakdownByProductID(ctx context.Context, pid int) ([]*RatingBreakdown, error)
}

RatingRepository provides all functions for Rating storage

Jump to

Keyboard shortcuts

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