A continuation of HomeBox the inventory and organization system built for the Home User
ProductBarcode: return an array of BarcodeProduct instead of one
Crumb Owla3c13a8a743c
diff --git a/backend/app/api/handlers/v1/v1_ctrl_qrcode.go b/backend/app/api/handlers/v1/v1_ctrl_qrcode.goindex d6d4fa55..a76c5ef1 100644--- a/backend/app/api/handlers/v1/v1_ctrl_qrcode.go+++ b/backend/app/api/handlers/v1/v1_ctrl_qrcode.go@@ -77,28 +77,6 @@ func (ctrl *V1Controller) HandleGenerateQRCode() errchain.HandlerFunc {}}-type BarcodeProduct struct {- SearchEngineName string `json:"search_engine_name"`-- //Name string `json:"name" validate:"required,min=1,max=255"`- //Description string `json:"description" validate:"max=1000"`-- // Identifications- ModelNumber string `json:"modelNumber"`- Manufacturer string `json:"manufacturer"`-- // Extras- Country string `json:"notes"`- Barcode string `json:"barcode"`-- // TODO: add image attachement- // TODO: add asin?- ImageURL string `json:"imageURL"`- ImageBase64 string `json:"imageBase64"`-- Item repo.ItemCreate `json:"item"`-}-/*ImportRef string `json:"-"`ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`@@ -191,7 +169,7 @@ type BARCODESPIDER_COMResponse struct {// @Tags Items// @Produce json// @Param data query string false "barcode to be searched"-// @Success 200 {object} repo.ItemCreate+// @Success 200 {object} []repo.BarcodeProduct// @Router /v1/getproductfromean [GET]// @Security Bearerfunc (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) errchain.HandlerFunc {@@ -217,13 +195,13 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) errlog.Info().Msg("========================" + q.EAN)// Search on UPCITEMDB- var products []BarcodeProduct+ var products []repo.BarcodeProduct// www.ean-search.org/: not free// Example code: dewalt 5035048748428- upcitemdb := func(iEan string) ([]BarcodeProduct, error) {+ upcitemdb := func(iEan string) ([]repo.BarcodeProduct, error) {resp, err := http.Get("https://api.upcitemdb.com/prod/trial/lookup?upc=" + iEan)if err != nil {return nil, err@@ -243,10 +221,10 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) errlog.Error().Msg("Can not unmarshal JSON")}- var res []BarcodeProduct+ var res []repo.BarcodeProductfor _, it := range result.Items {- var p BarcodeProduct+ var p repo.BarcodeProductp.SearchEngineName = "upcitemdb.com"p.Barcode = iEan@@ -270,7 +248,7 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) err}// Barcode spider implementation- barcodespider := func(tokenAPI string, iEan string) ([]BarcodeProduct, error) {+ barcodespider := func(tokenAPI string, iEan string) ([]repo.BarcodeProduct, error) {if len(tokenAPI) == 0 {return nil, errors.New("no api token configured for barcodespider")@@ -307,7 +285,7 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) err}// TODO: check 200 code on HTTP repsonse.- var p BarcodeProduct+ var p repo.BarcodeProductp.Barcode = iEanp.SearchEngineName = "barcodespider.com"p.Item.Name = result.ItemAttributes.Title@@ -316,7 +294,7 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) errp.ModelNumber = result.ItemAttributes.Modelp.ImageURL = result.ItemAttributes.Image- var res []BarcodeProduct+ var res []repo.BarcodeProductres = append(res, p)return res, nil@@ -383,7 +361,7 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) errif len(products) != 0 {// Return only the first result for now. Enhance this with a dedicated dialog// displaying all the references found?- return json.NewEncoder(w).Encode(products[0])+ return json.NewEncoder(w).Encode(products)}return nildiff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.goindex bb267d57..3df008bb 100644--- a/backend/app/api/static/docs/docs.go+++ b/backend/app/api/static/docs/docs.go@@ -221,7 +221,10 @@ const docTemplate = `{"200": {"description": "OK","schema": {- "$ref": "#/definitions/repo.ItemCreate"+ "type": "array",+ "items": {+ "$ref": "#/definitions/repo.BarcodeProduct"+ }}}}@@ -3095,6 +3098,37 @@ const docTemplate = `{"TypeTime"]},+ "repo.BarcodeProduct": {+ "type": "object",+ "properties": {+ "barcode": {+ "type": "string"+ },+ "imageBase64": {+ "type": "string"+ },+ "imageURL": {+ "type": "string"+ },+ "item": {+ "$ref": "#/definitions/repo.ItemCreate"+ },+ "manufacturer": {+ "type": "string"+ },+ "modelNumber": {+ "description": "Identifications",+ "type": "string"+ },+ "notes": {+ "description": "Extras",+ "type": "string"+ },+ "search_engine_name": {+ "type": "string"+ }+ }+ },"repo.Group": {"type": "object","properties": {diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.jsonindex a8493f57..1c01d28e 100644--- a/backend/app/api/static/docs/swagger.json+++ b/backend/app/api/static/docs/swagger.json@@ -219,7 +219,10 @@"200": {"description": "OK","schema": {- "$ref": "#/definitions/repo.ItemCreate"+ "type": "array",+ "items": {+ "$ref": "#/definitions/repo.BarcodeProduct"+ }}}}@@ -3093,6 +3096,37 @@"TypeTime"]},+ "repo.BarcodeProduct": {+ "type": "object",+ "properties": {+ "barcode": {+ "type": "string"+ },+ "imageBase64": {+ "type": "string"+ },+ "imageURL": {+ "type": "string"+ },+ "item": {+ "$ref": "#/definitions/repo.ItemCreate"+ },+ "manufacturer": {+ "type": "string"+ },+ "modelNumber": {+ "description": "Identifications",+ "type": "string"+ },+ "notes": {+ "description": "Extras",+ "type": "string"+ },+ "search_engine_name": {+ "type": "string"+ }+ }+ },"repo.Group": {"type": "object","properties": {diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yamlindex babde081..9d4bc3a9 100644--- a/backend/app/api/static/docs/swagger.yaml+++ b/backend/app/api/static/docs/swagger.yaml@@ -646,6 +646,27 @@ definitions:- TypeNumber- TypeBoolean- TypeTime+ repo.BarcodeProduct:+ properties:+ barcode:+ type: string+ imageBase64:+ type: string+ imageURL:+ type: string+ item:+ $ref: '#/definitions/repo.ItemCreate'+ manufacturer:+ type: string+ modelNumber:+ description: Identifications+ type: string+ notes:+ description: Extras+ type: string+ search_engine_name:+ type: string+ type: objectrepo.Group:properties:createdAt:@@ -1564,7 +1585,9 @@ paths:"200":description: OKschema:- $ref: '#/definitions/repo.ItemCreate'+ items:+ $ref: '#/definitions/repo.BarcodeProduct'+ type: arraysecurity:- Bearer: []summary: Search EAN from Barcodediff --git a/backend/internal/data/repo/repo_product_search.go b/backend/internal/data/repo/repo_product_search.gonew file mode 100644index 00000000..3e0c6b15--- /dev/null+++ b/backend/internal/data/repo/repo_product_search.go@@ -0,0 +1,18 @@+package repo++type BarcodeProduct struct {+ SearchEngineName string `json:"search_engine_name"`++ // Identifications+ ModelNumber string `json:"modelNumber"`+ Manufacturer string `json:"manufacturer"`++ // Extras+ Country string `json:"notes"`+ Barcode string `json:"barcode"`++ ImageURL string `json:"imageURL"`+ ImageBase64 string `json:"imageBase64"`++ Item ItemCreate `json:"item"`+}diff --git a/docs/en/api/openapi-2.0.json b/docs/en/api/openapi-2.0.jsonindex a8493f57..1c01d28e 100644--- a/docs/en/api/openapi-2.0.json+++ b/docs/en/api/openapi-2.0.json@@ -219,7 +219,10 @@"200": {"description": "OK","schema": {- "$ref": "#/definitions/repo.ItemCreate"+ "type": "array",+ "items": {+ "$ref": "#/definitions/repo.BarcodeProduct"+ }}}}@@ -3093,6 +3096,37 @@"TypeTime"]},+ "repo.BarcodeProduct": {+ "type": "object",+ "properties": {+ "barcode": {+ "type": "string"+ },+ "imageBase64": {+ "type": "string"+ },+ "imageURL": {+ "type": "string"+ },+ "item": {+ "$ref": "#/definitions/repo.ItemCreate"+ },+ "manufacturer": {+ "type": "string"+ },+ "modelNumber": {+ "description": "Identifications",+ "type": "string"+ },+ "notes": {+ "description": "Extras",+ "type": "string"+ },+ "search_engine_name": {+ "type": "string"+ }+ }+ },"repo.Group": {"type": "object","properties": {diff --git a/docs/en/api/openapi-2.0.yaml b/docs/en/api/openapi-2.0.yamlindex babde081..9d4bc3a9 100644--- a/docs/en/api/openapi-2.0.yaml+++ b/docs/en/api/openapi-2.0.yaml@@ -646,6 +646,27 @@ definitions:- TypeNumber- TypeBoolean- TypeTime+ repo.BarcodeProduct:+ properties:+ barcode:+ type: string+ imageBase64:+ type: string+ imageURL:+ type: string+ item:+ $ref: '#/definitions/repo.ItemCreate'+ manufacturer:+ type: string+ modelNumber:+ description: Identifications+ type: string+ notes:+ description: Extras+ type: string+ search_engine_name:+ type: string+ type: objectrepo.Group:properties:createdAt:@@ -1564,7 +1585,9 @@ paths:"200":description: OKschema:- $ref: '#/definitions/repo.ItemCreate'+ items:+ $ref: '#/definitions/repo.BarcodeProduct'+ type: arraysecurity:- Bearer: []summary: Search EAN from Barcodediff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.tsindex f7876439..3ae47355 100644--- a/frontend/lib/api/types/data-contracts.ts+++ b/frontend/lib/api/types/data-contracts.ts@@ -451,6 +451,23 @@ export interface EntUserEdges {notifiers: EntNotifier[];}+export interface BarcodeProduct {+ barcode: string;+ imageBase64: string;+ /**+ * TODO: add image attachement+ * TODO: add asin?+ */+ imageURL: string;+ item: ItemCreate;+ manufacturer: string;+ /** Identifications */+ modelNumber: string;+ /** Extras */+ notes: string;+ search_engine_name: string;+}+export interface Group {createdAt: Date | string;currency: string;