diff --git a/backend/app/api/handlers/v1/v1_ctrl_qrcode.go b/backend/app/api/handlers/v1/v1_ctrl_qrcode.go index 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 Bearer func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) errchain.HandlerFunc { @@ -217,13 +195,13 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) err log.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) err log.Error().Msg("Can not unmarshal JSON") } - var res []BarcodeProduct + var res []repo.BarcodeProduct for _, it := range result.Items { - var p BarcodeProduct + var p repo.BarcodeProduct p.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.BarcodeProduct p.Barcode = iEan p.SearchEngineName = "barcodespider.com" p.Item.Name = result.ItemAttributes.Title @@ -316,7 +294,7 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) err p.ModelNumber = result.ItemAttributes.Model p.ImageURL = result.ItemAttributes.Image - var res []BarcodeProduct + var res []repo.BarcodeProduct res = append(res, p) return res, nil @@ -383,7 +361,7 @@ func (ctrl *V1Controller) HandleProductSearchEAN(conf config.BarcodeAPIConf) err if 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 nil diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 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.json index 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.yaml index 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: object repo.Group: properties: createdAt: @@ -1564,7 +1585,9 @@ paths: "200": description: OK schema: - $ref: '#/definitions/repo.ItemCreate' + items: + $ref: '#/definitions/repo.BarcodeProduct' + type: array security: - Bearer: [] summary: Search EAN from Barcode diff --git a/backend/internal/data/repo/repo_product_search.go b/backend/internal/data/repo/repo_product_search.go new file mode 100644 index 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.json index 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.yaml index 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: object repo.Group: properties: createdAt: @@ -1564,7 +1585,9 @@ paths: "200": description: OK schema: - $ref: '#/definitions/repo.ItemCreate' + items: + $ref: '#/definitions/repo.BarcodeProduct' + type: array security: - Bearer: [] summary: Search EAN from Barcode diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index 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;