func (repo *Repository) RentLaptop(w http.ResponseWriter, r *http.Request) {
	_ = r.ParseForm()

	LaptopID, err := strconv.Atoi(r.URL.Query().Get("id"))
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "invalid Laptop ID")
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}

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

	var res models.Reservation
	res.LaptopID = LaptopID
	res.StartDate = startDate
	res.EndDate = endDate

	laptop, err := repo.DB.GetLaptopByID(res.LaptopID)
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "error connecting to the database")
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}

	res.Laptop.LaptopName = laptop.LaptopName

	repo.App.Session.Put(r.Context(), "reservation", res)
	http.Redirect(w, r, "/make-reservation", http.StatusSeeOther)
}
// RentLaptop takes URL parameters, builds a sessional variable, and takes user to make reservation page
RentLaptop takes URL parameters, builds a sessional variable, and takes user to make reservation page
// RentLaptop takes URL parameters builds a sessional variable and takes user to make reservation page
func (repo *Repository) RentLaptop(w http.ResponseWriter, r *http.Request) {
	_ = r.ParseForm()
	LaptopID, err := strconv.Atoi(r.URL.Query().Get("id"))
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "invalid Laptop ID")
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	form := forms.New(r.Form)
	startDate, err := form.GetTimeObj("s")
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse start date")
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	endDate, err := form.GetTimeObj("e")
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse end date")
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	var res models.Reservation
	res.LaptopID = LaptopID
	res.StartDate = startDate
	res.EndDate = endDate
	laptop, err := repo.DB.GetLaptopByID(res.LaptopID)
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "error connecting to the database")
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	res.Laptop.LaptopName = laptop.LaptopName
	repo.App.Session.Put(r.Context(), "reservation", res)
	http.Redirect(w, r, "/make-reservation", http.StatusSeeOther)
}
func ( repo * Repository ) RentLaptop ( w http . ResponseWriter , r * http . Request ) { _ = r . ParseForm ( ) LaptopID , err := strconv . Atoi ( r . URL . Query ( ) . Get ( " " ) ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } form := forms . New ( r . Form ) startDate , err := form . GetTimeObj ( " " ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } endDate , err := form . GetTimeObj ( " " ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } var res models . Reservation res . LaptopID = LaptopID res . StartDate = startDate res . EndDate = endDate laptop , err := repo . DB . GetLaptopByID ( res . LaptopID ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } res . Laptop . LaptopName = laptop . LaptopName repo . App . Session . Put ( r . Context ( ) , " " , res ) http . Redirect ( w , r , " " , http . StatusSeeOther ) }
RentLaptop takes URL parameters, builds a sessional variable, and takes user to make reservation page
RentLaptop takes URL parameters builds a sessional variable and takes user to make reservation page