Skip to content

Commit 8365b87

Browse files
authored
Merge pull request #504 from karlomikus/develop
Minor release
2 parents 1776cce + e616bbd commit 8365b87

17 files changed

+432
-255
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# v5.6.0
2+
## New
3+
- Added cocktail recipe parent ID tracking
4+
- Enables recipe varieties/riffs
5+
- Copying recipe will automatically reference the copied recipe as a parent cocktail
6+
- Added `parent_cocktail_id` to `Cocktail` schema
7+
- Added `varieties` to `Cocktail` schema
8+
- Added cocktail recipe year
9+
10+
## Fixes
11+
- Fixed missing detailed error message when scraping failes
12+
- Fixed calculator import error on null values
13+
114
# v5.5.1
215
## Fixes
316
- Fixed missing cocktail recipes with duplicated names in datapack export

app/External/Model/Cocktail.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ private function __construct(
3838
public array $utensils = [],
3939
public array $images = [],
4040
public array $ingredients = [],
41+
public ?int $parentCocktailId = null,
42+
public ?int $year = null,
4143
) {
4244
}
4345

@@ -67,6 +69,8 @@ public static function fromModel(CocktailModel $model, bool $useFileURI = false,
6769
$model->utensils->pluck('name')->toArray(),
6870
$images,
6971
$ingredients,
72+
$model->parent_cocktail_id,
73+
$model->year,
7074
);
7175
}
7276

@@ -98,6 +102,8 @@ public static function fromDataPackArray(array $sourceArray): self
98102
$sourceArray['utensils'] ?? [],
99103
$images,
100104
$ingredients,
105+
$sourceArray['parent_cocktail_id'] ?? null,
106+
$sourceArray['year'] ?? null,
101107
);
102108
}
103109

@@ -119,6 +125,8 @@ public function toDataPackArray(): array
119125
'utensils' => $this->utensils,
120126
'images' => array_map(fn ($model) => $model->toDataPackArray(), $this->images),
121127
'ingredients' => array_map(fn ($model) => $model->toDataPackArray(), $this->ingredients),
128+
'parent_cocktail_id' => $this->parentCocktailId,
129+
'year' => $this->year,
122130
];
123131
}
124132

app/Http/Controllers/CocktailController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ public function copy(string $idOrSlug, CocktailService $cocktailService, ImageSe
453453
$ingredients,
454454
$images,
455455
$cocktail->utensils->pluck('id')->toArray(),
456+
$cocktail->id,
456457
);
457458

458459
try {

app/Http/Controllers/ImportController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,11 @@ public function scrape(ScrapeRequest $request): JsonResponse
102102

103103
try {
104104
$scraper = Manager::scrape($request->input('source'));
105+
$dataToImport = $scraper->toArray();
105106
} catch (Throwable $e) {
106107
abort(400, $e->getMessage());
107108
}
108109

109-
$dataToImport = $scraper->toArray();
110-
111110
return response()->json([
112111
'data' => $dataToImport,
113112
]);

app/Http/Filters/CocktailQueryFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function __construct(CocktailService $cocktailRepo)
175175
->whereIn('cocktail_ingredients.ingredient_id', $value);
176176
});
177177
}),
178+
AllowedFilter::exact('parent_cocktail_id'),
178179
])
179180
->defaultSort('name')
180181
->allowedSorts([

app/Http/Resources/CocktailResource.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
'can_rate',
6060
'can_add_note',
6161
]),
62+
new OAT\Property(property: 'parent_cocktail', type: CocktailBasicResource::class, description: 'If this cocktail is a variety of existing cocktail, this will reference the original cocktail', nullable: true),
63+
new OAT\Property(property: 'varieties', type: 'array', items: new OAT\Items(type: CocktailBasicResource::class), description: 'List of varieties of this cocktail'),
64+
new OAT\Property(property: 'year', type: 'number', example: 2023, description: 'Cocktail recipe year', nullable: true),
6265
],
6366
required: [
6467
'id',
@@ -139,6 +142,11 @@ public function toArray($request)
139142
'can_add_note' => $request->user()->can('addNote', $this->resource),
140143
];
141144
}),
145+
'parent_cocktail' => $this->whenLoaded('parentCocktail', function () {
146+
return new CocktailBasicResource($this->parentCocktail);
147+
}),
148+
'varieties' => CocktailBasicResource::collection($this->whenLoaded('cocktailVarieties')),
149+
'year' => $this->year,
142150
];
143151
}
144152
}

app/Models/Cocktail.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ public function menuCocktails(): HasMany
129129
return $this->hasMany(MenuCocktail::class);
130130
}
131131

132+
/**
133+
* @return HasMany<Cocktail, $this>
134+
*/
135+
public function cocktailVarieties(): HasMany
136+
{
137+
return $this->hasMany(Cocktail::class, 'parent_cocktail_id');
138+
}
139+
140+
/**
141+
* @return BelongsTo<Cocktail, $this>
142+
*/
143+
public function parentCocktail(): BelongsTo
144+
{
145+
return $this->belongsTo(Cocktail::class, 'parent_cocktail_id');
146+
}
147+
132148
public function deleteFromMenu(): void
133149
{
134150
$this->menuCocktails()->delete();
@@ -434,6 +450,8 @@ public function loadDefaultRelations(): self
434450
'ratings',
435451
'ingredients.ingredient.bar.shelfIngredients',
436452
'ingredients.ingredient.descendants',
453+
'parentCocktail.images',
454+
'cocktailVarieties.images',
437455
]);
438456

439457
return $this;

app/OpenAPI/Schemas/CalculatorBlockRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function fromArray(array $source): self
4444
return new self(
4545
$source['label'],
4646
$source['variable_name'],
47-
$source['value'],
47+
$source['value'] ?? '',
4848
CalculatorBlockTypeEnum::from($source['type']),
4949
$settings,
5050
$source['description'] ?? null,

app/OpenAPI/Schemas/CocktailRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function __construct(
4141
public array $images = [],
4242
#[OAT\Property(items: new OAT\Items(type: 'integer'), description: 'List of existing utensil ids')]
4343
public array $utensils = [],
44+
#[OAT\Property(example: 1, property: 'parent_cocktail_id')]
45+
public ?int $parentCocktailId = null,
46+
#[OAT\Property(example: 2023, property: 'year')]
47+
public ?int $year = null,
4448
) {
4549
}
4650

@@ -68,6 +72,8 @@ public static function fromIlluminateRequest(Request $request, ?int $barId = nul
6872
$ingredients,
6973
$request->input('images', []),
7074
$request->input('utensils', []),
75+
$request->filled('parent_cocktail_id') ? $request->integer('parent_cocktail_id') : null,
76+
$request->filled('year') ? $request->integer('year') : null,
7177
);
7278
}
7379
}

app/Scraper/AbstractSiteExtractor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ abstract class AbstractSiteExtractor implements SiteExtractorContract
2727
public function __construct(
2828
protected readonly string $url,
2929
) {
30+
$saf = mt_rand(531, 536) . mt_rand(0, 2);
31+
$userAgent = "(X11; Linux x86_64) AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . mt_rand(36, 40) . '.0.' . mt_rand(800, 899) . ".0 Mobile Safari/$saf";
3032
$cachingMiddleware = new CacheMiddleware(new GreedyCacheStrategy(new LaravelCacheStorage(Cache::store()), 60 * 15));
3133
$response = Http::withMiddleware($cachingMiddleware)
34+
->withUserAgent($userAgent)
3235
->timeout(10)
3336
->get($url);
3437

0 commit comments

Comments
 (0)