func (repo *Repository) PostSearchAvailability(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse form")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}

	form := forms.New(r.PostForm)

	startDate, err := form.GetTimeObj("start_date")
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse start date")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	endDate, err := form.GetTimeObj("end_date")
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse end date")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}

	laptops, err := repo.DB.SearchAvailabilityForAllLaptops(startDate, endDate)
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't search availability")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusSeeOther)
		return
	}

	if len(laptops) == 0 {
		repo.App.Session.Put(r.Context(), "error", "no availability")
		r.Method = "GET"
		http.Redirect(w, r, "/search-availability", http.StatusSeeOther)
		return
	}

	data := make(map[string]interface{})
	data["laptops"] = laptops

	res := models.Reservation{
		StartDate: startDate,
		EndDate:   endDate,
	}

	repo.App.Session.Put(r.Context(), "reservation", res)

	render.Template(w, r, "choose-laptop.page.html", &models.TemplateData{
		Data: data,
	})
}
// PostSearchAvailability handles request for availability
PostSearchAvailability handles request for availability
// PostSearchAvailability handles request for availability
func (repo *Repository) PostSearchAvailability(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse form")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	form := forms.New(r.PostForm)
	startDate, err := form.GetTimeObj("start_date")
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse start date")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	endDate, err := form.GetTimeObj("end_date")
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse end date")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	laptops, err := repo.DB.SearchAvailabilityForAllLaptops(startDate, endDate)
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't search availability")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusSeeOther)
		return
	}
	if len(laptops) == 0 {
		repo.App.Session.Put(r.Context(), "error", "no availability")
		r.Method = "GET"
		http.Redirect(w, r, "/search-availability", http.StatusSeeOther)
		return
	}
	data := make(map[string]interface{})
	data["laptops"] = laptops
	res := models.Reservation{
		StartDate: startDate,
		EndDate:   endDate,
	}
	repo.App.Session.Put(r.Context(), "reservation", res)
	render.Template(w, r, "choose-laptop.page.html", &models.TemplateData{
		Data: data,
	})
}
func ( repo * Repository ) PostSearchAvailability ( w http . ResponseWriter , r * http . Request ) { err := r . ParseForm ( ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } form := forms . New ( r . PostForm ) startDate , err := form . GetTimeObj ( " " ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } endDate , err := form . GetTimeObj ( " " ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } laptops , err := repo . DB . SearchAvailabilityForAllLaptops ( startDate , endDate ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusSeeOther ) return } if len ( laptops ) == 0 { repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusSeeOther ) return } data := make ( map [ string ] interface { } ) data [ " " ] = laptops res := models . Reservation { StartDate : startDate , EndDate : endDate , } repo . App . Session . Put ( r . Context ( ) , " " , res ) render . Template ( w , r , " " , & models . TemplateData { Data : data , } ) }
PostSearchAvailability handles request for availability
PostSearchAvailability handles request for availability