aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-11-12 12:28:51 -0800
committercolin <colin@cicadas.surf>2023-11-12 12:28:51 -0800
commitc333f1b3efc611795703c70c6f56321a02cf29da (patch)
tree05468ea21cbf3b77e329b93d8b9247a6800d9947
parenta8fd8ff49a95e610c3cd38aba02ee28129d4d881 (diff)
ready to hack on the site
-rw-r--r--src/api.lisp28
-rw-r--r--src/mailbox.lisp6
2 files changed, 23 insertions, 11 deletions
diff --git a/src/api.lisp b/src/api.lisp
index ad171c6..943beae 100644
--- a/src/api.lisp
+++ b/src/api.lisp
@@ -111,10 +111,9 @@ fields: \"username\" and \"password\"."
The JSON body must contain properties \"code\", \"username\", and
\"password\"."
(with-json-body (code username password)
- (json:to-json
- (if (model:use-invite-with-code code username password)
- (list :|status| "SUCCESS")
- (list :|status| "INVITE_UNKNOWN")))))
+ (if (model:use-invite-with-code code username password)
+ "true"
+ "false")))
;;; PLAYLIST ENDPOINTS
@@ -146,13 +145,15 @@ witht he given id."
(defendpoint/session :post "/add-track/:pl a-playlist:"
(check-can-edit pl)
- (let ((user (model:user *session*)))
+ (let ((user (model:user *session*))) ; need to capture lexically
+ ; b/c of closures below
(with-json-body (url)
(downloader:fetch-track
url
(lambda (track)
(model:append-track pl track)
- (mail:send user (list :|newTrack| track :|playlist| (model:key pl))))
+ (mail:send user (list :|newTrack| (model:key track)
+ :|playlist| (model:key pl))))
(lambda (e)
(logger:logerror (list :error e :url url))
(mail:send user (list :|fetchError| url)))))))
@@ -163,13 +164,15 @@ witht he given id."
(model:destroy-playlist pl)
"true")
-(defendpoint/session :patch "/user/:user a-user:/add-editor/:pl a-playlist:"
+;;; USER ENDPOINTS
+
+(defendpoint/session :patch "/user/:user a-user:/add-playlist/:pl a-playlist:"
"Owners can add collaborators to their playlists"
(check-ownership pl)
(model:add-editor pl user)
"true")
-(defendpoint/session :patch "/user/:user a-user:/remove-editor/:pl a-playlist:"
+(defendpoint/session :patch "/user/:user a-user:/remove-playlist/:pl a-playlist:"
"Owners can remove collaborators from their playlists"
(check-ownership pl)
(model:remove-editor pl user)
@@ -184,8 +187,15 @@ witht he given id."
(defendpoint/session :patch "/track/:track a-track:"
"Any logged in user can edit track metadata"
(with-json-body (title artist album)
- (model:update-track-info track new artist album title)
+ (model:update-track-info track (or artist "") (or album "") (or title ""))
"true"))
+;;; MAILBOX ENDPOINTS
+
+(defendpoint/session :get "/notifications"
+ "Get the messages, if any, for the user session."
+ (mail:deliver (model:user *session*)))
+
+
diff --git a/src/mailbox.lisp b/src/mailbox.lisp
index 8ce1acf..16e82d0 100644
--- a/src/mailbox.lisp
+++ b/src/mailbox.lisp
@@ -2,6 +2,7 @@
(defpackage #:vampire.mailbox
(:use #:cl)
+ (:import-from #:alexandria #:when-let)
(:export #:send #:deliver))
(in-package #:vampire.mailbox)
@@ -12,6 +13,7 @@
(push message (gethash user *mailboxes*)))
(defun deliver (user)
- (prog1 (reverse (gethash user *mailboxes*))
- (remhash user *mailboxes*)))
+ (alexandria:when-let (msgs (reverse (gethash user *mailboxes*)))
+ (remhash user *mailboxes*)
+ msgs))