Skip to content

Commit

Permalink
Merge pull request #17 from karlomikus/develop
Browse files Browse the repository at this point in the history
Version 0.4.0
  • Loading branch information
karlomikus committed Nov 18, 2022
2 parents e8431c4 + ed8d0fd commit dee798a
Show file tree
Hide file tree
Showing 42 changed files with 1,520 additions and 267 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.4.0
- Refactor image uploading and handling
- Updates for some base ingredients
- Add more popular cocktails
- Finish cocktail ingredient substitutes endpoints
- Finish glass type endpoints

# v0.3.0
- Move "Uncategorized" ingredient category to id: 1
- Cocktail save/update methods now save glass type
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Commands/BarExportCocktails.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BarExportCocktails extends Command
public function handle()
{
$dump = [];
Cocktail::with('tags', 'ingredients.ingredient')->orderBy('name')->chunk(200, function ($cocktails) use (&$dump) {
Cocktail::with('tags', 'ingredients.ingredient')->orderBy('created_at')->chunk(200, function ($cocktails) use (&$dump) {
foreach ($cocktails as $cocktail) {
$dump[] = [
'name' => $cocktail->name,
Expand All @@ -40,6 +40,7 @@ public function handle()
'source' => $cocktail->source,
'image_copyright' => $cocktail->images->first()->copyright ?? null,
'tags' => $cocktail->tags->pluck('name')->toArray(),
'glass' => $cocktail->glass->name,
'ingredients' => $cocktail->ingredients->map(function ($cIng) {
return [
'amount' => $cIng->amount,
Expand Down
46 changes: 29 additions & 17 deletions app/Console/Commands/OpenBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ public function handle()
Ingredient::create(['name' => 'Triple Sec', 'ingredient_category_id' => $liqueurs->id, 'strength' => 40.0, 'description' => 'Triple sec is usually made from orange peels steeped in a spirit derived from sugar beet due to its neutral flavor. Oranges are then harvested when their skin is still green and they have not fully ripened, so the essential oils remain in the skin and not the flesh of the fruit. This spirit is then redistilled and mixed with more neutral spirit, water, and powdered beet sugar resulting in the final liqueur. This process creates a spirit that has a very strong and distinct orange flavor.', 'color' => '#ffffff', 'origin' => 'France', 'user_id' => 1]);
Ingredient::create(['name' => 'Maraschino', 'ingredient_category_id' => $liqueurs->id, 'strength' => 32.0, 'description' => 'Liqueur obtained from the distillation of Marasca cherries. The small, slightly sour fruit of the Tapiwa cherry tree, which grows wild along parts of the Dalmatian coast in Croatia, lends the liqueur its unique aroma.', 'color' => '#ffffff', 'origin' => 'Croatia', 'user_id' => 1]);
Ingredient::create(['name' => 'Galliano', 'ingredient_category_id' => $liqueurs->id, 'strength' => 42.3, 'description' => 'Galliano is sweet with vanilla-anise flavour and subtle citrus and woodsy herbal undernotes.', 'color' => '#caa701', 'origin' => 'Italy', 'user_id' => 1]);
Ingredient::create(['name' => 'Orange Curaçao', 'ingredient_category_id' => $liqueurs->id, 'strength' => 20.0, 'description' => 'Liqueur flavored with the dried peel of the bitter orange laraha, a citrus fruit grown on the Dutch island of Curaçao.', 'color' => '#edaa53', 'origin' => 'Netherlands', 'user_id' => 1]);
Ingredient::create(['name' => 'Blue Curaçao', 'ingredient_category_id' => $liqueurs->id, 'strength' => 20.0, 'description' => 'Liqueur flavored with the dried peel of the bitter orange laraha, a citrus fruit grown on the Dutch island of Curaçao.', 'color' => '#0192fe', 'origin' => 'Netherlands', 'user_id' => 1]);
Ingredient::create(['name' => 'Chambord', 'ingredient_category_id' => $liqueurs->id, 'strength' => 16.5, 'description' => 'Raspberry liqueur modelled after a liqueur produced in the Loire Valley of France during the late 17th century.', 'color' => '#6f1123', 'origin' => 'Worldwide', 'user_id' => 1]);
Ingredient::create(['name' => 'Falernum', 'ingredient_category_id' => $liqueurs->id, 'strength' => 11.0, 'description' => 'Liqueur with flavors of ginger, lime, and almond, and frequently cloves or allspice. It may be thought of as a spicier version of orgeat syrup.', 'color' => '#f4f2e5', 'origin' => 'Caribbean', 'user_id' => 1]);
Ingredient::create(['name' => 'Green Chartreuse', 'ingredient_category_id' => $liqueurs->id, 'strength' => 55.0, 'description' => 'Green Chartreuse is a naturally green liqueur made from 130 herbs and other plants macerated in alcohol and steeped for about eight hours.', 'color' => '#85993a', 'origin' => 'France', 'user_id' => 1]);
Expand All @@ -176,6 +174,11 @@ public function handle()
Ingredient::create(['name' => 'Ouzo', 'ingredient_category_id' => $liqueurs->id, 'strength' => 35.0, 'description' => 'Dry anise-flavored aperitif that is widely consumed in Greece.', 'color' => '#ffffff', 'origin' => 'Greece', 'user_id' => 1]);
Ingredient::create(['name' => 'Passoã', 'ingredient_category_id' => $liqueurs->id, 'strength' => 17.0, 'description' => 'Liqueur with passion fruit being the main ingredient.', 'color' => '#ea5f4c', 'origin' => 'France', 'user_id' => 1]);
Ingredient::create(['name' => 'Fernet Branca', 'ingredient_category_id' => $liqueurs->id, 'strength' => 39.0, 'description' => 'Fernet Branca is a bittersweet, herbal liqueur made with a number of different herbs and spices, including myrrh, rhubarb, chamomile, cardamom, aloe, and gentian root.', 'origin' => 'Italy', 'user_id' => 1]);
Ingredient::create(['name' => 'Baileys Irish Cream', 'ingredient_category_id' => $liqueurs->id, 'strength' => 17.0, 'description' => 'Baileys Irish Cream is an Irish cream liqueur, an alcoholic drink flavoured with cream, cocoa and Irish whiskey. It is made by Diageo at Nangor Road, in Dublin, Ireland and in Mallusk, Northern Ireland. It is the original Irish cream, invented by a team headed by Tom Jago in 1971 for Gilbeys of Ireland.', 'origin' => 'Ireland', 'user_id' => 1]);

$curacao = Ingredient::create(['name' => 'Orange Curaçao', 'ingredient_category_id' => $liqueurs->id, 'strength' => 20.0, 'description' => 'Liqueur flavored with the dried peel of the bitter orange laraha, a citrus fruit grown on the Dutch island of Curaçao. Curaçao is used by liqueur makers the world over as a generic name for orange-flavoured liqueurs.', 'color' => '#edaa53', 'origin' => 'Netherlands', 'user_id' => 1]);
Ingredient::create(['name' => 'Dry Curaçao', 'parent_ingredient_id' => $curacao->id, 'ingredient_category_id' => $liqueurs->id, 'strength' => 40.0, 'description' => 'Cognac Ferrand\'s innovative owner Alexandre Gabriel, followed an old recipe and modified it to create this curaçao. While Curaçao and sweet oranges are the main ingredients, vanilla, prunes and lemon peel are amongst the other botanicals called for in the old recipe.', 'origin' => 'Italy', 'user_id' => 1]);
Ingredient::create(['name' => 'Blue Curaçao', 'parent_ingredient_id' => $curacao->id, 'ingredient_category_id' => $liqueurs->id, 'strength' => 20.0, 'description' => 'Liqueur flavored with the dried peel of the bitter orange laraha, a citrus fruit grown on the Dutch island of Curaçao.', 'color' => '#0192fe', 'origin' => 'Netherlands', 'user_id' => 1]);

// Juices
Ingredient::create(['name' => 'Lemon juice', 'ingredient_category_id' => $juices->id, 'strength' => 0.0, 'description' => 'Freshly squeezed lemon juice.', 'color' => '#f3efda', 'user_id' => 1]);
Expand Down Expand Up @@ -251,19 +254,23 @@ public function handle()
Ingredient::create(['name' => 'Ginger syrup', 'ingredient_category_id' => $syrups->id, 'description' => 'Syrup made from ginger root.', 'color' => '#c6972c', 'user_id' => 1]);

// Wines
Ingredient::create(['name' => 'Sweet Vermouth', 'ingredient_category_id' => $wines->id, 'strength' => 18.0, 'description' => 'Aromatized fortified wine.', 'color' => '#8e4201', 'user_id' => 1]);
Ingredient::create(['name' => 'Dry Vermouth', 'ingredient_category_id' => $wines->id, 'strength' => 18.0, 'description' => 'Aromatized fortified wine.', 'color' => '#ffffff', 'user_id' => 1]);
Ingredient::create(['name' => 'White wine', 'ingredient_category_id' => $wines->id, 'strength' => 11.0, 'description' => 'Wine is an alcoholic drink typically made from fermented grapes.', 'color' => '#f6e1b0', 'user_id' => 1]);
Ingredient::create(['name' => 'Red wine', 'ingredient_category_id' => $wines->id, 'strength' => 11.0, 'description' => 'Red wine is a type of wine made from dark-colored grape varieties.', 'color' => '#801212', 'user_id' => 1]);
Ingredient::create(['name' => 'Prosecco', 'ingredient_category_id' => $wines->id, 'strength' => 11.0, 'description' => 'Sparkling wine made from Prosecco grapes.', 'color' => '#a57600', 'user_id' => 1]);
Ingredient::create(['name' => 'Champagne', 'ingredient_category_id' => $wines->id, 'strength' => 12.0, 'description' => 'Sparkling wine.', 'color' => '#f6e1b0', 'user_id' => 1]);
Ingredient::create(['name' => 'Lillet Blanc', 'ingredient_category_id' => $wines->id, 'strength' => 17.0, 'description' => 'Aromatized sweet wine.', 'color' => '#f7ec77', 'user_id' => 1]);
Ingredient::create(['name' => 'Sweet Vermouth', 'ingredient_category_id' => $wines->id, 'strength' => 18.0, 'description' => 'Aromatized fortified wine.', 'color' => '#8e4201', 'user_id' => 1, 'origin' => 'Worldwide']);
Ingredient::create(['name' => 'Dry Vermouth', 'ingredient_category_id' => $wines->id, 'strength' => 18.0, 'description' => 'Aromatized fortified wine.', 'color' => '#ffffff', 'user_id' => 1, 'origin' => 'Worldwide']);
Ingredient::create(['name' => 'White wine', 'ingredient_category_id' => $wines->id, 'strength' => 11.0, 'description' => 'Wine is an alcoholic drink typically made from fermented grapes.', 'color' => '#f6e1b0', 'user_id' => 1, 'origin' => 'Worldwide']);
Ingredient::create(['name' => 'Red wine', 'ingredient_category_id' => $wines->id, 'strength' => 11.0, 'description' => 'Red wine is a type of wine made from dark-colored grape varieties.', 'color' => '#801212', 'user_id' => 1, 'origin' => 'Worldwide']);
Ingredient::create(['name' => 'Prosecco', 'ingredient_category_id' => $wines->id, 'strength' => 11.0, 'description' => 'Sparkling wine made from Prosecco grapes.', 'color' => '#a57600', 'user_id' => 1, 'origin' => 'Italy']);
Ingredient::create(['name' => 'Champagne', 'ingredient_category_id' => $wines->id, 'strength' => 12.0, 'description' => 'Sparkling wine.', 'color' => '#f6e1b0', 'user_id' => 1, 'origin' => 'France']);
Ingredient::create(['name' => 'Lillet Blanc', 'ingredient_category_id' => $wines->id, 'strength' => 17.0, 'description' => 'Aromatized sweet wine.', 'color' => '#f7ec77', 'user_id' => 1, 'origin' => 'France']);
Ingredient::create(['name' => 'Dry Sherry', 'ingredient_category_id' => $wines->id, 'strength' => 17.0, 'description' => 'Fortified wine made from white grapes that are grown near the city of Jerez de la Frontera in Andalusia, Spain.', 'color' => '#8c4122', 'user_id' => 1, 'origin' => 'Spain']);

$this->info('Attaching images to ingredients...');

// Create image for every ingredient
$ingredients = Ingredient::all();
foreach ($ingredients as $ing) {
if (!file_exists(storage_path('uploads/ingredients/' . Str::slug($ing->name) . '.png'))) {
continue;
}
$image = new Image();
$image->file_path = 'ingredients/' . Str::slug($ing->name) . '.png';
$image->file_extension = 'png';
Expand All @@ -278,7 +285,7 @@ public function handle()
$this->info('Finding some cocktail recipes...');

$this->importCocktailsFromJson(resource_path('/data/iba_cocktails_v0.1.0.yml'));
$this->importCocktailsFromJson(resource_path('/data/popular_cocktails_v0.3.0.yml'));
$this->importCocktailsFromJson(resource_path('/data/popular_cocktails.yml'));

Artisan::call('scout:import', ['model' => "Kami\Cocktail\Models\Cocktail"]);
Artisan::call('scout:import', ['model' => "Kami\Cocktail\Models\Ingredient"]);
Expand Down Expand Up @@ -361,13 +368,18 @@ private function importCocktailsFromJson(string $sourcePath)
$cocktailIng->optional = $sIngredient['optional'];
$cocktailIng->save();

// if (isset($sIngredient['substitutes'])) {
// foreach ($sIngredient['substitutes'] ?? [] as $subName) {
// $substitute = new CocktailIngredientSubstitute();
// $substitute->ingredient_id = $dbIngredients->filter(fn ($item) => $item->name == strtolower($subName))->first()->id ?? null;
// $cocktailIng->substitutes()->save($substitute);
// }
// }
if (isset($sIngredient['substitutes'])) {
foreach ($sIngredient['substitutes'] ?? [] as $subName) {
$foundIng = $dbIngredients->filter(fn ($item) => $item->name == strtolower($subName))->first()->id ?? null;
if (!$foundIng) {
continue;
}

$substitute = new CocktailIngredientSubstitute();
$substitute->ingredient_id = $foundIng;
$cocktailIng->substitutes()->save($substitute);
}
}
}

$cocktail->refresh();
Expand Down
41 changes: 41 additions & 0 deletions app/Console/Commands/TestScrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Kami\Cocktail\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Symfony\Component\HttpClient\CachingHttpClient;

class TestScrap extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bar:test';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// $scraper = new \Kami\Cocktail\Scraper\Scraper('https://tuxedono2.com/vieux-carre-cocktail-recipe');

// dd($scraper->toArray());

return Command::SUCCESS;
}
}
9 changes: 8 additions & 1 deletion app/Http/Controllers/CocktailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CocktailController extends Controller
* - Paginated by 15 items
* Optional query strings:
* - user_id -> Filter by user id
* - favorites -> Filter by user favorites
*/
public function index(Request $request)
{
Expand All @@ -28,6 +29,12 @@ public function index(Request $request)
$cocktails->where('user_id', $request->get('user_id'));
}

if ($request->has('favorites')) {
$cocktails->whereIn('id', function ($query) use ($request) {
$query->select('cocktail_id')->from('cocktail_favorites')->where('user_id', $request->user()->id);
});
}

return CocktailResource::collection($cocktails->paginate(15));
}

Expand Down Expand Up @@ -142,7 +149,7 @@ public function userShelf(CocktailService $cocktailService, Request $request)
/**
* Favorite a cocktail by id
*/
public function favorite(CocktailService $cocktailService, Request $request, int $id)
public function toggleFavorite(CocktailService $cocktailService, Request $request, int $id)
{
$isFavorite = $cocktailService->toggleFavorite($request->user(), $id);

Expand Down
25 changes: 25 additions & 0 deletions app/Http/Controllers/GlassController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);

namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Http\Request;
use Kami\Cocktail\Models\Glass;
use Kami\Cocktail\Http\Resources\GlassResource;

class GlassController extends Controller
{
public function index()
{
$glasses = Glass::orderBy('name')->get();

return GlassResource::collection($glasses);
}

public function show(int $id)
{
$glass = Glass::findOrFail($id);

return new GlassResource($glass);
}
}
8 changes: 8 additions & 0 deletions app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Http\Request;
use Kami\Cocktail\Models\Image;
use Kami\Cocktail\Services\ImageService;
use Kami\Cocktail\Http\Requests\ImageRequest;
Expand All @@ -25,6 +26,13 @@ public function store(ImageService $imageservice, ImageRequest $request)
return ImageResource::collection($images);
}

public function update(int $id, ImageService $imageservice, Request $request)
{
$image = $imageservice->updateImage($id, null, $request->input('copyright'));

return new ImageResource($image);
}

public function delete(int $id)
{
Image::findOrFail($id)->delete();
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Resources/CocktailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public function toArray($request)
'garnish' => e($this->garnish),
'description' => e($this->description),
'source' => $this->source,
'image_copyright' => $this->images->first()->copyright ?? null,
'image_url' => $this->getImageUrl(),
'image_id' => $this->images->first()->id ?? null,
'main_image_id' => $this->images->first()->id ?? null,
'images' => ImageResource::collection($this->images),
'tags' => $this->tags->pluck('name'),
'user_id' => $this->user_id,
'glass' => new GlassResource($this->whenLoaded('glass')),
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Resources/ImageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Kami\Cocktail\Http\Resources;

use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Resources\Json\JsonResource;

/**
Expand All @@ -21,6 +22,7 @@ public function toArray($request)
return [
'id' => $this->id,
'file_path' => $this->file_path,
'url' => $this->getImageUrl(),
'copyright' => $this->copyright,
'last_modified' => $this->updated_at,
];
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Resources/IngredientResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function toArray($request)
'strength' => $this->strength,
'description' => $this->description,
'origin' => $this->origin,
'image_url' => $this->getImageUrl(),
'main_image_id' => $this->images->first()->id ?? null,
'images' => ImageResource::collection($this->images),
'ingredient_category_id' => $this->ingredient_category_id,
'color' => $this->color,
'category' => new IngredientCategoryResource($this->category),
Expand All @@ -39,8 +40,8 @@ public function toArray($request)
];
})->toArray();
}),
'cocktails' => $this->whenLoaded('cocktails', function () {
return $this->cocktails->map(function ($c) {
'cocktails' => $this->when($this->relationLoaded('cocktails') || $this->relationLoaded('cocktailIngredientSubstitutes'), function () {
return $this->cocktails->merge($this->cocktailsAsSubstituteIngredient())->map(function ($c) {
return [
'id' => $c->id,
'slug' => $c->slug,
Expand Down
5 changes: 2 additions & 3 deletions app/Models/Cocktail.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Cocktail extends Model
use HasFactory, Searchable, HasImages, HasSlug;

private $appImagesDir = 'cocktails/';
private $missingImageFileName = 'no-image.jpg'; // TODO: WEBP

protected static function booted()
{
Expand Down Expand Up @@ -72,7 +71,7 @@ public function toSiteSearchArray()
'id' => $this->id,
'slug' => $this->slug,
'name' => $this->name,
'image_url' => $this->getImageUrl(),
'image_url' => $this->getMainImageUrl(),
'type' => 'cocktail',
];
}
Expand All @@ -87,7 +86,7 @@ public function toSearchableArray(): array
'description' => $this->description,
'source' => $this->source,
'garnish' => $this->garnish,
'image_url' => $this->getImageUrl(),
'image_url' => $this->getMainImageUrl(),
'short_ingredients' => $this->ingredients->pluck('ingredient.name'),
'user_id' => $this->user_id,
'tags' => $this->tags->pluck('name'),
Expand Down
Loading

0 comments on commit dee798a

Please sign in to comment.