Permalink
Browse files

dish

  • Loading branch information...
1 parent 9b0e7da commit f263d2daa78c85a53c850914d6b139b1a8d62887 @rigidus committed Apr 11, 2012
Showing with 137 additions and 119 deletions.
  1. +66 −7 storage/orm.lisp
  2. +71 −112 storage/routes.lisp
View
@@ -25,7 +25,7 @@ alter user <dbuser> with password '<dbpassword>';
(defparameter *db-pass* "resto1111")
(defparameter *db-serv* "localhost")
(defparameter *db-spec* (list *db-name* *db-user* *db-pass* *db-serv*))
-(connect-toplevel *db-name* *db-user* *db-pass* *db-serv*)
+;; (connect-toplevel *db-name* *db-user* *db-pass* *db-serv*)
;; (disconnect-toplevel)
;; produce (and re-init storage table if need) linktable object
@@ -413,10 +413,10 @@ alter user <dbuser> with password '<dbpassword>';
(mv "en" "panoramic"))))
-(print (get-all-entityes-opt-val (select-dao 'shop)
- :entity-func #'(lambda (shop) (list :shop (id shop) (site shop)))
- :optname-func #'(lambda (option) (list :opt (id option) (parent-id option) (name option)))
- :optvalue-func #'(lambda (optval) (list :val (lang-id optval) (val optval)))))
+;; (print (get-all-entityes-opt-val (select-dao 'shop)
+;; :entity-func #'(lambda (shop) (list :shop (id shop) (site shop)))
+;; :optname-func #'(lambda (option) (list :opt (id option) (parent-id option) (name option)))
+;; :optvalue-func #'(lambda (optval) (list :val (lang-id optval) (val optval)))))
;; (((:SHOP 1 "http://macarenabar.ru")
@@ -463,6 +463,65 @@ alter user <dbuser> with password '<dbpassword>';
;; ((:VAL 1 "панорамный")
;; (:VAL 2 "panoramic"))))))
-;; TODO ::: SUBWAYS
-
;; (query-dao 'subway "SELECT * FROM subway WHERE id IN (SELECT subway_id FROM shop_2_subway WHERE shop_id = 1)")
+
+
+;; CATEGORY
+
+(def~daoclass-entity category ()
+ ((id :col-type integer :initform (incf-category-id))
+ (parent-id :col-type integer :initform 0)
+ (image :col-type string :initform "")
+ (code :col-type string :initform ""))
+ (:keys id)
+ (:incf id)
+ (:re-init t)
+ (:re-link t))
+
+(def~daoclass-linktable shop category t)
+
+(defparameter *cold-dishes*
+ (make-dao
+ 'category
+ :code "cold-dishes"))
+
+(let ((i *cold-dishes*))
+ (mo i 0 "name" 0
+ (mv "ru" "Холодные закуски")
+ (mv "en" "Cold dishes")))
+
+(defparameter *hot-dishes*
+ (make-dao
+ 'category
+ :code "hot-dishes"))
+
+(let ((i *hot-dishes*))
+ (mo i 0 "name" 0
+ (mv "ru" "Горячие блюда")
+ (mv "en" "Hot dishes")))
+
+
+(query (:insert-into 'shop_2_category :set 'shop-id (id *makarena*) 'category_id (id *cold-dishes*)))
+(query (:insert-into 'shop_2_category :set 'shop-id (id *makarena*) 'category_id (id *hot-dishes*)))
+
+
+;; PRODUCT
+
+(def~daoclass-entity product ()
+ ((id :col-type integer :initform (incf-product-id))
+ (code :col-type string :initform "")
+ (price :col-type float :initform 0.0)
+ (photo-small :col-type string :initform "")
+ (photo-big :col-type string :initform "")
+ (delivery :col-type integer :initform 0)
+ (rating :col-type float :initform 0.0)
+ (rating_count :col-type integer :initform 0)
+ (comment_count :col-type integer :initform 0))
+ (:keys id)
+ (:incf id)
+ (:re-init t)
+ (:re-link t))
+
+(def~daoclass-linktable shop product t)
+(def~daoclass-linktable category product t)
+
View
@@ -133,6 +133,7 @@
(defun get-shop (item &key (lang "ru"))
(list (cons :id (id item))
+ (cons :code (code item))
(cons :name (car (mapcar #'val (remove-if-not #'(lambda (x)
(equal (lang-id x) (get-lang-id lang)))
(load-values (car (load-options item :name "name")))))))
@@ -156,14 +157,14 @@
,(cons :city-id (city-id item))
,(cons :city-code (city-code item))
;(:SUBWAY--ID . 1)
- ,(cons :subway (list (mapcar #'(lambda (subway)
+ ,(cons :subway (mapcar #'(lambda (subway)
(car (mapcar #'val (remove-if-not #'(lambda (x)
(equal (lang-id x) (get-lang-id lang)))
(load-values (car (load-options subway :name "name")))))))
(query-dao
'subway
(format nil "SELECT * FROM subway WHERE id IN (SELECT subway_id FROM shop_2_subway WHERE shop_id = ~A)"
- (id item))))))
+ (id item)))))
,(cons :street (car (mapcar #'val (remove-if-not #'(lambda (x)
(equal (lang-id x) (get-lang-id lang)))
(load-values (car (load-options item :name "street")))))))
@@ -185,12 +186,79 @@
(format nil "{\"response\": ~A}"
(json:encode-json-to-string
(loop :for item :in (select-dao 'shop) :collect
- (get-shop *makarena* :lang (aif (hunchentoot:get-parameter "lang") it "ru"))))))
+ (get-shop item :lang (aif (hunchentoot:get-parameter "lang") it "ru"))))))
(restas:define-route restaurant-id ("/restaurant/:code")
+ (format nil "{\"response\": ~A}"
+ (json:encode-json-to-string
+ (aif (car (select-dao 'shop (:= 'code code)))
+ (get-shop it :lang (aif (hunchentoot:get-parameter "lang") it "ru"))))))
+(defun get-category (item &key (lang "ru"))
+ (list (cons :id (id item))
+ (cons :code (code item))
+ (cons :image (image item))
+ (cons :parent (aif (get-dao 'category (parent-id item))
+ (code it)
+ nil))
+ (cons :name (car (mapcar #'val (remove-if-not #'(lambda (x)
+ (equal (lang-id x) (get-lang-id lang)))
+ (load-values (car (load-options item :name "name")))))))
+ (cons :subcategoryes (mapcar #'code (select-dao 'category (:= 'parent-id (id item)))))))
+
+;; (get-category *hot-dishes*)
+
+(restas:define-route category ("/category")
+ (let ((rs (aif (hunchentoot:get-parameter "restaurant")
+ ;; isset parameter restaurant
+ (aif (select-dao 'shop (:= 'code it))
+ (query-dao 'category
+ (format nil "SELECT * FROM category WHERE id IN (SELECT category_id FROM shop_2_category WHERE shop_id = ~A)"
+ (id (car it)))))
+ ;; no parameter restaurant
+ (select-dao 'category))))
+ (format nil "{\"response\": ~A}"
+ (json:encode-json-to-string
+ (loop :for item :in rs :collect (get-category item :lang (aif (hunchentoot:get-parameter "lang") it "ru")))))))
+
+;; todo - завершить здесь представление
+(defun get-product (item &key (lang "ru"))
+ (list (cons :id (id item))
+ (cons :code (code item))
+ (cons :image (image item))
+ (cons :parent (aif (get-dao 'category (parent-id item))
+ (code it)
+ nil))
+ (cons :name (car (mapcar #'val (remove-if-not #'(lambda (x)
+ (equal (lang-id x) (get-lang-id lang)))
+ (load-values (car (load-options item :name "name")))))))
+ (cons :subcategoryes (mapcar #'code (select-dao 'category (:= 'parent-id (id item)))))))
+
+
+;; todo - оттестировать
+(restas:define-route dish ("/dish")
+ (let ((err) (rs))
+ (aif (hunchentoot:get-parameter "restaurant")
+ ;; isset parameter restaurant
+ (aif (select-dao 'shop (:= 'code it))
+ (setf rs (append rs (query (:select 'shop_id :from 'shop_2_product :where (:= 'shop_id (id (car it)))))))
+ (push "restaurant not found" err)))
+ (aif (hunchentoot:get-parameter "category")
+ ;; isset parameter restaurant
+ (aif (select-dao 'category (:= 'code it))
+ (setf rs (append rs (query (:select 'product_id :from 'category_2_product :where (:= 'category_id (id (car it)))))))
+ (push "category not found" err)))
+ (when err
+ (return-from dish (format nil "{\"errors\": ~A}" (json:encode-json-to-string err))))
+ (format nil "{\"response\": ~A}"
+ (json:encode-json-to-string
+ (loop :for item :in (query-dao 'product (format nil "SELECT * FROM product WHERE id IN (~{~A~^, ~})" (remove-duplicates rs)))
+ :collect (get-product item :lang (aif (hunchentoot:get-parameter "lang") it "ru")))))))
+
+
+;; todo - оттестировать и интегрировать расчет расстояний в сферических координатах
;; haversinus
;; http://js-php.ru/web-development/distance-from-dot-to-dot/
;; lat1=deg2rad(lat1);
@@ -234,112 +302,3 @@
:lang (aif (hunchentoot:get-parameter "lang") it "ru")))))
(t "disp-error"))))
-
-;; (restas:define-route resto-list ("/restaurants")
-;; (let ((rs)
-;; (lang (aif (hunchentoot:get-parameter "lang") it "ru")))
-;; (maphash #'(lambda (k v)
-;; (push (make-instance
-;; 'resto~shortlist
-;; :id (id v)
-;; :name (funcall (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage) (name v))
-;; :price (price v)
-;; :photo (photo v)
-;; :address (let ((w (address v)))
-;; (make-instance
-;; 'address
-;; :latitude (latitude w)
-;; :longitude (longitude w)
-;; :postal_code (postal_code w)
-;; :country (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (gethash (country w) *h-country*))
-;; :city (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (gethash (city w) *h-city*))
-;; :subway (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (subway w))
-;; :street (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (street w))
-;; :building (building w)))
-;; :estimate (estimate v))
-;; rs))
-;; *h-resto*)
-;; (format nil "{\"response\": ~A}" (json:encode-json-to-string (reverse rs)))))
-
-
-;; (restas:define-route resto-id ("/restaurant/:id/about")
-;; (let ((rs)
-;; (lang (aif (hunchentoot:get-parameter "lang") it "ru"))
-;; (v (gethash (parse-integer id :junk-allowed t) *h-resto*)))
-;; (setf rs (make-instance
-;; 'resto~longview
-;; :id (id v)
-;; :name (funcall (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage) (name v))
-;; :descr (funcall (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage) (descr v))
-;; :price (price v)
-;; :photo (photo v)
-;; :site (site v)
-;; :phone (phone v)
-;; :address (let ((w (address v)))
-;; (make-instance
-;; 'address
-;; :latitude (latitude w)
-;; :longitude (longitude w)
-;; :postal_code (postal_code w)
-;; :country (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (gethash (country w) *h-country*))
-;; :city (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (gethash (city w) *h-city*))
-;; :subway (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (subway w))
-;; :street (funcall
-;; (intern (string-upcase (format nil "i18n-str-~A" lang)) :eshop.storage)
-;; (street w))
-;; :building (building w)))
-;; :estimate (estimate v)
-;; :capacity (capacity v)
-;; :optional (optional v)
-;; ))
-;; (format nil "{\"response\": ~A}" (json:encode-json-to-string rs))))
-
-
-
-;; (restas:define-route resto-id ("/restaurant/:id/menu")
-;; (let ((rs)
-;; (lang (aif (hunchentoot:get-parameter "lang") it "ru"))
-;; (v (gethash (parse-integer id :junk-allowed t) *h-resto*))
-;; (categoryes)
-;; (products))
-;; ;; (setf rs (make-instance
-;; ;; 'category
-;; (format nil "
-;; [
-;; {
-;; \"categories\" :
-;; {
-;; \"id\":\"1\",
-;; \"name\" : \"Акции\",
-;; \"icon\":\"/img/icon_action.png\"
-;; },
-;; {
-;; \"id\":\"2\",
-;; \"name\" : \"Специальные предложения\",
-;; \"icon\":\"/img/icon_spec.png\"
-;; }
-;; },
-;; {
-;; \"products\" :
-;; {
-;; \"id\":\"1\",
-;; \"name\" : \"Еда мужская, 1 кг.\",
-;; \"pic\":\"/img/eda.png\"
-;; }
-;; }
-;; ]")))
-

0 comments on commit f263d2d

Please sign in to comment.