models

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpdateRating

func UpdateRating[U UpdateableKeyTypes](ctx context.Context, rs *RatingStorage, id int64, values []U) (err error)

Types

type RatingAverage added in v0.7.0

type RatingAverage struct {
	BaseRatingScore float64 `json:"base_rating_score" db:"base_rating_score"`
	//nolint: revive
	SecondaryRatingTypes    *[]string                `` /* 153-byte string literal not displayed */
	SecondaryRatingAverages []SecondaryRatingAverage `json:"secondary_rating_score" db:"secondary_rating_score"`
}

rating average is a helper, "meta"-type so that the averages retrieved are more concise

type RatingInput

type RatingInput struct {
	// TODO: allow for setting dynamic rating scales
	NumStars    int8      `json:"numstars" binding:"required" validate:"min=0,max=10" error:"numstars must be between 1 and 15" db:"stars"`
	Comment     string    `json:"comment,omitempty" db:"comment"`
	Topic       string    `json:"topic,omitempty" db:"topic"`
	Attribution string    `json:"attribution,omitempty" db:"attribution"`
	UserID      uint32    `json:"userid" db:"user_id"`
	MediaID     uuid.UUID `json:"mediaid" db:"media_id"`
}

nolint: revive

type RatingStorage

type RatingStorage struct {
	// contains filtered or unexported fields
}

func NewRatingStorage

func NewRatingStorage(db *pgxpool.Pool, log *zerolog.Logger) *RatingStorage

func (*RatingStorage) Delete

func (rs *RatingStorage) Delete(ctx context.Context, id int64) (err error)

func (*RatingStorage) Get

func (rs *RatingStorage) Get(ctx context.Context, id int64) (r *Review, err error)

Get retrieves a rating by its id.

func (*RatingStorage) GetAll

func (rs *RatingStorage) GetAll() (ratings []*Review, err error)

GetAll gets all the reviews

func (*RatingStorage) GetAverageStars

func (rs *RatingStorage) GetAverageStars(ctx context.Context,
	mediaID uuid.UUID,
) (avgStars float64, err error)

func (*RatingStorage) GetByMediaID

func (rs *RatingStorage) GetByMediaID(ctx context.Context, mediaID uuid.UUID) (ratings []*Review, err error)

func (*RatingStorage) GetLatest

func (rs *RatingStorage) GetLatest(ctx context.Context, limit int, offset int) (ratings []*Review, err error)

GetLatestRatings retrieves the latest reviews for all media items. The limit and offset parameters are used for pagination.

func (*RatingStorage) New

func (rs *RatingStorage) New(ctx context.Context, rating *RatingInput) error

type RatingStorer

type RatingStorer interface {
	New(ri *RatingInput) error
	Get(ctx context.Context, ID int64) (*Review, error)
	GetAll() ([]*Review, error)
	GetByMediaID(ctx context.Context, mediaID uuid.UUID) ([]*Review, error)
}

Update is not present, because methods cannot have type parameters

type Review added in v0.7.0

type Review struct {
	ID               int64              `json:"_key" db:"id,pk"`
	CreatedAt        time.Time          `json:"created_at" db:"created_at"`
	NumStars         int8               `json:"numstars" binding:"required" validate:"min=0,max=10" error:"numstars must be between 1 and 10" db:"stars" `
	Body             string             `json:"comment,omitempty" db:"body"`
	Topic            string             `json:"topic,omitempty" db:"topic"`
	Attribution      string             `json:"attribution,omitempty" db:"attribution"`
	UserID           uint32             `json:"userid" db:"user_id"`
	MediaID          uuid.UUID          `json:"mediaid" db:"media_id"`
	SecondaryRatings []*SecondaryRating `json:"secondary_ratings,omitempty" db:"secondary_ratings"`
}

nolint: revive

type SecondaryRating added in v0.7.0

type SecondaryRating struct {
	ID       int64      `json:"_key" db:"id,pk"`
	MediaID  *uuid.UUID `json:"media_id" db:"media_id"`
	Kind     string     `json:"kind" validate:"required,oneof=track plotline soundtrack acting scenography scenario theme" db:"kind"`
	NumStars int8       `json:"numstars" binding:"required" validate:"min=1,max=10,error='numstars must be between 1 and 10'" db:"stars"`
	UserID   uint32     `json:"userid" db:"user_id"`
}

TODO: add migration nolint: revive

type SecondaryRatingAverage added in v0.7.0

type SecondaryRatingAverage struct {
	MediaID   uuid.UUID `json:"_key" db:"media_id,pk"`
	MediaKind string    `json:"media_kind" db:"media_kind"`
	Score     float64   `json:"score,omitempty" db:"score"`
}

TODO: add migration (if needed) SecondaryRatingAverages is a map of (secondary rating's) kind to it's value

type UpdateableKeyTypes

type UpdateableKeyTypes interface {
	~int | ~uint | string
}

Directories

Path Synopsis
This package handles the retrieval of data from the CouchDB search database Synchronization is handled by triggers in the database using the http postgresql extension, without the need for postgres->application->couchdb->app->postgres- round trip (we need to store the returned document id to ensure deduplication)
This package handles the retrieval of data from the CouchDB search database Synchronization is handled by triggers in the database using the http postgresql extension, without the need for postgres->application->couchdb->app->postgres- round trip (we need to store the returned document id to ensure deduplication)

Jump to

Keyboard shortcuts

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