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

Initial Mongo Product Data #5

Merged
merged 2 commits into from
Apr 9, 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
Binary file modified .DS_Store
Binary file not shown.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ Her servis, aşağıdaki NPM paketlerini kullanmaktadır:

## Çalıştırma Adımları

Projeyi yerel makinenize klonlayın.
Gerekli bağımlılıkları yüklemek için her bir mikroservis için npm install komutunu kullanın.
Docker ortamında projeyi çalıştırmak için docker-compose up komutunu kullanın.
Alternatif olarak, her servisi ayrı ayrı başlatmak için npm start komutunu her bir servis için kullanabilirsiniz.
- Projeyi yerel makinenize klonlayın.
- cp .env.example .env komutu ile kendi env dosyanızı oluşturun. Eğer sentry kullanmak istemiyorsanız; her servis'in `src/index.js` dosyasında şu satırı yoruma alın `setupSentryCapture(app);`.
- Docker ilk ayağa kalktığında DB içerisinde product verileri olması için, ilk etapta `chmod +x mongo-seed/import.sh` komutunu çalıştırın. Bu aşama docker ayağa kalkarken verilerin db'ye yüklenmesi için gerekli.
- Docker ortamında projeyi çalıştırmak için `docker-compose up` veya `docker compose up -d` komutunu kullanın.
- Alternatif olarak, her servisi ayrı ayrı başlatmak için npm start komutunu her bir servis için kullanabilirsiniz.

## Nginx Konfigürasyonu

Expand Down
13 changes: 0 additions & 13 deletions customer/.env.dev

This file was deleted.

9 changes: 9 additions & 0 deletions customer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
APP_SECRET='example-app-secret-key'

MONGODB_URI='mongodb://mongo_db/microservices_customer'
MSG_QUEUE_URL='amqp://rabbitmq'
SENTRY_DSN='[YOUR_SENTRY_DSN]'

EXCHANGE_NAME='ONLINE_STORE'

PORT=8005
1 change: 1 addition & 0 deletions customer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ web_modules/
.env.test.local
.env.production.local
.env.local
.env.dev

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
72 changes: 0 additions & 72 deletions customer/src/sampledata.json

This file was deleted.

10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ services:
- '27017:27017'
restart: always

mongo_seed:
image: mongo:latest
links:
- mongo_db
volumes:
- ./mongo-seed:/mongo-seed
command:
/mongo-seed/import.sh


customer:
build:
dockerfile: Dockerfile
Expand Down
3 changes: 3 additions & 0 deletions mongo-seed/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

mongoimport --host mongo_db --db microservices_product --collection products --type json --file /mongo-seed/product-data.json --jsonArray
152 changes: 152 additions & 0 deletions mongo-seed/product-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
[
{
"name": "Elma",
"desc": "Taze ve lezzetli elma",
"type": "Meyve",
"banner": "",
"unit": 1,
"price": 2.5,
"available": true,
"supplier": "MeyveDünyası"
},
{
"name": "Süt",
"desc": "Taze ve pastörize süt",
"type": "SütÜrünleri",
"banner": "",
"unit": 1,
"price": 3.25,
"available": true,
"supplier": "SütÇiftliği"
},
{
"name": "Ekmek",
"desc": "Tam buğday ekmeği",
"type": "FırınÜrünleri",
"banner": "",
"unit": 1,
"price": 1.75,
"available": true,
"supplier": "EkmekFırını"
},
{
"name": "Tavuk Göğsü",
"desc": "Dana etiyle hazırlanmış sağlıklı tavuk göğsü",
"type": "EtveEtÜrünleri",
"banner": "",
"unit": 1,
"price": 9.99,
"available": false,
"supplier": "EtDünyası"
},
{
"name": "Makarna",
"desc": "Kepekli makarna",
"type": "KuruGıda",
"banner": "YeniÜrün",
"unit": 1,
"price": 2.99,
"available": true,
"supplier": "MakarnaA.Ş."
},
{
"name": "Salatalık",
"desc": "Taze ve organik salatalık",
"type": "Sebze",
"banner": "",
"unit": 1,
"price": 1.5,
"available": true,
"supplier": "SebzeBahçesi"
},
{
"name": "Kola",
"desc": "Kafeinsiz gazlı içecek",
"type": "İçecek",
"banner": "",
"unit": 1,
"price": 1.25,
"available": true,
"supplier": "GazlıİçeceklerLtd."
},
{
"name": "Dondurma",
"desc": "Vanilyalı dondurma",
"type": "Dondurma",
"banner": "İndirimde",
"unit": 1,
"price": 4.99,
"available": true,
"supplier": "Dondurmacı"
},
{
"name": "Bisküvi",
"desc": "Çikolatalı bisküvi",
"type": "Atıştırmalık",
"banner": "",
"unit": 1,
"price": 2.0,
"available": true,
"supplier": "BisküviFabrikası"
},
{
"name": "Portakal Suyu",
"desc": "Taze sıkılmış portakal suyu",
"type": "MeyveSuları",
"banner": "",
"unit": 1,
"price": 4.5,
"available": true,
"supplier": "SıkılmışSularA.Ş."
},
{
"name": "Çilek",
"desc": "Taze ve organik çilek",
"type": "Meyve",
"banner": "",
"unit": 1,
"price": 3.99,
"available": true,
"supplier": "MeyveBahçesi"
},
{
"name": "Yumurta",
"desc": "Organik tavuk yumurtası",
"type": "Yumurta",
"banner": "",
"unit": 1,
"price": 0.5,
"available": true,
"supplier": "YumurtaÇiftliği"
},
{
"name": "Patates",
"desc": "Taze ve organik patates",
"type": "Sebze",
"banner": "",
"unit": 1,
"price": 2.0,
"available": true,
"supplier": "SebzeBahçesi"
},
{
"name": "Balık",
"desc": "Taze deniz ürünü balık",
"type": "Balık",
"banner": "",
"unit": 1,
"price": 7.99,
"available": true,
"supplier": "Balıkçı"
},
{
"name": "Domates",
"desc": "Taze ve organik domates",
"type": "Sebze",
"banner": "",
"unit": 1,
"price": 2.5,
"available": true,
"supplier": "SebzeBahçesi"
}
]
12 changes: 0 additions & 12 deletions products/.env.dev

This file was deleted.

10 changes: 10 additions & 0 deletions products/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
APP_SECRET='example-app-secret-key'

MONGODB_URI='mongodb://mongo_db/microservices_product'
MSG_QUEUE_URL='amqp://rabbitmq'
SENTRY_DSN='[YOUR_SENTRY_DSN]'

EXCHANGE_NAME='ONLINE_STORE'

PORT=8006

1 change: 1 addition & 0 deletions products/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ web_modules/
.env.test.local
.env.production.local
.env.local
.env.dev

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
4 changes: 2 additions & 2 deletions products/src/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default async function (app, channel) {
*/
app.post('/product/create', async (req, res, next) => {
try {
const { name, desc, type, unit, price, available, suplier, banner } = req.body;
const { data } = await service.CreateProduct({ name, desc, type, unit, price, available, suplier, banner });
const { name, desc, type, unit, price, available, supplier, banner } = req.body;
const { data } = await service.CreateProduct({ name, desc, type, unit, price, available, supplier, banner });
return res.json(data);
} catch (err) {
next(err);
Expand Down
2 changes: 1 addition & 1 deletion products/src/database/models/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ProductSchema = new Schema({
unit: Number,
price: Number,
available: Boolean,
suplier: String,
supplier: String,
});

const Product = mongoose.model('Product', ProductSchema);
Expand Down
4 changes: 2 additions & 2 deletions products/src/database/repository/product-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProductRepository {
* @returns {Promise<Object>} The created product object.
* @throws {APIError} When there is an error creating the product.
*/
async CreateProduct({ name, desc, type, unit, price, available, suplier, banner }) {
async CreateProduct({ name, desc, type, unit, price, available, supplier, banner }) {
try {
const product = new Product({
name,
Expand All @@ -24,7 +24,7 @@ class ProductRepository {
unit,
price,
available,
suplier,
supplier,
banner,
});

Expand Down
Loading
Loading