/** * file: types/logicprovider.go * author: theo technicguy * license: apache 2.0 * * Logic provider interface */ package types import "errors" var ( ErrIDNotFound = errors.New("identifer not found") ) // UseDatasource creates a LogicProvider bound to the passed // data source, used to persist data. type UseDatasource func(*Datasource) *LogicProvider // A LogicProvidier is the part of the server that implements // the logic of the application. type LogicProvider interface { // CreateProduct creates a new product in the data source // using the passed product. The product ID is updated to // match the one assigned in the data source and the tags // are the full tags assigned. // TODO: Populate product with OFF data. CreateProduct(*Product) error // GetAllProducts returns all products saved in the data // source. GetAllProducts() ([]*Product, error) // GetProductByID returns the product saved in the data // source matching the ID. If no product matches, // GetProductByID returns an empty product and ErrIDNotFound. GetProductByID(uint) (*Product, error) // GetProductsLike returns all products saved in the data // source matching the requested search. If no product // matches, GetProductsLike returns an empty array of // products and a nil error. GetProductsLike(*ProductSearch) ([]*Product, error) // UpdateProduct checks if the product ID exists. If // it does, it updates the product with the ID to match // the data passed. Otherwise, it returns ErrIDNotFound. UpdateProduct(*Product) (*Product, error) // DeleteProduct checks if the product ID exists. If it // does, it requests deletion of the product to the data // source and returns the deleted product. Otherwise, it // returns an empty produt and ErrIDNotFound. DeleteProduct(uint) (*Product, error) // CreateProductTag creates a new product tag in the data // source using the passed tag. The product tag ID is // updated to match the one assigned in the data source. CreateProductTag(*Tag) error // GetAllProductTags returns all product tags saved in // the data source. GetAllProductTags() ([]*Tag, error) // GetProductTagByID and GetProductTagByName return the // product tag matching the ID and name respectively. // If no product tag matches, they both return an empty // product tag and ErrIDNotFound. GetProductTagByID(uint) (*Tag, error) GetProductTagByName(string) (*Tag, error) // GetProductTagsLikeName returns all product tags // matching the requested name. If no product tags match, // GetProductTagsLikeName returns an empty array of // product tags and a nil error. GetProductTagsLikeName(string) ([]*Tag, error) // UpdateProductTag checks if the product tag ID exists. // If it does, it updates the product tag with the ID to // match the data passed. Otherwise, it returns // ErrIDNotFound. UpdateProductTag(*Tag) (*Tag, error) // DeleteProductTag checks if the product tag ID exists. // If it does, it requests deletion of the product tag // to the data source and returns the deleted product tag. // Otherwise, it returns an empty product tag and // ErrIDNotFound. DeleteProductTag(uint) (*Tag, error) }