Exemple #1
0
func (r *RestaurantHandler) get(req *http.Request) *Response {
	ckey, err := ConsumerKey(req)
	if err != nil {
		return missingConsumerKeyResponse()
	}

	var restaurantId string
	if !strings.Contains(req.URL.Path, "mine") {
		restaurantId = req.URL.Path[len(r.basePath):]
	}

	var restaurant *db.Restaurant
	if restaurantId != "" {
		restaurant, err = db.RestaurantById(restaurantId)
	} else {
		restaurant, err = db.RestaurantByKey(ckey)
	}

	if err != nil {
		return errorResponse(err)
	}

	return &Response{Status: http.StatusOK, Data: *restaurant}

}
Exemple #2
0
func main() {
	//	u := db.User{}
	//	u.Email = "*****@*****.**"
	//	u.FirstName = "Kranthi"
	//	u.LastName = "Chalasani"
	//	h := sha256.New()
	//	io.WriteString(h, "venkat")
	//	u.Password = fmt.Sprintf("%x", h.Sum(nil))
	//	u.Phone = "248-470-8466"
	//
	//	fmt.Println(u.Create())

	//	usr, err := db.UserByEmail("*****@*****.**")
	//	if err != nil{
	//		panic(err)
	//	}
	//	usrJson, err := json.Marshal(usr)
	//	if err != nil{
	//		panic(err)
	//	}
	//	fmt.Println(string(usrJson))

	//	usr.Email= "*****@*****.**"
	//	fmt.Println(usr.Update())
	//	createUser()
	//	createRestaurant()
	restaurant, err := db.RestaurantByKey("ad65d8bee534a388fa9a077d91027100")
	if err != nil {
		panic(err)
	}
	//	sku1 := db.Sku{}
	//	sku1.Price = 8.99
	//	createItem(restaurant.Key, "Chicken Biryani", "Authentic Hyderabadi Biryani", &[]db.Sku{sku1})
	r := service.Response{Status: 200, Data: *restaurant}
	j, _ := json.Marshal(r)
	fmt.Println(string(j))
}