LCW IMPORTER GOSHULDY2

This commit is contained in:
merdan 2023-01-26 15:42:58 +05:00
parent 11f5bf96fe
commit fa9ed72c3d
1 changed files with 6 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
helper "db_service/pkg" helper "db_service/pkg"
"db_service/repositories" "db_service/repositories"
"encoding/json" "encoding/json"
"fmt"
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
@ -29,7 +30,7 @@ func ParseLink(w http.ResponseWriter, route *http.Request) {
func ParseLinkLCW(link string,w http.ResponseWriter) { func ParseLinkLCW(link string,w http.ResponseWriter) {
start := time.Now() start := time.Now()
fmt.Println(link)
linkParser := repositories.NewLCWScraper(link) linkParser := repositories.NewLCWScraper(link)
product, err := linkParser.InitProductDetailParsing() product, err := linkParser.InitProductDetailParsing()
@ -39,7 +40,7 @@ func ParseLinkLCW(link string,w http.ResponseWriter) {
json.NewEncoder(w).Encode(map[string]string{ json.NewEncoder(w).Encode(map[string]string{
"msg": err.Error(), "msg": err.Error(),
}) })
fmt.Println(err)
return return
} }
@ -48,6 +49,7 @@ func ParseLinkLCW(link string,w http.ResponseWriter) {
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
fmt.Println(err)
return return
} }
//wait until initialization data is loaded to memory //wait until initialization data is loaded to memory
@ -55,6 +57,7 @@ func ParseLinkLCW(link string,w http.ResponseWriter) {
if err = importRepo.UpdateOrCreate(product).Error; err != nil { if err = importRepo.UpdateOrCreate(product).Error; err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
fmt.Println(err)
return return
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
@ -80,7 +83,7 @@ func ParseLinkTY(link string,w http.ResponseWriter) {
json.NewEncoder(w).Encode(map[string]string{ json.NewEncoder(w).Encode(map[string]string{
"msg": err.Error(), "msg": err.Error(),
}) })
fmt.Println(err)
return return
} }