Пример #1
0
func SetMaxOccupancy(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	var auth S.AuthToken

	var maxOccupancy int
	var date string

	for k, v := range r.Form {
		if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "date" {
			date = strings.Join(v, "")
		} else if k == "maxOccupancy" {
			date = strings.Join(v, "")
		} else {
			auth.Code = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) {
		fmt.Fprintf(w, "Please login")
		return
	}

	if db.HasHotel(auth) {
		fmt.Fprintf(w, db.SetMaxOccupancy(auth, maxOccupancy, date))
	} else {
		fmt.Fprintf(w, "You do not work for a hotel")
	}
}
Пример #2
0
func SetMaxOccupancy(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")

	r.ParseForm()

	var auth S.AuthToken

	var maxOccupancy string
	var date string
	hotel := "none"

	for k, v := range r.Form {
        if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "date" {
			date = strings.Join(v, "")
		} else if k == "maxOccupancy" {
			maxOccupancy = strings.Join(v, "")
		} else if k == "hotel" {
			hotel = strings.Join(v, "")
		} else if k == "code" {
			auth.Code = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) || hotel == "none" {
		fmt.Fprintf(w, "{\"Please login\"}")
		return
	}


	maxOccupancyInt, err := strconv.Atoi(maxOccupancy)
	if err != nil {
		fmt.Fprintf(w, "{\"ERROR\":1}")
		return
	}

	fail := "0"

	if db.SetMaxOccupancy(date, hotel, maxOccupancyInt) {
		fail = "1"
	}
	fmt.Fprintf(w, "{" + fail + "}")

	// if db.HasHotel(auth) {
	// 	fmt.Fprintf(w, db.SetMaxOccupancy(auth, maxOccupancy, date))
	// } else {
	// 	fmt.Fprintf(w, "You do not work for a hotel")
	// }
}