productdata

package
v0.0.0-...-edcd610 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Apache v2 license

* Copyright (C) <2019> Intel Corporation * * SPDX-License-Identifier: Apache-2.0

Apache v2 license

* Copyright (C) <2019> Intel Corporation * * SPDX-License-Identifier: Apache-2.0

Apache v2 license

* Copyright (C) <2019> Intel Corporation * * SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const DbSchema = `` /* 210-byte string literal not displayed */

DbSchema postgresql db schema

View Source
const Schema = `` /* 1924-byte string literal not displayed */

Schema represents the schema for input data for RESTFul POST API

Variables

This section is empty.

Functions

func GroupBySku

func GroupBySku(prodDataSlice []SKUData) map[string][]SKUData

GroupBySku creates a map of SKUData with sku as key and groups same sku object.

func Insert

func Insert(db *sql.DB, skuData []SKUData) error

Insert receives a slice of sku mapping and inserts them to the database

func Retrieve

func Retrieve(db *sql.DB, query url.Values, maxSize int) ([]SKUData, *CountType, error)

Retrieve gets the data out of the DB

Types

type CountType

type CountType struct {
	Count int `json:"count"`
}

CountType is used to hold the total count

type IncomingData

type IncomingData struct {
	// the Broker calls this `upc`, even though it could be any type of product ID
	ProductID        string                 `json:"upc"`
	SKU              string                 `json:"sku"`
	BeingRead        float64                `json:"beingRead"`
	BecomingReadable float64                `json:"becomingReadable"`
	ExitError        float64                `json:"exitError"`
	DailyTurn        float64                `json:"dailyTurn"`
	Metadata         map[string]interface{} `json:"metadata"`
}

IncomingData represents the struct of the raw data coming from the Broker.

Although it may have the same "shape" as the ProductData, the json attributes may be different, but must be correctly mapped to the database model.

type ProductData

type ProductData struct {
	// ProductID is the "formal" ID for a product, often a GTIN
	ProductID        string  `json:"productId" db:"productId"`
	BeingRead        float64 `json:"beingRead" db:"beingRead"`
	BecomingReadable float64 `json:"becomingReadable" db:"becomingReadable"`
	ExitError        float64 `json:"exitError" db:"exitError"`
	DailyTurn        float64 `json:"dailyTurn" db:"dailyTurn"`
	// Metadata stores arbitrary data about a product
	Metadata map[string]interface{} `json:"metadata"`
}

ProductData models the product's attributes

type Root

type Root struct {
	//in: body
	Data []SKUData `json:"data"`
}

Root - Main struct for input swagger:parameters postSkus

type SKUData

type SKUData struct {
	// SKU represents an identifier a business uses for a product or collection of products
	SKU string `json:"sku" db:"sku"`
	// ProductList connects one or more products to the same SKU
	ProductList []ProductData `json:"productList" db:"productList"`
}

SKUData connects a SKU to its list of products

func GetProductMetadata

func GetProductMetadata(db *sql.DB, productID string) (SKUData, error)

GetProductMetadata receives a product ID (upc) and looks up and returns the corresponding metadata

func MapBySku

func MapBySku(prodDataMap map[string][]SKUData) []SKUData

MapBySku appends Product and Metadata to ProductList array

func (*SKUData) Scan

func (s *SKUData) Scan(value interface{}) error

Scan implements sql.Scanner inferfaces

func (SKUData) Value

func (s SKUData) Value() (driver.Value, error)

Value implements driver.Valuer inferfaces

Jump to

Keyboard shortcuts

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