ready link import fx 1
This commit is contained in:
parent
b2649c95d9
commit
fa8bba5bec
|
|
@ -1,6 +1,7 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"db_service/models"
|
||||
helper "db_service/pkg"
|
||||
"db_service/repositories"
|
||||
"encoding/json"
|
||||
|
|
@ -60,3 +61,35 @@ func ParseLink(w http.ResponseWriter, route *http.Request) {
|
|||
/////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
func ImportLink(w http.ResponseWriter, route *http.Request) {
|
||||
|
||||
var product models.Product
|
||||
|
||||
err := json.NewDecoder(route.Body).Decode(&product)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
/////////////////////////////
|
||||
importRepo, err := repositories.ImporterInstance()
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
//wait until initialization data is loaded to memory
|
||||
importRepo.ImportWGroup.Wait()
|
||||
|
||||
if err = importRepo.UpdateOrCreate(product).Error; err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"msg": "Link parsed successfully",
|
||||
"productGroupId": product.ProductGroupID,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
1
main.go
1
main.go
|
|
@ -49,6 +49,7 @@ func main() {
|
|||
//route.HandleFunc("/init-importer", controller.StartImport)
|
||||
route.HandleFunc("/init-importer", controller.StartProductImport)
|
||||
route.HandleFunc("/parse-link", controller.ParseLink)
|
||||
route.HandleFunc("/import-link", controller.ImportLink).Methods("POST", "GET")
|
||||
err := http.ListenAndServe(os.Getenv("port"), route)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ func SendRequest(method string, endpoint string, values []byte, authKey string)
|
|||
DialContext: (&net.Dialer{
|
||||
Timeout: ConnectMaxWaitTime,
|
||||
}).DialContext,
|
||||
},
|
||||
},gl
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), RequestMaxWaitTime)
|
||||
|
|
|
|||
Loading…
Reference in New Issue