Change events.occurred_at from TIMESTAMPTZ to DATE

Make date required, remove default. Simplifies date handling
throughout the controller.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 16:04:24 +01:00
co-authored by Claude Opus 4.6
parent 130815e32f
commit 96d12f170b
3 changed files with 16 additions and 7 deletions
@@ -0,0 +1,5 @@
ALTER TABLE deposits ALTER COLUMN occurred_at TYPE TIMESTAMPTZ USING occurred_at::timestamptz;
--;;
ALTER TABLE events ALTER COLUMN occurred_at SET DEFAULT NOW();
--;;
ALTER TABLE events ALTER COLUMN occurred_at TYPE TIMESTAMPTZ USING occurred_at::timestamptz;
@@ -0,0 +1,5 @@
ALTER TABLE events ALTER COLUMN occurred_at TYPE DATE USING occurred_at::date;
--;;
ALTER TABLE events ALTER COLUMN occurred_at DROP DEFAULT;
--;;
ALTER TABLE deposits ALTER COLUMN occurred_at TYPE DATE USING occurred_at::date;
@@ -5,7 +5,7 @@
[pmagnus.btcdata.frankfurter.rates :as rates] [pmagnus.btcdata.frankfurter.rates :as rates]
[ring.util.http-response :as response]) [ring.util.http-response :as response])
(:import (:import
[java.time Instant LocalDate ZoneOffset] [java.time LocalDate]
[java.util UUID])) [java.util UUID]))
(defn list-wallets [{:keys [query-fn]} req] (defn list-wallets [{:keys [query-fn]} req]
@@ -51,11 +51,10 @@
(try (try
(let [wallet (query-fn :get-wallet-by-id {:id to-wallet-id}) (let [wallet (query-fn :get-wallet-by-id {:id to-wallet-id})
exchange (or (:name wallet) "Unknown") exchange (or (:name wallet) "Unknown")
date (.toLocalDate (.atOffset occurred-at ZoneOffset/UTC)) rates (or (query-fn :get-currency-rates-by-date {:rate-date occurred-at})
rates (or (query-fn :get-currency-rates-by-date {:rate-date date})
(rates/fetch-and-persist-for-date! (rates/fetch-and-persist-for-date!
(:client frankfurter) (:url frankfurter) (:client frankfurter) (:url frankfurter)
query-fn date)) query-fn occurred-at))
amounts (if rates amounts (if rates
(convert-amount fiat-amount fiat-currency rates) (convert-amount fiat-amount fiat-currency rates)
{:amount-eur nil :amount-dkk nil :amount-usd nil})] {:amount-eur nil :amount-dkk nil :amount-usd nil})]
@@ -75,9 +74,9 @@
event-type (:event_type params)] event-type (:event_type params)]
(if-not (#{"bank_to_exchange" "exchange_to_wallet" "wallet_to_wallet"} event-type) (if-not (#{"bank_to_exchange" "exchange_to_wallet" "wallet_to_wallet"} event-type)
(response/bad-request {:error "Invalid event_type"}) (response/bad-request {:error "Invalid event_type"})
(let [occurred-at (if-let [ts (:occurred_at params)] (let [occurred-at (if-let [d (:occurred_at params)]
(Instant/parse ts) (LocalDate/parse d)
(Instant/now)) (LocalDate/now))
row {:event-type event-type row {:event-type event-type
:occurred-at occurred-at :occurred-at occurred-at
:sats (:sats params) :sats (:sats params)