       (response {:status 403
                  :body {:error (str "The team '" team-name "' already exists")}}))))
 
-(defn update-by-field [team-name field value]
+(defn update-by-field 
+  "Helper function to update correct field of team"
+  [team-name field value]
   (cond
     (= field "Weight") (update-team-weight! db value team-name)
     (= field "Launch") (update-team-launch! db value team-name)
     (= field "Ramp") (update-team-ramp! db value team-name)
     (= field "Presentation") (update-team-presentation! db value team-name)))
 
-(defn update-team [{:keys [team-name field value]}]
+(defn update-team 
+  "Updates team field, weight or score, to new value provided the team exists"
+  [{:keys [team-name field value]}]
   (let [rows-aff (update-by-field team-name field value)]
     (if (= 1 rows-aff)
       (response {:status 200

(defquery update-team-presentation! "sql/update-team-pres-score.sql")
(defquery delete-team! "sql/delete-team.sql")

(defn teams-summary []
  {:body (select-summary db)})

(defn results-summary []
  {:body (select-results db)}) 

(defn create-team [{:keys [team-name]}]
  (let [rows-aff (create-team! db team-name)]
    (if (= 1 rows-aff)
      (response {:status 200

                                   (str "http://"
                                        (env :db-url)
                                        ":3000/teams"))))))
;;; Routes served by databse operations
;; database connector parameters
(def db {:classname "com.mysql.jdbc.Driver"
         :subprotocol "mysql"
         :subname (str "//" (env :db-url) ":" (env :db-port) "/" (env :db-name))
         :user (env :db-user)
         :password (env :db-pass)})

;; SQL queries and operations over team data
(defquery select-results "sql/select-results.sql")
(defquery select-summary "sql/select-summary.sql")
(defquery create-team! "sql/insert-team.sql")
