webpurchase

package
v0.0.0-...-da9a50a Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusToBeRenewed  string = "to-be-renewed"
	StatusToBeReturned string = "to-be-returned"
	StatusError        string = "error"
	StatusOk           string = "ok"
)

Purchase status

View Source
const (
	BUY  string = "BUY"
	LOAN string = "LOAN"
)

Enumeration of PurchaseType

Variables

View Source
var ErrNoChange = errors.New("No lines were updated")

ErrNoChange is thrown when an update action does not change any rows (not found)

View Source
var ErrNotFound = errors.New("Purchase not found")

ErrNotFound Error is thrown when a purchase is not found

Functions

This section is empty.

Types

type Purchase

type Purchase struct {
	ID              int64                      `json:"id, omitempty"`
	UUID            string                     `json:"uuid"`
	Publication     webpublication.Publication `json:"publication"`
	User            webuser.User               `json:"user"`
	LicenseUUID     *string                    `json:"licenseUuid,omitempty"`
	Type            string                     `json:"type"`
	TransactionDate time.Time                  `json:"transactionDate, omitempty"`
	StartDate       *time.Time                 `json:"startDate, omitempty"`
	EndDate         *time.Time                 `json:"endDate, omitempty"`
	Status          string                     `json:"status"`
	MaxEndDate      *time.Time                 `json:"maxEndDate, omitempty"`
}

Purchase struct defines a user in json and database PurchaseType: BUY or LOAN

type PurchaseManager

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

func (PurchaseManager) Add

func (pManager PurchaseManager) Add(p Purchase) error

Add a purchase

func (PurchaseManager) GenerateOrGetLicense

func (pManager PurchaseManager) GenerateOrGetLicense(purchase Purchase) (license.License, error)

GenerateOrGetLicense generates a new license associated with a purchase, or gets an existing license, depending on the value of the license id in the purchase.

func (PurchaseManager) Get

func (pManager PurchaseManager) Get(id int64) (Purchase, error)

Get a purchase using its id

func (PurchaseManager) GetByLicenseID

func (pManager PurchaseManager) GetByLicenseID(licenseID string) (Purchase, error)

GetByLicenseID gets a purchase by the associated license id

func (PurchaseManager) GetLicenseStatusDocument

func (pManager PurchaseManager) GetLicenseStatusDocument(purchase Purchase) (licensestatuses.LicenseStatus, error)

GetLicenseStatusDocument gets a license status document associated with a purchase

func (PurchaseManager) GetPartialLicense

func (pManager PurchaseManager) GetPartialLicense(purchase Purchase) (license.License, error)

GetPartialLicense gets the license associated with a purchase, from the license server

func (PurchaseManager) List

func (pManager PurchaseManager) List(page int, pageNum int) func() (Purchase, error)

List all purchases, with pagination

func (PurchaseManager) ListByUser

func (pManager PurchaseManager) ListByUser(userID int64, page int, pageNum int) func() (Purchase, error)

ListByUser lists the purchases of a given user, with pagination

func (PurchaseManager) Update

func (pManager PurchaseManager) Update(p Purchase) error

Update modifies a purchase on a renew or return request parameters: a Purchase structure withID, LicenseUUID, StartDate, EndDate, Status EndDate may be undefined (nil), in which case the lsd server will choose the renew period

type WebPurchase

type WebPurchase interface {
	Get(id int64) (Purchase, error)
	GenerateOrGetLicense(purchase Purchase) (license.License, error)
	GetPartialLicense(purchase Purchase) (license.License, error)
	GetLicenseStatusDocument(purchase Purchase) (licensestatuses.LicenseStatus, error)
	GetByLicenseID(licenseID string) (Purchase, error)
	List(page int, pageNum int) func() (Purchase, error)
	ListByUser(userID int64, page int, pageNum int) func() (Purchase, error)
	Add(p Purchase) error
	Update(p Purchase) error
}

WebPurchase defines possible interactions with DB

func Init

func Init(config config.Configuration, db *sql.DB) (i WebPurchase, err error)

Init initializes the PurchaseManager

Jump to

Keyboard shortcuts

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