Skip to content

Commit

Permalink
Add glass volume
Browse files Browse the repository at this point in the history
  • Loading branch information
karlomikus committed May 19, 2024
1 parent 1789651 commit 4b2f2ad
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Currently supports `default_units` and `default_lang`
- You can change units used in collection CSV, markdown and text share by passing query string `units` with one of the following units: `ml`, `cl`, `oz`
- CocktailIngredient schema now includes converted and formatted values for: `ml`, `cl`, `oz`
- Added `volume` to `Glass` schema

## Changes
- Updated cocktail text share format
Expand Down
5 changes: 5 additions & 0 deletions UPCOMING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Breaking
- Remove collections share
- Encode images into export file
- Bump php to 8.3
- Bump laravel to 11
2 changes: 2 additions & 0 deletions app/Http/Controllers/GlassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function store(GlassRequest $request): JsonResponse
$glass = new Glass();
$glass->name = $request->post('name');
$glass->description = $request->post('description');
$glass->volume = $request->float('volume');
$glass->bar_id = bar()->id;
$glass->save();

Expand All @@ -61,6 +62,7 @@ public function update(int $id, GlassRequest $request): JsonResource

$glass->name = $request->post('name');
$glass->description = $request->post('description');
$glass->volume = $request->float('volume');
$glass->updated_at = now();
$glass->save();

Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/GlassResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function toArray($request)
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'volume' => $this->volume,
'cocktails_count' => $this->whenCounted('cocktails'),
];
}
Expand Down
24 changes: 24 additions & 0 deletions app/Models/Glass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Database\Eloquent\Model;
use Kami\Cocktail\Models\Concerns\HasAuthors;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Kami\Cocktail\Models\Concerns\HasBarAwareScope;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -15,6 +16,29 @@ class Glass extends Model
{
use HasFactory, HasBarAwareScope, HasAuthors;

/**
* @return Attribute<?float, ?float>
*/
protected function volume(): Attribute
{
return Attribute::make(
get: function (?float $value) {
if ($value <= 0.0) {
return null;
}

return $value;
},
set: function (?float $value) {
if ($value <= 0.0) {
return null;
}

return $value;
},
);
}

/**
* @return HasMany<Cocktail>
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('glasses', function (Blueprint $table) {
$table->decimal('volume')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('glasses', function (Blueprint $table) {
$table->dropColumn('volume');
});
}
};

0 comments on commit 4b2f2ad

Please sign in to comment.