//DailyUpdate is the handler for POST /internal
DailyUpdate is the handler for POST /internal
// DailyUpdate is the handler for POST / internal
func DailyUpdate(rw http.ResponseWriter, r *http.Request) {
	log.Info("handlers: POST /internal")
	var wg sync.WaitGroup
	dbURL := os.Getenv("DATABASE_URL")
	conn := db.Connect(dbURL)
	defer conn.CloseConnection()
	dErr := exel.Download(exel.FileLocation, exel.AlkoFileURI)
	if dErr != nil {
		log.Errorf("internal: %s\n", dErr)
	}
	drinkExel, rErr := exel.ReadXlsx(exel.FileLocation)
	if rErr != nil {
		log.Errorf("internal: %s\n", rErr)
	}
	deleteErr := conn.DeleteDrinks()
	if deleteErr != nil {
		log.Errorf("internal: %s\n", deleteErr)
	}
	wg.Add(1)
	go func(wg *sync.WaitGroup) {
		defer wg.Done()
		ok, err := conn.InsertDrinks(&drinkExel)
		if !ok {
			log.Errorf("internal: %s", err)
		}
	}(&wg)
	wg.Add(1)
	go func(wg *sync.WaitGroup) {
		defer wg.Done()
		ok, err := conn.CreatePrices(&drinkExel)
		if !ok {
			log.Errorf("internal: %s\n", err)
		}
	}(&wg)
	wg.Wait()
	json.NewEncoder(rw).Encode(map[string]interface{}{"message": "Daily update was succesfull", "date": time.Now()})
}
func DailyUpdate ( rw http . ResponseWriter , r * http . Request ) { log . Info ( " " ) var wg sync . WaitGroup dbURL := os . Getenv ( " " ) conn := db . Connect ( dbURL ) defer conn . CloseConnection ( ) dErr := exel . Download ( exel . FileLocation , exel . AlkoFileURI ) if dErr != nil { log . Errorf ( " \n " , dErr ) } drinkExel , rErr := exel . ReadXlsx ( exel . FileLocation ) if rErr != nil { log . Errorf ( " \n " , rErr ) } deleteErr := conn . DeleteDrinks ( ) if deleteErr != nil { log . Errorf ( " \n " , deleteErr ) } wg . Add ( 1 ) go func ( wg * sync . WaitGroup ) { defer wg . Done ( ) ok , err := conn . InsertDrinks ( & drinkExel ) if ! ok { log . Errorf ( " " , err ) } } ( & wg ) wg . Add ( 1 ) go func ( wg * sync . WaitGroup ) { defer wg . Done ( ) ok , err := conn . CreatePrices ( & drinkExel ) if ! ok { log . Errorf ( " \n " , err ) } } ( & wg ) wg . Wait ( ) json . NewEncoder ( rw ) . Encode ( map [ string ] interface { } { " " : " " , " " : time . Now ( ) } ) }
DailyUpdate is the handler for POST /internal
DailyUpdate is the handler for POST / internal
// download file from alko website // read the downloaded file // delete old rows from drink table // insert new drinks // insert new prices