Skip to content

Commit

Permalink
no validation on email id for get product endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
muly committed Jan 14, 2024
1 parent 0bd85a3 commit af29e82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
20 changes: 10 additions & 10 deletions postman/product-track.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "30d91009-2271-4c8e-96e7-ce855e61d7bd",
"_postman_id": "48df846e-6554-4974-bcc4-0fe6b3ef3747",
"name": "product-track",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "4009003"
Expand Down Expand Up @@ -29,43 +29,43 @@
"response": []
},
{
"name": "{{host}}/product",
"name": "{{host}}/track/price",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"url\":\"https://www.flipkart.com/samsung-galaxy-f13-nightsky-green-64-gb/p/itmeadfda1bd23fa?pid=MOBGENJWF4KJTPEN&lid=LSTMOBGENJWF4KJTPENS2XJXA&marketplace=FLIPKART&store=tyy%2F4io&srno=b_1_1&otracker=clp_banner_1_14.bannerX3.BANNER_mobile-phones-store_ARV72AV1ALWY&fm=neo%2Fmerchandising&iid=d2edff5a-41be-41c5-825a-89fbf189399b.MOBGENJWF4KJTPEN.SEARCH&ppt=clp&ppn=mobile-phones-store&ssid=m55kbf5z280000001686801244020\"\n}"
"raw": "{\"url\":\"https://www.flipkart.com/samsung-galaxy-f13-nightsky-green-64-gb/p/itmeadfda1bd23fa?pid=MOBGENJWF4KJTPEN&lid=LSTMOBGENJWF4KJTPENS2XJXA&marketplace=FLIPKART&store=tyy%2F4io&srno=b_1_1&otracker=clp_banner_1_14.bannerX3.BANNER_mobile-phones-store_ARV72AV1ALWY&fm=neo%2Fmerchandising&iid=d2edff5a-41be-41c5-825a-89fbf189399b.MOBGENJWF4KJTPEN.SEARCH&ppt=clp&ppn=mobile-phones-store&ssid=m55kbf5z280000001686801244020\",\n \"min_threshold\": 122,\n \"emailid\":\"[email protected]\"\n}"
},
"url": {
"raw": "{{host}}/product",
"raw": "{{host}}/track/price",
"host": [
"{{host}}"
],
"path": [
"product"
"track",
"price"
]
}
},
"response": []
},
{
"name": "{{host}}/track/price",
"name": "{{host}}/product",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"url\":\"https://www.flipkart.com/samsung-galaxy-f13-nightsky-green-64-gb/p/itmeadfda1bd23fa?pid=MOBGENJWF4KJTPEN&lid=LSTMOBGENJWF4KJTPENS2XJXA&marketplace=FLIPKART&store=tyy%2F4io&srno=b_1_1&otracker=clp_banner_1_14.bannerX3.BANNER_mobile-phones-store_ARV72AV1ALWY&fm=neo%2Fmerchandising&iid=d2edff5a-41be-41c5-825a-89fbf189399b.MOBGENJWF4KJTPEN.SEARCH&ppt=clp&ppn=mobile-phones-store&ssid=m55kbf5z280000001686801244020\",\n \"min_threshold\": 122,\n \"emailid\":\"[email protected]\"\n}"
"raw": "{\n \"url\":\"https://www.flipkart.com/samsung-galaxy-f13-nightsky-green-64-gb/p/itmeadfda1bd23fa?pid=MOBGENJWF4KJTPEN&lid=LSTMOBGENJWF4KJTPENS2XJXA&marketplace=FLIPKART&store=tyy%2F4io&srno=b_1_1&otracker=clp_banner_1_14.bannerX3.BANNER_mobile-phones-store_ARV72AV1ALWY&fm=neo%2Fmerchandising&iid=d2edff5a-41be-41c5-825a-89fbf189399b.MOBGENJWF4KJTPEN.SEARCH&ppt=clp&ppn=mobile-phones-store&ssid=m55kbf5z280000001686801244020\"\n}"
},
"url": {
"raw": "{{host}}/track/price",
"raw": "{{host}}/product",
"host": [
"{{host}}"
],
"path": [
"track",
"price"
"product"
]
}
},
Expand Down
12 changes: 10 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ func readSupportedWebsites() (map[string]bool, error) {
}

func validateAndCleanup(t *trackInput) error {
if t.URL == "" || t.EmailID == "" {
return fmt.Errorf("some of the mandatory fields are missing")

if t.URL == "" {
return fmt.Errorf("product url is mandatory field")
}

if t.TypeOfRequest == requestTypeAvailability ||
t.TypeOfRequest == requestTypePrice {
if t.EmailID == "" {
return fmt.Errorf("email id is mandatory field")
}
}

u, err := url.Parse(t.URL)
Expand Down

0 comments on commit af29e82

Please sign in to comment.