[feat] The ability to get a list of all allocated appointments and office hours is up.

TODO: Add *this users* appointments to the list of appointments provided in the given
      time range.

Then: add/update/delete appointments.
This commit is contained in:
Elf M. Sternberg 2016-02-08 20:14:24 -08:00
parent a0d44664bd
commit bd0adf19ab
3 changed files with 45 additions and 15 deletions

42
main.hy
View File

@ -1,10 +1,46 @@
#!/usr/local/bin/hy #!/usr/local/bin/hy
(import [flask [Flask]]) (import psycopg2 psycopg2.extras datetime [flask [Flask jsonify]])
(def app (Flask __name__)) (def app (Flask __name__))
(with-decorator (.route app "/") (defn hello [] "Hello World")) (defn connect []
(psycopg2.connect "host='localhost' dbname='officehours' user='officehours' password='eatabug'"))
(defn tap [a] (print (str a)) a)
(defn select [curs cmd &rest args]
(.execute curs cmd (list args))
(.fetchall curs))
(defn during-to-utc [d]
(let [[ud (.isoformat (getattr (get d 0) "upper"))]
[ld (.isoformat (getattr (get d 0) "lower"))]]
(, ld ud)))
(with-decorator
(.route app "/")
(defn hello []
(let [[conn (connect)]
[curs (.cursor conn)]
[week (psycopg2.extras.DateTimeRange (datetime.datetime 2015 1 31 0 0)
(datetime.datetime 2015 2 7 23 59))]
[cmd1 (+ "SELECT during FROM staff_appointments WHERE staff_id IN "
"(SELECT staff_id FROM staff_client_relationships "
"WHERE client_id = %s) AND during && %s")]
[appointments (select curs cmd1 3 week)]
[cmd2 (+ "SELECT during, appointment_id, client_id FROM staff_appointments "
"WHERE client_id = %s AND during && %s")]
[client_appointments (select curs cmd2 3 week)]
[cmd3 (+ "SELECT during FROM officehours WHERE staff_id IN "
"(SELECT staff_id FROM staff_client_relationships "
"WHERE client_id = %s) AND during && %s")]
[officehours (select curs cmd3 3 week)]]
(jsonify { "appointments" (list (map during-to-utc appointments))
"officehours" (list (map during-to-utc officehours)) }))))
(if (= __name__ "__main__") (if (= __name__ "__main__")
(.run app)) (do
(setv app.debug True)
(.run app)))

10
main.py
View File

@ -1,10 +0,0 @@
from flask import Flask
app = Flask(__name__)
@app.route("/") # take note of this decorator syntax, it's a common pattern
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()

View File

@ -101,8 +101,12 @@ CREATE VIEW staff_client_relationships AS
INNER JOIN client_members ON relationship.client_id = client_members.client_id); INNER JOIN client_members ON relationship.client_id = client_members.client_id);
CREATE VIEW staff_appointments AS CREATE VIEW staff_appointments AS
(SELECT staff_name, staff_client_relationships.staff_id AS staff_id, (SELECT staff_name,
client_name, staff_client_relationships.client_id AS client_id, during staff_client_relationships.staff_id AS staff_id,
client_name,
staff_client_relationships.client_id AS client_id,
appointments.id AS appointment_id,
during
FROM appointments INNER JOIN staff_client_relationships FROM appointments INNER JOIN staff_client_relationships
ON appointments.client_id = staff_client_relationships.client_id); ON appointments.client_id = staff_client_relationships.client_id);