summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-24 00:30:03 +0530
committerArun Isaac2022-06-25 14:17:42 +0530
commit993aec0b17086cc4681fbf234aa19f4710fff441 (patch)
tree1521e62f80d6f37c5e6d61515d1c4841eb908477
parent27f28fae92364314604936fd0a0daf7f03aae28e (diff)
downloadtissue-993aec0b17086cc4681fbf234aa19f4710fff441.tar.gz
tissue-993aec0b17086cc4681fbf234aa19f4710fff441.tar.lz
tissue-993aec0b17086cc4681fbf234aa19f4710fff441.zip
issue: Add serialization and deserialization functions.
* tissue/issue.scm (date->iso-8601, iso-8601->date): New functions. (issue->alist, post->alist, alist->issue, alist->post): New public functions.
-rw-r--r--tissue/issue.scm55
1 files changed, 55 insertions, 0 deletions
diff --git a/tissue/issue.scm b/tissue/issue.scm
index 8f36d94..3b6c015 100644
--- a/tissue/issue.scm
+++ b/tissue/issue.scm
@@ -48,6 +48,10 @@
post
post-author
post-date
+ issue->alist
+ alist->issue
+ post->alist
+ alist->post
authors
issues))
@@ -81,6 +85,57 @@
(author post-author)
(date post-date))
+(define (date->iso-8601 date)
+ "Convert DATE, an SRFI-19 date object, to an ISO-8601 date string."
+ (date->string date "~4"))
+
+(define (iso-8601->date str)
+ "Convert STR, an ISO-8601 date string, to an SRFI-19 date object."
+ (string->date str "~Y-~m-~dT~H:~M:~S~z"))
+
+(define (issue->alist issue)
+ "Convert ISSUE, a <issue> object, to an association list that can be
+serialized."
+ `((file . ,(issue-file issue))
+ (title . ,(issue-title issue))
+ (creator . ,(issue-creator issue))
+ (created-date . ,(date->iso-8601 (issue-created-date issue)))
+ (last-updater . ,(issue-last-updater issue))
+ (last-updated-date . ,(date->iso-8601 (issue-last-updated-date issue)))
+ (assigned . ,(issue-assigned issue))
+ (keywords . ,(issue-keywords issue))
+ (open . ,(issue-open? issue))
+ (tasks . ,(issue-tasks issue))
+ (completed-tasks . , (issue-completed-tasks issue))
+ (posts . ,(map post->alist (issue-posts issue)))))
+
+(define (post->alist post)
+ "Convert POST, a <post> object, to an association list that can be
+serialized."
+ `((author . ,(post-author post))
+ (date . ,(date->iso-8601 (post-date post)))))
+
+(define (alist->issue alist)
+ "Convert ALIST to an <issue> object."
+ (issue (assq-ref alist 'file)
+ (assq-ref alist 'title)
+ (assq-ref alist 'creator)
+ (iso-8601->date (assq-ref alist 'created-date))
+ (assq-ref alist 'last-updater)
+ (iso-8601->date (assq-ref alist 'last-updated-date))
+ (assq-ref alist 'assigned)
+ (assq-ref alist 'keywords)
+ (assq-ref alist 'open)
+ (assq-ref alist 'tasks)
+ (assq-ref alist 'completed-tasks)
+ (map alist->post
+ (assq-ref alist 'posts))))
+
+(define (alist->post alist)
+ "Convert ALIST to a <post> object."
+ (post (assq-ref alist 'author)
+ (iso-8601->date (assq-ref alist 'date))))
+
(define (hashtable-append! hashtable key new-values)
"Append NEW-VALUES to the list of values KEY is associated to in
HASHTABLE. Deduplicate the resulting list if necessary. If KEY is not