Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/shopping module #259

Merged
merged 8 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
purchase_listinator_server:
container_name: purchase_listinator_server
restart: always
image: gumberss/purchase-listinator:v2
image: gumberss/purchase-listinator:v3
ports:
- "3000:3000"
volumes:
Expand All @@ -14,7 +14,7 @@ services:
- rabbitmq
environment:
- DATAHIKE_PATH=/usr/purchaselistinator/database
- REDIS_HOST=redis
- SHOPPING_CART_REDIS_HOST=redis
- MONGODB_HOST=mongodb
- RABBITMQ_HOST=rabbitmq
- ENVIRONMENT_TYPE=prod
Expand Down
1 change: 0 additions & 1 deletion services/llm-client/diplomat/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)

def complete(rendered_prompt : RenderedPrompt):

images = [{
"type": "image_url",
"image_url": {
Expand Down
20 changes: 0 additions & 20 deletions src/purchase_listinator/adapters/db/shopping.clj

This file was deleted.

9 changes: 0 additions & 9 deletions src/purchase_listinator/adapters/in/cart.clj

This file was deleted.

8 changes: 0 additions & 8 deletions src/purchase_listinator/adapters/in/price_suggestion.clj

This file was deleted.

10 changes: 0 additions & 10 deletions src/purchase_listinator/adapters/in/shopping_initiation.clj

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions src/purchase_listinator/adapters/out/shopping.clj

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions src/purchase_listinator/components/datahike.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns purchase-listinator.components.datahike
(:require [com.stuartsierra.component :as component]
[datahike.api :as d]))

(defn create-schema [conn schemas]
(d/transact conn schemas))

(defrecord Datahike [config-key schemas config]
component/Lifecycle

(start [component]
(try (d/create-database (-> config config-key))
(catch Exception e
(println e)))
(let [conn (d/connect (-> config config-key))]
(create-schema conn schemas)
(assoc component :connection conn)))

(stop [component]
(d/release (:connection component))
(dissoc component :connection)))

(defn new-datahike [config-key schemas]
(map->Datahike {:config-key config-key
:schemas schemas}))
6 changes: 0 additions & 6 deletions src/purchase_listinator/components/datomic.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
[purchase-listinator.dbs.datomic.purchase-list :as datomic.purchase-list]
[purchase-listinator.dbs.datomic.purchase-category :as datomic.purchase-category]
[purchase-listinator.dbs.datomic.purchase-item :as datomic.purchase-item]
[purchase-listinator.dbs.datomic.shopping :as datomic.shopping]
[purchase-listinator.dbs.datomic.shopping-category :as dbs.datomic.shopping-category]
[purchase-listinator.dbs.datomic.shopping-item :as dbs.datomic.shopping-item]
[purchase-listinator.dbs.datomic.user :as dbs.datomic.user]
[purchase-listinator.dbs.datomic.share :as dbs.datomic.share]))

(def schema (concat dbs.datomic.user/schema
datomic.purchase-list/schema
datomic.purchase-category/schema
datomic.purchase-item/schema
datomic.shopping/schema
dbs.datomic.shopping-item/schema
dbs.datomic.shopping-category/schema
dbs.datomic.share/schema))

(defn create-schema [conn]
Expand Down
14 changes: 6 additions & 8 deletions src/purchase_listinator/components/mongo.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
(ns purchase-listinator.components.mongo
(:require [monger.core :as mg]
[com.stuartsierra.component :as component]
[purchase-listinator.dbs.mongo.shopping-location :as dbs.mongo.shopping-location]))

(def indexes (vector dbs.mongo.shopping-location/indexes))
[com.stuartsierra.component :as component]))

(defn connect-by-uri
[uri]
Expand All @@ -16,10 +13,10 @@
{:conn conn
:db db}))

(defrecord Mongo [config]
(defrecord Mongo [config config-key indexes]
component/Lifecycle
(start [this]
(let [{{:keys [host port db-name uri]} :mongo} config
(let [{{:keys [host port db-name uri]} config-key} config
conn (mg/connect {:host host :port port})
db (mg/get-db conn db-name)]
(if uri
Expand All @@ -35,8 +32,9 @@
(dissoc this :connection :db)))

(defn new-mongo
[]
(map->Mongo {}))
[config-key indexes]
(map->Mongo {:indexes indexes
:config-key config-key}))


(defrecord MongoFake [config]
Expand Down
21 changes: 20 additions & 1 deletion src/purchase_listinator/components/rabbitmq_channel.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,23 @@

(defn new-rabbit-mq-channel
[config-key]
(map->RabbitMqChannel {:config-key config-key}))
(map->RabbitMqChannel {:config-key config-key}))


(defrecord RabbitMqChannelFake [config-key config]
component/Lifecycle
(start [this]
this)
(stop [this]
this)
IProducer
(publish
[producer exchange payload]
payload)
(publish
[producer exchange payload args]
payload))

(defn new-rabbit-mq-channel-fake
[config-key]
(map->RabbitMqChannelFake {:config-key config-key}))
4 changes: 3 additions & 1 deletion src/purchase_listinator/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
[purchase-listinator.modules.events.core :as modules.events.core]
[purchase-listinator.modules.price-suggestion.core :as modules.price-suggestion.core]
[purchase-listinator.modules.shopping-cart.core :as modules.shopping-cart.core]
[purchase-listinator.modules.shopping.core :as modules.shopping.core]
[purchase-listinator.purchase-listinator-core :as purchase-listinator-core])
(:gen-class))

(def modules-config [purchase-listinator-core/module-config
modules.events.core/config
modules.price-suggestion.core/config
modules.shopping-cart.core/config])
modules.shopping-cart.core/config
modules.shopping.core/config])
(def system-config
(reduce conj
{:env (keyword (or (System/getenv "ENVIRONMENT_TYPE") "dev"))
Expand Down
7 changes: 0 additions & 7 deletions src/purchase_listinator/logic/reposition.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
(decrement-order item)
item))

(s/defn increment-if-after-or-equal :- models.logic.reposition/Reorder
[position
{:keys [order-position] :as item} :- models.logic.reposition/Reorder]
(if (>= order-position position)
(increment-order item)
item))

(s/defn ^:private reposition-one :- models.logic.reposition/Reorder
[old-position :- s/Num
new-position :- s/Num
Expand Down
10 changes: 0 additions & 10 deletions src/purchase_listinator/logic/shopping_category.clj

This file was deleted.

9 changes: 0 additions & 9 deletions src/purchase_listinator/models/internal/cart.clj

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns purchase-listinator.modules.shopping.adapters.db.datomic.shopping
(:require [schema.core :as s]
[purchase-listinator.misc.general :as misc.general]
[purchase-listinator.misc.datomic :as misc.datomic]
[purchase-listinator.modules.shopping.schemas.models.shopping :as models.shopping]))

(s/defn internal->db
[internal :- models.shopping/Shopping]
(-> (dissoc internal :categories)
(misc.general/namespace-keys :shopping)))

(s/defn db->internal :- models.shopping/Shopping
[db-wire]
(when (not-empty db-wire)
(-> (misc.datomic/datomic->entity db-wire)
(misc.general/unnamespace-keys))))
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns purchase-listinator.adapters.db.shopping-category
(ns purchase-listinator.modules.shopping.adapters.db.datomic.shopping-category
(:require [schema.core :as s]
[purchase-listinator.misc.general :as misc.general]
[purchase-listinator.misc.datomic :as misc.datomic]
[purchase-listinator.models.internal.shopping-category :as models.internal.shopping-category]))
[purchase-listinator.modules.shopping.schemas.models.shopping-category :as models.internal.shopping-category]))


(s/defn internal->db
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns purchase-listinator.adapters.db.shopping-item
(ns purchase-listinator.modules.shopping.adapters.db.datomic.shopping-item
(:require [schema.core :as s]
[purchase-listinator.misc.general :as misc.general]
[purchase-listinator.misc.datomic :as misc.datomic]
[purchase-listinator.models.internal.shopping-item :as models.internal.shopping-item]))
[purchase-listinator.modules.shopping.schemas.models.shopping-item :as models.internal.shopping-item]))

(s/defn internal->db
[{:keys [category-id order-position price] :as internal} :- models.internal.shopping-item/ShoppingItem]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns purchase-listinator.adapters.db.mongo.shopping-location
(ns purchase-listinator.modules.shopping.adapters.db.mongo.shopping-location
(:require [schema.core :as s]
[purchase-listinator.models.internal.shopping-location :as models.internal.shopping-location]))
[purchase-listinator.modules.shopping.schemas.models.shopping-location :as models.internal.shopping-location]))

(s/defn internal->db
[{:keys [latitude longitude] :as internal} :- models.internal.shopping-location/ShoppingLocation]
Expand Down
9 changes: 9 additions & 0 deletions src/purchase_listinator/modules/shopping/adapters/in/cart.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns purchase-listinator.modules.shopping.adapters.in.cart
(:require
[purchase-listinator.modules.shopping.schemas.models.cart :as models.internal.cart]
[purchase-listinator.modules.shopping.schemas.wires.in.cart :as wires.in.cart]
[schema.core :as s]))

(s/defn wire->internal :- models.internal.cart/Cart
[wire :- wires.in.cart/Cart]
wire)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns purchase-listinator.modules.shopping.adapters.in.price-suggestion
(:require [schema.core :as s]
[purchase-listinator.modules.shopping.schemas.wires.in.price-suggestion :as wires.in.price-suggestion]
[purchase-listinator.modules.shopping.schemas.models.price-suggestion :as models.internal.price-suggestion]))

(s/defn wire->internal :- models.internal.price-suggestion/ShoppingItemSuggestedPrices
[wire :- wires.in.price-suggestion/ShoppingItemSuggestedPrices]
wire)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns purchase-listinator.modules.shopping.adapters.in.shopping-initiation
(:require [purchase-listinator.modules.shopping.schemas.wires.in.shopping :as wires.in.shopping]
[purchase-listinator.modules.shopping.schemas.models.shopping-initiation :as shopping.models.shopping-initiation]
[purchase-listinator.adapters.misc :as adapters.misc]
[schema.core :as s]))

(s/defn wire->internal :- shopping.models.shopping-initiation/ShoppingInitiation
[{:keys [id list-id] :as wire} :- wires.in.shopping/ShoppingInitiation]
(assoc wire :id (adapters.misc/string->uuid id)
:list-id (adapters.misc/string->uuid list-id)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns purchase-listinator.modules.shopping.adapters.in.shopping-initiation-data-request
(:require [purchase-listinator.modules.shopping.schemas.wires.in.shopping :as wires.in.shopping]
[purchase-listinator.modules.shopping.schemas.models.shopping-initiation-data-request :as models.shopping-initiation-data-request]
[purchase-listinator.adapters.misc :as adapters.misc]
[schema.core :as s]))

(s/defn wire->internal :- models.shopping-initiation-data-request/ShoppingInitiationDataRequest
[{:keys [list-id latitude longitude] :as wire} :- wires.in.shopping/ShoppingInitiationDataRequest]
(assoc wire :list-id (adapters.misc/string->uuid list-id)
:latitude (Double/parseDouble latitude)
:longitude (Double/parseDouble longitude)))
14 changes: 14 additions & 0 deletions src/purchase_listinator/modules/shopping/adapters/out/shopping.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns purchase-listinator.modules.shopping.adapters.out.shopping
(:require
[schema.core :as s]
[purchase-listinator.modules.shopping.schemas.models.shopping :as shopping.models.shopping]
[purchase-listinator.modules.shopping.schemas.wires.out.shopping :as wires.out.shopping]))

(s/defn ->ShoppingFinishedEvent :- wires.out.shopping/ShoppingFinishedEvent
[{:keys [user-id] :as shopping} :- shopping.models.shopping/Shopping
moment :- s/Num
event-id :- s/Uuid]
{:event-id event-id
:user-id user-id
:moment moment
:shopping shopping})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns purchase-listinator.modules.shopping.adapters.out.shopping-initiation-data
(:require [purchase-listinator.modules.shopping.schemas.models.shopping :as models.internal.shopping]
[purchase-listinator.modules.shopping.schemas.wires.out.shopping-initiation-data :as wires.out.shopping-initiation-data]
[schema.core :as s]))

(s/defn shopping->wire :- wires.out.shopping-initiation-data/ShoppingInitiationData
[{:keys [place type]} :- models.internal.shopping/Shopping]
{:place place
:type type})
Loading
Loading