-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/add_components_in_test
- Loading branch information
Showing
11 changed files
with
409 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ pom.xml.asc | |
.clj-kondo/ | ||
.lsp/ | ||
.DS_Store | ||
.idea | ||
clojure-sandbox/.idea/ | ||
clojure-sandbox/clojure-sandbox.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
(ns swift-ticketing.db.booking | ||
(:require [honey.sql :as sql])) | ||
(:require [honey.sql :as sql] | ||
[swift-ticketing.db.query :refer [run-query! run-query-one!]])) | ||
|
||
(defonce INPROCESS "InProcess") | ||
(defonce CONFIRMED "Confirmed") | ||
(defonce PAYMENTPENDING "PaymentPending") | ||
(defonce REJECTED "Rejected") | ||
(defonce CANCELED "Canceled") | ||
|
||
(defn insert-booking [uid booking-id] | ||
(sql/format {:insert-into :booking | ||
:columns [:booking_id :user_id :booking_status] | ||
:values [[booking-id | ||
[:cast uid :uuid] | ||
[:cast INPROCESS :booking_status]]]})) | ||
(defn insert-booking [db-spec uid booking-id] | ||
(run-query! | ||
db-spec | ||
(sql/format {:insert-into :booking | ||
:columns [:booking_id :user_id :booking_status] | ||
:values [[booking-id | ||
[:cast uid :uuid] | ||
[:cast INPROCESS :booking_status]]]}))) | ||
|
||
(defn get-booking-status [uid booking-id] | ||
(sql/format {:select [:booking_status] :from :booking | ||
:where [[:= :booking_id [:cast booking-id :uuid]] | ||
]})) | ||
(defn get-booking [db-spec booking-id] | ||
(run-query-one! | ||
db-spec | ||
(sql/format {:select [:*] :from :booking | ||
:where [[:= :booking_id [:cast booking-id :uuid]]]}))) | ||
|
||
(defn update-booking-status [booking-id booking-status] | ||
(sql/format {:update :booking | ||
:set {:booking_status [:cast booking-status :booking_status]} | ||
:where [:= :booking_id [:cast booking-id :uuid]]})) | ||
(defn get-booking-status [db-spec booking-id] | ||
(:booking_status (get-booking db-spec booking-id))) | ||
|
||
(defn update-booking-status [db-spec booking-id booking-status] | ||
(run-query! | ||
db-spec | ||
(sql/format {:update :booking | ||
:set {:booking_status [:cast booking-status :booking_status]} | ||
:where [:= :booking_id [:cast booking-id :uuid]]}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,63 @@ | ||
(ns swift-ticketing.db.event | ||
(:require [honey.sql :as sql] | ||
[next.jdbc :as jdbc] | ||
[next.jdbc.result-set :as rs] | ||
[swift-ticketing.db.query :refer [run-query!]] | ||
[swift-ticketing.db.ticket :as ticket]) | ||
(:import [java.time Instant])) | ||
|
||
(defn execute-query [query-fn db-spec args] | ||
(jdbc/execute! db-spec (apply query-fn args) {:builder-fn rs/as-unqualified-maps})) | ||
|
||
(defn insert-event-query [uid event_id event-req] | ||
(sql/format {:insert-into :event | ||
:columns [:event_id :event_name :event_description :event_date :organizer_id :venue] | ||
:values [[event_id | ||
(:name event-req) | ||
(:description event-req) | ||
[:cast (:date event-req) :date] | ||
[:cast uid :uuid] | ||
(:venue event-req)]]})) | ||
|
||
(defn insert-event [db-spec & args] | ||
(execute-query insert-event-query db-spec args)) | ||
|
||
(defn get-events-query [venue from to] | ||
(sql/format {:select [:event_id :event_name :event_description :event_date :venue] :from :event | ||
:where [:and | ||
(if (nil? venue) [true] [:= :venue venue]) | ||
(if (nil? from) [true] [:>= :event_date [:cast from :date]]) | ||
(if (nil? to) [true] [:<= :event_date [:cast to :date]])]})) | ||
|
||
(defn get-events [db-spec & args] | ||
(execute-query get-events-query db-spec args)) | ||
|
||
(defn get-event-query [event-id] | ||
(sql/format {:select [:event_id :event_name :event_description :event_date :venue] :from :event | ||
:where [:= :event_id [:cast event-id :uuid]]})) | ||
|
||
(defn get-event [db-spec & args] | ||
(execute-query get-event-query db-spec args)) | ||
|
||
(defn get-event-with-tickets-query [event-id] | ||
(let [current-time (Instant/now) | ||
reservation-expired [:and | ||
[:= :ticket.ticket_status [:cast ticket/RESERVED :ticket_status]] | ||
[:or | ||
[:> current-time :ticket.reservation_expiration_time] | ||
[:= :ticket.reservation-expiration-time nil]]] | ||
tickets-available [:= :ticket.ticket_status [:cast ticket/AVAILABLE :ticket_status]]] | ||
(sql/format {:select [:e.event_id | ||
:event_name | ||
:event_description | ||
:event_date | ||
:venue | ||
:tt.ticket_type | ||
:tt.ticket_type_id | ||
:tt.seat_type | ||
[[:count :ticket_id] :ticket_count] | ||
[[:min :ticket_name] :ticket_name] | ||
[[:min :tt.ticket_type_description] :ticket_description] | ||
[[:min :ticket_price] :ticket_price]] | ||
:from [[:event :e]] | ||
:left-join [[:ticket_type :tt] [:= :e.event_id :tt.event_id] | ||
[:ticket] [:= :ticket.ticket_type_id :tt.ticket_type_id]] | ||
:where [:and | ||
[:or tickets-available reservation-expired] | ||
[:= :e.event_id [:cast event-id :uuid]]] | ||
:group-by [:e.event_id :tt.ticket_type_id]}))) | ||
|
||
(defn get-event-with-tickets [db-spec & args] | ||
(execute-query get-event-with-tickets-query db-spec args)) | ||
|
||
(defn insert-event [db-spec uid event_id event-req] | ||
(run-query! | ||
db-spec | ||
(sql/format {:insert-into :event | ||
:columns [:event_id :event_name :event_description :event_date :organizer_id :venue] | ||
:values [[event_id | ||
(:name event-req) | ||
(:description event-req) | ||
[:cast (:date event-req) :date] | ||
[:cast uid :uuid] | ||
(:venue event-req)]]}))) | ||
|
||
(defn get-events [db-spec filters] | ||
(let [{:keys [venue from to]} filters] | ||
(run-query! | ||
db-spec | ||
(sql/format {:select [:event_id :event_name :event_description :event_date :venue] :from :event | ||
:where [:and | ||
(if (nil? venue) [true] [:= :venue venue]) | ||
(if (nil? from) [true] [:>= :event_date [:cast from :date]]) | ||
(if (nil? to) [true] [:<= :event_date [:cast to :date]])]})))) | ||
|
||
(defn get-event [db-spec event-id] | ||
(run-query! | ||
db-spec | ||
(sql/format {:select [:event_id :event_name :event_description :event_date :venue] :from :event | ||
:where [:= :event_id [:cast event-id :uuid]]}))) | ||
|
||
(defn get-event-with-tickets [db-spec event-id] | ||
(run-query! | ||
db-spec | ||
(let [current-time [:cast (.toString (Instant/now)) :timestamptz] | ||
reservation-expired [:and | ||
[:= :ticket.ticket_status [:cast ticket/RESERVED :ticket_status]] | ||
[:or | ||
[:> current-time :ticket.reservation_expiration_time] | ||
[:= :ticket.reservation-expiration-time nil]]] | ||
tickets-available [:= :ticket.ticket_status [:cast ticket/AVAILABLE :ticket_status]]] | ||
(sql/format {:select [:e.event_id | ||
:event_name | ||
:event_description | ||
:event_date | ||
:venue | ||
:tt.ticket_type | ||
:tt.ticket_type_id | ||
:tt.seat_type | ||
[[:count :ticket_id] :ticket_count] | ||
[[:min :ticket_name] :ticket_name] | ||
[[:min :tt.ticket_type_description] :ticket_description] | ||
[[:min :ticket_price] :ticket_price]] | ||
:from [[:event :e]] | ||
:left-join [[:ticket_type :tt] [:= :e.event_id :tt.event_id] | ||
[:ticket] [:= :ticket.ticket_type_id :tt.ticket_type_id]] | ||
:where [:and | ||
[:or tickets-available reservation-expired] | ||
[:= :e.event_id [:cast event-id :uuid]]] | ||
:group-by [:e.event_id :tt.ticket_type_id]})))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns swift-ticketing.db.query | ||
(:require [next.jdbc :as jdbc] | ||
[next.jdbc.result-set :as rs])) | ||
|
||
(defn- run-query-with | ||
[f db-spec query] | ||
(f db-spec query {:builder-fn rs/as-unqualified-maps})) | ||
|
||
(defn run-query! | ||
[db-spec query] | ||
(run-query-with jdbc/execute! db-spec query)) | ||
|
||
(defn run-query-one! | ||
[db-spec query] | ||
(run-query-with jdbc/execute-one! db-spec query)) |
Oops, something went wrong.