Skip to content

Commit a5fa054

Browse files
authored
Merge pull request #535 from karlomikus/develop
next release
2 parents 99e267b + 00b4d73 commit a5fa054

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1003
-587
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# v5.9.0
2+
# New
3+
- Documented `public/{slugOrId}` endpoints
4+
- You can now access public bar data via `public/{slugOrId}` endpoints
5+
- Added GET `public/{slugOrId}/menu` endpoint
6+
- Added GET `public/{slugOrId}/cocktails` endpoint
7+
- Added GET `public/{slugOrId}/cocktails/{cocktailId}` endpoint
8+
- Added `is_public` property to `Bar` schema
9+
- If set to `true`, bar will expose public endpoints `/public/{barId}/*`
10+
- Added `is_menu_enabled` to public `Bar` schema
11+
12+
## Fixes
13+
- Fixed search driver indexing calls when not using search driver
14+
- Default ingredient unit bar setting is not correctly applied when importing data via datapack
15+
- Fixed unique constraint violation when adding ingredients into bar shelf
16+
17+
# v5.8.1
18+
## Fixes
19+
- Fixed missing API ability on `import/cocktail` endpoint
20+
121
# v5.8.0
222
## New
323
- Added `bars/{id}/sync-datapack` endpoint

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ This repository only contains the API server, if you are looking for easy to use
4949
- Data export support in various formats
5050
- Support for multiple ingredient prices
5151
- Automatic cocktail price calculation based on ingredients
52-
- SSO Support
52+
- Single sign-on (SSO) support
53+
- Recipe recommendations based on your favorites and tags
54+
55+
## Documentation
56+
57+
[Documentation is available here.](https://docs.barassistant.app/)
5358

5459
## Container images
5560

@@ -63,13 +68,13 @@ We recommend that you always use the latest major release, as it will always be
6368

6469
## Managed instance
6570

66-
Bar Assistant will always be open-source and MIT-licensed, but if you want to support the project or don't want to self-host, you can try officialy managed instance. Visit [barassistant.app](https://barassistant.app/) for more information about our cloud offering.
71+
Bar Assistant will always be open-source and MIT-licensed, but if you want to support the project or don't want to self-host, you can try our official managed instance. Visit [barassistant.app](https://barassistant.app/) for more information about our cloud offering.
6772

6873
![Cloud offering screenshot](/resources/art/art1.png)
6974

70-
## Documentation
75+
## 3rd Party Integrations
7176

72-
[Documentation is available here.](https://bar-assistant.github.io/docs/)
77+
There's an [unofficial Raycast extension](https://www.raycast.com/stupifier/barassistant) maintained by a [community member](https://github.com/zhdenny).
7378

7479
## Contributing
7580

app/External/Export/ToDataPack.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function process(int $barId, ?string $filename = null, ForceUnitConvertEn
6565
}
6666

6767
$this->dumpCocktails($barId, $zip, $toUnits);
68-
$this->dumpIngredients($barId, $zip);
68+
$this->dumpIngredients($barId, $zip, $toUnits);
6969
$this->dumpBaseData($barId, $zip);
7070
$this->dumpCalculators($barId, $zip);
7171

@@ -111,13 +111,13 @@ private function dumpCocktails(int $barId, ZipArchive &$zip, ?Units $toUnits = n
111111
}
112112
}
113113

114-
private function dumpIngredients(int $barId, ZipArchive &$zip): void
114+
private function dumpIngredients(int $barId, ZipArchive &$zip, ?Units $toUnits = null): void
115115
{
116116
$ingredients = Ingredient::with('images.imageable', 'calculator', 'prices.priceCategory', 'ingredientParts.ingredient.parentIngredient', 'ancestors', 'parentIngredient')->where('bar_id', $barId)->get();
117117

118118
/** @var Ingredient $ingredient */
119119
foreach ($ingredients as $ingredient) {
120-
$data = IngredientExternal::fromModel($ingredient, true);
120+
$data = IngredientExternal::fromModel($ingredient, true, $toUnits);
121121

122122
/** @var \Kami\Cocktail\Models\Image $img */
123123
foreach ($ingredient->images as $img) {

app/External/Import/FromDataPack.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ public function process(Filesystem $dataDisk, Bar $bar, User $user, ?BarOptionsE
7676

7777
$bar->setStatus(BarStatusEnum::Active)->save();
7878

79-
/** @phpstan-ignore-next-line */
80-
Ingredient::where('bar_id', $bar->id)->searchable();
81-
/** @phpstan-ignore-next-line */
82-
Cocktail::where('bar_id', $bar->id)->searchable();
79+
if (!empty(config('scout.driver'))) {
80+
/** @phpstan-ignore-next-line */
81+
Ingredient::where('bar_id', $bar->id)->searchable();
82+
/** @phpstan-ignore-next-line */
83+
Cocktail::where('bar_id', $bar->id)->searchable();
84+
}
8385

8486
$timerEnd = microtime(true);
8587

@@ -192,6 +194,12 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user):
192194
continue;
193195
}
194196

197+
$ingredientUnit = $externalIngredient->units?->value;
198+
$barSettings = $bar->settings ?? [];
199+
if ($externalIngredient->units?->isConvertable() && array_key_exists('default_units', $barSettings)) {
200+
$ingredientUnit = $barSettings['default_units'];
201+
}
202+
195203
$slug = $externalIngredient->id . '-' . $bar->id;
196204
$ingredientsToInsert[] = [
197205
'bar_id' => $bar->id,
@@ -208,7 +216,7 @@ private function importIngredients(Filesystem $dataDisk, Bar $bar, User $user):
208216
'sugar_g_per_ml' => $externalIngredient->sugarContent,
209217
'acidity' => $externalIngredient->acidity,
210218
'distillery' => $externalIngredient->distillery,
211-
'units' => $externalIngredient->units,
219+
'units' => $ingredientUnit,
212220
];
213221

214222
if ($externalIngredient->parentId) {

app/External/Model/Ingredient.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
namespace Kami\Cocktail\External\Model;
66

77
use Kami\Cocktail\External\SupportsCSV;
8+
use Kami\RecipeUtils\UnitConverter\Units;
89
use Kami\Cocktail\External\SupportsDraft2;
910
use Kami\Cocktail\Models\ComplexIngredient;
1011
use Kami\Cocktail\External\SupportsDataPack;
1112
use Kami\Cocktail\Models\Image as ImageModel;
13+
use Kami\Cocktail\Models\ValueObjects\UnitValueObject;
1214
use Kami\Cocktail\Models\Ingredient as IngredientModel;
1315
use Kami\Cocktail\Models\IngredientPrice as IngredientPriceModel;
1416

@@ -37,11 +39,11 @@ private function __construct(
3739
public ?float $sugarContent = null,
3840
public ?float $acidity = null,
3941
public ?string $distillery = null,
40-
public ?string $units = null,
42+
public ?UnitValueObject $units = null,
4143
) {
4244
}
4345

44-
public static function fromModel(IngredientModel $model, bool $useFileURI = false): self
46+
public static function fromModel(IngredientModel $model, bool $useFileURI = false, ?Units $toUnits = null): self
4547
{
4648
$images = $model->images->map(function (ImageModel $image) use ($useFileURI) {
4749
return Image::fromModel($image, $useFileURI);
@@ -55,6 +57,11 @@ public static function fromModel(IngredientModel $model, bool $useFileURI = fals
5557
return IngredientPrice::fromModel($price);
5658
})->toArray();
5759

60+
$defaultIngredientUnits = $model->getDefaultUnits();
61+
if ($model->getDefaultUnits()?->isConvertable() && $toUnits) {
62+
$defaultIngredientUnits = new UnitValueObject($toUnits->value);
63+
}
64+
5865
return new self(
5966
id: $model->getExternalId(),
6067
name: $model->name,
@@ -73,7 +80,7 @@ public static function fromModel(IngredientModel $model, bool $useFileURI = fals
7380
sugarContent: $model->sugar_g_per_ml,
7481
acidity: $model->acidity,
7582
distillery: $model->distillery,
76-
units: $model->getDefaultUnits()?->value,
83+
units: $defaultIngredientUnits,
7784
);
7885
}
7986

@@ -112,7 +119,7 @@ public static function fromDataPackArray(array $sourceArray): self
112119
sugarContent: $sourceArray['sugar_g_per_ml'] ?? null,
113120
acidity: $sourceArray['acidity'] ?? null,
114121
distillery: $sourceArray['distillery'] ?? null,
115-
units: $sourceArray['units'] ?? null,
122+
units: ($sourceArray['units'] ?? null) ? new UnitValueObject($sourceArray['units']) : null,
116123
);
117124
}
118125

@@ -136,7 +143,7 @@ public function toDataPackArray(): array
136143
'sugar_g_per_ml' => $this->sugarContent,
137144
'acidity' => $this->acidity,
138145
'distillery' => $this->distillery,
139-
'units' => $this->units,
146+
'units' => $this->units?->value,
140147
];
141148
}
142149

@@ -161,7 +168,7 @@ public static function fromCSV(array $sourceArray): self
161168
sugarContent: blank($sourceArray['sugar_g_per_ml']) ? null : $sourceArray['sugar_g_per_ml'],
162169
acidity: blank($sourceArray['acidity']) ? null : $sourceArray['acidity'],
163170
distillery: blank($sourceArray['distillery']) ? null : $sourceArray['distillery'],
164-
units: blank($sourceArray['units']) ? null : $sourceArray['units'],
171+
units: blank($sourceArray['units']) ? null : new UnitValueObject($sourceArray['units']),
165172
);
166173
}
167174

app/Http/Controllers/BarController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Kami\Cocktail\Http\Controllers;
66

7+
use Throwable;
78
use Illuminate\Http\Request;
89
use Illuminate\Http\Response;
910
use Kami\Cocktail\Models\Bar;
@@ -87,7 +88,7 @@ public function show(Request $request, int $id): JsonResource
8788
public function store(BarRequest $request): JsonResponse
8889
{
8990
if ($request->user()->cannot('create', Bar::class)) {
90-
abort(403, 'You can not create anymore bars');
91+
abort(403, 'You can not create any more bars.');
9192
}
9293

9394
Cache::forget('metrics_bass_total_bars');
@@ -106,7 +107,7 @@ public function store(BarRequest $request): JsonResponse
106107
try {
107108
$imageModels = Image::findOrFail($barRequest->images);
108109
$bar->attachImages($imageModels);
109-
} catch (\Throwable $e) {
110+
} catch (Throwable $e) {
110111
abort(500, $e->getMessage());
111112
}
112113
}
@@ -167,7 +168,7 @@ public function update(int $id, BarRequest $request): JsonResource
167168
try {
168169
$imageModels = Image::findOrFail($barRequest->images);
169170
$bar->attachImages($imageModels);
170-
} catch (\Throwable $e) {
171+
} catch (Throwable $e) {
171172
abort(500, $e->getMessage());
172173
}
173174
}

app/Http/Controllers/GlassController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ public function update(int $id, GlassRequest $request): JsonResource
132132
}
133133
}
134134

135-
$glass->cocktails->each(fn ($cocktail) => $cocktail->searchable());
135+
if (!empty(config('scout.driver'))) {
136+
$glass->cocktails->each(fn ($cocktail) => $cocktail->searchable());
137+
}
136138

137139
return new GlassResource($glass);
138140
}

app/Http/Controllers/MenuController.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
use Kami\Cocktail\Rules\ResourceBelongsToBar;
1616
use Kami\Cocktail\Http\Resources\MenuResource;
1717
use Illuminate\Http\Resources\Json\JsonResource;
18-
use Kami\Cocktail\Models\Enums\MenuItemTypeEnum;
18+
use Kami\Cocktail\OpenAPI\Schemas\MenuItemRequest;
1919
use Kami\Cocktail\Http\Resources\MenuPublicResource;
20+
use Kami\Cocktail\OpenAPI\Schemas\MenuRequest as SchemasMenuRequest;
2021

2122
class MenuController extends Controller
2223
{
@@ -98,27 +99,26 @@ public function update(MenuRequest $request): MenuResource
9899
abort(403);
99100
}
100101

101-
/** @var array<mixed> */
102-
$items = $request->input('items', []);
102+
$schemaRequest = SchemasMenuRequest::fromIlluminateRequest($request);
103103

104-
$ingredients = collect($items)->where('type', MenuItemTypeEnum::Ingredient->value)->values()->toArray();
105-
$cocktails = collect($items)->where('type', MenuItemTypeEnum::Cocktail->value)->values()->toArray();
104+
$ingredients = $schemaRequest->getIngredients();
105+
$cocktails = $schemaRequest->getCocktails();
106106

107-
Validator::make($ingredients, [
107+
Validator::make(collect($ingredients)->map(fn (MenuItemRequest $mi) => ['id' => $mi->id])->toArray(), [
108108
'*.id' => [new ResourceBelongsToBar(bar()->id, 'ingredients')],
109109
])->validate();
110110

111-
Validator::make($cocktails, [
111+
Validator::make(collect($cocktails)->map(fn (MenuItemRequest $mi) => ['id' => $mi->id])->toArray(), [
112112
'*.id' => [new ResourceBelongsToBar(bar()->id, 'cocktails')],
113113
])->validate();
114114

115115
$menu = Menu::firstOrCreate(['bar_id' => bar()->id]);
116-
$menu->is_enabled = $request->boolean('is_enabled');
116+
$menu->is_enabled = $schemaRequest->isEnabled;
117117
if (!$menu->created_at) {
118118
$menu->created_at = now();
119119
}
120120
$menu->updated_at = now();
121-
$menu->syncItems($items);
121+
$menu->syncItems($schemaRequest->items);
122122
$menu->save();
123123

124124
return new MenuResource($menu);

app/Http/Controllers/Public/BarController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212

1313
class BarController extends Controller
1414
{
15-
#[OAT\Get(path: '/public/{barId}', tags: ['Public'], operationId: 'showPublicBar', description: 'Show public information about a single bar. To access this endpoint the bar must be marked as public.', summary: 'Show bar', parameters: [
16-
new OAT\Parameter(name: 'barId', in: 'path', required: true, description: 'Database id of bar', schema: new OAT\Schema(type: 'number')),
15+
#[OAT\Get(path: '/public/{slugOrId}', tags: ['Public'], operationId: 'showPublicBar', description: 'Show public information about a single bar. To access this endpoint the bar must be marked as public.', summary: 'Show bar', parameters: [
16+
new OAT\Parameter(name: 'slugOrId', in: 'path', required: true, description: 'Database id of bar', schema: new OAT\Schema(type: 'string')),
1717
new BAO\Parameters\PageParameter(),
1818
], security: [])]
1919
#[BAO\SuccessfulResponse(content: [
2020
new BAO\WrapObjectWithData(BarResource::class),
2121
])]
2222
#[BAO\NotFoundResponse]
23-
public function show(int $barId): BarResource
23+
public function show(string $slugOrId): BarResource
2424
{
25-
$bar = Bar::findOrFail($barId);
26-
if (!$bar->is_public) {
25+
$bar = Bar::where('slug', $slugOrId)->orWhere('id', $slugOrId)->firstOrFail();
26+
if (!$bar->isPublic()) {
2727
abort(404);
2828
}
2929

0 commit comments

Comments
 (0)