From c65cde9e8e55b39ff468e4b5ce76d51fb0468d7e Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 4 Jul 2013 21:51:31 +0200 Subject: Add tasks to stories --- pg-datastore.lisp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'pg-datastore.lisp') diff --git a/pg-datastore.lisp b/pg-datastore.lisp index 8cfdbeb..d6b3e54 100644 --- a/pg-datastore.lisp +++ b/pg-datastore.lisp @@ -17,10 +17,27 @@ (:metaclass dao-class) (:keys id)) +(defclass task () + ((id :col-type serial :reader story-id) + (state :col-type string :reader state :initform "TODO") + (description :col-type string :reader description :initarg :description) + (priority :col-type integer :reader priority :initarg :priority) + (reporter :col-type string :reader reporter :initarg :reporter) + (assignee :col-type string :reader assignee :initarg :assignee) + (story-id :col-type integer :reader story-id :initarg :story-id)) + (:metaclass dao-class) + (:keys id)) + +(deftable task + (!dao-def) + (!foreign 'story 'story-id 'id)) + (defmethod datastore-init ((datastore pg-datastore)) (with-connection (connection-spec datastore) (unless (table-exists-p 'story) - (execute (dao-table-definition 'story))))) + (execute (dao-table-definition 'story))) + (unless (table-exists-p 'task) + (execute (dao-table-definition 'task))))) (defmethod datastore-get-all-stories ((datastore pg-datastore)) (with-connection (connection-spec datastore) @@ -28,7 +45,10 @@ (defmethod datastore-get-story ((datastore pg-datastore) id) (with-connection (connection-spec datastore) - (query (:select :* :from 'story :where (:= 'id id)) :alist))) + (append (query (:select :* :from 'story :where (:= 'id id)) :alist) + `((tasks . ,(query (:select :* :from 'task + :where (:= 'story-id id)) + :alists)))))) (defmethod datastore-post-story ((datastore pg-datastore) role necessity title content reporter) @@ -42,6 +62,18 @@ :content content :assignee "" :reporter reporter))) (save-dao obj)))) +(defmethod datastore-post-task + ((datastore pg-datastore) story-id description reporter) + (with-connection (connection-spec datastore) + (let ((obj (make-instance + 'task :description description + :priority (+ 1 (query (:select + (:coalesce (:max 'priority) 0) + :from 'task) :single)) + :reporter reporter :story-id (parse-integer story-id) + :assignee ""))) + (save-dao obj)))) + (defmethod datastore-story-get-state ((datastore pg-datastore) id) (with-connection (connection-spec datastore) (query (:select 'state :from 'story :where (:= 'id id)) :single))) -- cgit v1.2.3-54-g00ecf