Skip to content

Commit

Permalink
feat: ensuring working with both mysql and postgres
Browse files Browse the repository at this point in the history
Signed-off-by: Fawzi Abdulfattah <iifawzie@gmail.com>
  • Loading branch information
iifawzi committed Dec 13, 2023
1 parent e347854 commit bf18902
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/Models/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class OrderItem extends Model
use HasFactory;

public $timestamps = false;
protected $fillable = ["quantity", "unit_price", "total_price", "product_id", "order_id"];
protected $fillable = ["quantity", "unit_price", "total_price", "product_id"];
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up(): void
$table->string("description");
$table->string("price");

$table->foreignId('merchant_id')->type("integer");
$table->unsignedInteger('merchant_id');
$table->foreign('merchant_id')->on('merchants')->references('merchant_id');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function up(): void
$table->unsignedInteger('min_threshold_percentage');
$table->timestamps();

$table->foreignId('merchant_id')->type("integer");
$table->unsignedInteger('merchant_id');
$table->foreign("merchant_id")->on('merchants')->references("merchant_id");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function up(): void
Schema::create('product_ingredients', function (Blueprint $table) {
$table->unsignedInteger('base_quantity');

$table->foreignId('product_id')->type("integer");
$table->foreignId('ingredient_id')->type("integer");
$table->unsignedInteger('product_id');
$table->unsignedInteger('ingredient_id');
$table->foreign('product_id')->on('products')->references('product_id');
$table->foreign('ingredient_id')->on('ingredient_stocks')->references('ingredient_id');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
public function up(): void
{
Schema::create('stock_transactions', function (Blueprint $table) {
$table->uuid('transaction_id')->primary();
$table->string('transaction_id')->primary();
$table->unsignedInteger("quantity");
$table->text("reason");
$table->string("type");
$table->timestamps();

$table->foreignId("ingredient_id")->type("integer");
$table->unsignedInteger("ingredient_id");
$table->foreign("ingredient_id")->on("ingredient_stocks")->references("ingredient_id");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
public function up(): void
{
Schema::create('low_stock_notifications', function (Blueprint $table) {
$table->uuid("notification_id")->primary();
$table->string("notification_id")->primary();
$table->string("status");
$table->timestamps();

$table->foreignId("ingredient_id")->type("integer");
$table->unsignedInteger("ingredient_id");
$table->foreign("ingredient_id")->on("ingredient_stocks")->references("ingredient_id");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('orders', function (Blueprint $table) {
$table->uuid("order_id")->primary();
$table->string("order_id")->primary();
$table->string("status");
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public function up(): void
$table->unsignedInteger("quantity");
$table->unsignedInteger('total_price');

$table->foreignUuid('order_id');
$table->string('order_id');
$table->foreign('order_id')->on('orders')->references('order_id');

$table->foreignId('product_id')->type("integer");
$table->unsignedInteger('product_id')->type("integer");
$table->foreign('product_id')->on('products')->references('product_id');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Src\Infrastructure\repositories\Eloquent;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Src\Application\ports\infrastructure\repositories\OrderRepository;
use Src\Domain\Entities\Order;

Expand All @@ -19,17 +18,16 @@ public function saveOrder(Order $order): void
"unit_price" => $item->getUnitPrice(),
"total_price" => $item->getTotalPrice(),
"product_id" => $item->getId(),
"order_id" => "e6fe146e-77db-4869-8921-5761560e3bfa",
];
}


/**
* @var \App\Models\Order $orderModel
* @var \App\Models\Order $orderModel
*/
$orderModel = \App\Models\Order::factory()->createOne(
[
"order_id" => $order->getId(),
"order_id" => $order->getId()->toString(),
"status" => $order->getStatus(),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EloquentStockRepository implements StockRepository

public function getStockItems(array $ingredientIds): array
{
$stockItems = IngredientStock::query()->whereIn("ingredient_id", $ingredientIds)->get()->all();
$stockItems = IngredientStock::query()->whereIn("ingredient_id", $ingredientIds)->lockForUpdate()->get()->all();

$items = [];
foreach ($stockItems as $stockItem) {
Expand Down

0 comments on commit bf18902

Please sign in to comment.