refactor: Address PR review feedback for timestamp handling
- Rename format-timestamp-for-postgres to format-timestamp-iso8601 (database-agnostic) - Reuse format-timestamp-iso8601 in authenticate-user instead of inline formatting - Change listened_at field type from integer to timestamp for consistency
This commit is contained in:
parent
cd73db1516
commit
23328c2b43
|
|
@ -61,7 +61,7 @@
|
|||
(db:create "user_listening_history" '((user_id :integer)
|
||||
(track_title :text)
|
||||
(track_artist :text)
|
||||
(listened_at :integer)
|
||||
(listened_at :timestamp)
|
||||
(duration_seconds :integer))))
|
||||
|
||||
(unless (db:collection-exists-p "user_playlists")
|
||||
|
|
@ -98,8 +98,8 @@
|
|||
(string= (string-upcase (package-name (db:implementation)))
|
||||
"I-LAMBDALITE"))
|
||||
|
||||
(defun format-timestamp-for-postgres (value)
|
||||
"Convert a timestamp value to ISO 8601 format for PostgreSQL.
|
||||
(defun format-timestamp-iso8601 (value)
|
||||
"Convert a timestamp value to ISO 8601 format.
|
||||
Handles: integers (Unix epoch), local-time timestamps, strings, and NIL."
|
||||
(cond
|
||||
((null value) nil)
|
||||
|
|
@ -124,10 +124,10 @@ Handles: integers (Unix epoch), local-time timestamps, strings, and NIL."
|
|||
(last-login (dm:field data-model "last-login")))
|
||||
(when created-date
|
||||
(setf (dm:field data-model "created-date")
|
||||
(format-timestamp-for-postgres created-date)))
|
||||
(format-timestamp-iso8601 created-date)))
|
||||
(when last-login
|
||||
(setf (dm:field data-model "last-login")
|
||||
(format-timestamp-for-postgres last-login))))))
|
||||
(format-timestamp-iso8601 last-login))))))
|
||||
|
||||
(defun data-model-save (data-model)
|
||||
"Wrapper on data-model save method to bypass error using dm:save on lambdalite.
|
||||
|
|
|
|||
|
|
@ -70,14 +70,10 @@
|
|||
(when (and (= 1 user-active)
|
||||
(verify-password password user-password))
|
||||
;; Update last login using data-model (database agnostic)
|
||||
;; Use ISO 8601 format in UTC that PostgreSQL TIMESTAMP can parse
|
||||
(handler-case
|
||||
(progn
|
||||
(setf (dm:field user "last-login")
|
||||
(local-time:format-timestring nil (local-time:now)
|
||||
:format '(:year "-" (:month 2) "-" (:day 2) " "
|
||||
(:hour 2) ":" (:min 2) ":" (:sec 2))
|
||||
:timezone local-time:+utc-zone+))
|
||||
(format-timestamp-iso8601 (local-time:now)))
|
||||
;; Use data-model-save to normalize all timestamp fields before saving
|
||||
(data-model-save user))
|
||||
(error (e)
|
||||
|
|
|
|||
Loading…
Reference in New Issue