Skip to content

Commit

Permalink
feat: add article max_order_amount (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonostendorf authored Oct 6, 2024
1 parent 006289a commit 024d1b5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ APP_DEBUG=true
APP_URL=http://localhost
APP_PUBLIC_URL=http://localhost
APP_IS_VPN=false
VITE_APP_MAX_ORDER_COUNT=8

APP_PORTALS_URL=http://127.0.0.1:8000
APP_PORTALS_API_SECRET=secret
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function buy(Request $request, int $id, int $articleID)
$article = Article::findOrFail($articleID);

$amount = $request['amount'];
if (! is_numeric($amount) || $amount < 1 || $amount > env('VITE_APP_MAX_ORDER_COUNT')) {
if (! is_numeric($amount) || $amount < 1 || $amount > $article->max_order_amount) {
return Redirect::route('person.show', ['id' => $id]);
}

Expand Down
1 change: 1 addition & 0 deletions app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ class Article extends Model
'name',
'icon',
'show_order',
'max_order_amount',
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('articles', function (Blueprint $table) {
$table->integer('max_order_amount')->nullable(false)->default(1);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('articles', function (Blueprint $table) {
$table->dropColumn('max_order_amount');
});
}
};
4 changes: 4 additions & 0 deletions database/seeders/ArticleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ class ArticleSeeder extends Seeder
'name' => 'Bier',
'icon' => 'beer',
'show_order' => 1,
'max_order_amount' => 8,
],
[
'name' => 'Radler',
'icon' => 'lemon',
'show_order' => 2,
'max_order_amount' => 8,
],
[
'name' => 'Softdrinks',
'icon' => 'wine-bottle',
'show_order' => 3,
'max_order_amount' => 8,
],
[
'name' => 'Wasser',
'icon' => 'faucet',
'show_order' => 4,
'max_order_amount' => 8,
],
];

Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/ArticleCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default defineComponent({
emits: ['submit'],
setup(props, ctx) {
const amount = ref(1);
const maxAmount = parseInt(import.meta.env.VITE_APP_MAX_ORDER_COUNT);
const maxAmount = props.article.max_order_amount;
const disabled = ref(false);
const timeoutSeconds = 3;
Expand Down

0 comments on commit 024d1b5

Please sign in to comment.