Skip to content

Commit

Permalink
Update spec
Browse files Browse the repository at this point in the history
  • Loading branch information
karlomikus committed Sep 16, 2024
1 parent 4080b2e commit 4b08cf6
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 22 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/CocktailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ public function share(Request $request, string $idOrSlug): JsonResponse
]);
}

#[OAT\Get(path: '/cocktails/{id}/similar', tags: ['Cocktails'], summary: 'Show similar cocktails', parameters: [
new BAO\Parameters\DatabaseIdParameter(),
])]
#[OAT\Response(response: 200, description: 'Successful response', content: [
new BAO\WrapItemsWithData(BAO\Schemas\Cocktail::class),
])]
#[BAO\NotAuthorizedResponse]
#[BAO\NotFoundResponse]
public function similar(CocktailRepository $cocktailRepo, Request $request, string $idOrSlug): JsonResource
{
$cocktail = Cocktail::where('id', $idOrSlug)->orWhere('slug', $idOrSlug)->with('ingredients.ingredient')->firstOrFail();
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public function index(Request $request): JsonResource
#[OAT\Post(path: '/exports', tags: ['Exports'], summary: 'Create a new export', requestBody: new OAT\RequestBody(
required: true,
content: [
new OAT\JsonContent(type: 'object', properties: [
new OAT\Property(property: 'type', ref: ExportTypeEnum::class),
new OAT\Property(property: 'bar_id', type: 'integer', example: 1),
]),
new OAT\JsonContent(ref: BAO\Schemas\ExportRequest::class),
]
))]
#[OAT\Response(response: 200, description: 'Successful response', content: [
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/ShelfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ShelfController extends Controller
public function ingredients(Request $request, int $id): JsonResource
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public function ingredients(Request $request, int $id): JsonResource
public function cocktails(CocktailRepository $cocktailRepo, Request $request, int $id): JsonResource
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public function cocktails(CocktailRepository $cocktailRepo, Request $request, in
public function favorites(Request $request, int $id): JsonResource
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public function favorites(Request $request, int $id): JsonResource
public function batchStore(Request $request, int $id): Response
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down Expand Up @@ -174,7 +174,7 @@ public function batchStore(Request $request, int $id): Response
public function batchDelete(Request $request, int $id): Response
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down Expand Up @@ -208,7 +208,7 @@ public function batchDelete(Request $request, int $id): Response
public function recommend(Request $request, IngredientRepository $ingredientRepo, int $id): \Illuminate\Http\JsonResponse
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/ShoppingListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ShoppingListController extends Controller
public function index(Request $request, int $id): JsonResource
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand All @@ -56,7 +56,7 @@ public function index(Request $request, int $id): JsonResource
public function batchStore(IngredientsBatchRequest $request, int $id): Response
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public function batchStore(IngredientsBatchRequest $request, int $id): Response
public function batchDelete(IngredientsBatchRequest $request, int $id): Response
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public function batchDelete(IngredientsBatchRequest $request, int $id): Response
public function share(Request $request, int $id): JsonResponse
{
$user = User::findOrFail($id);
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
if ($request->user()->id !== $user->id && $request->user()->cannot('show', $user)) {
abort(403);
}

Expand Down
18 changes: 18 additions & 0 deletions app/Http/Controllers/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Kami\Cocktail\Http\Controllers;

use Throwable;
use OpenApi\Attributes as OAT;
use Kami\Cocktail\OpenAPI as BAO;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Mail;
Expand All @@ -13,6 +15,11 @@

class SubscriptionController extends Controller
{
#[OAT\Get(path: '/billing/subscriptions', tags: ['Billing'], summary: 'Get subscription status')]
#[OAT\Response(response: 200, description: 'Successful response', content: [
new BAO\WrapObjectWithData(BAO\Schemas\UserSubscription::class),
])]
#[BAO\NotFoundResponse]
public function subscription(Request $request): JsonResponse
{
if (!config('bar-assistant.enable_billing')) {
Expand Down Expand Up @@ -41,6 +48,17 @@ public function subscription(Request $request): JsonResponse
]);
}

#[OAT\Post(path: '/billing/subscriptions', tags: ['Billing'], summary: 'Update subscription', requestBody: new OAT\RequestBody(
required: true,
content: [
new OAT\JsonContent(type: 'object', required: ['type'], properties: [
new OAT\Property(property: 'type', type: 'string'),
]),
]
))]
#[OAT\Response(response: 204, description: 'Successful response')]
#[BAO\NotAuthorizedResponse]
#[BAO\NotFoundResponse]
public function updateSubscription(Request $request): JsonResponse
{
if (!config('bar-assistant.enable_billing')) {
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Resources/ExploreCocktailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public function toArray($request)
'note' => $cocktailIngredient->note,
'substitutes' => $cocktailIngredient->substitutes->map(function ($substitute) {
return [
'name' => $substitute->ingredient->name,
'ingredient' => [
'name' => $substitute->ingredient->name,
],
'amount' => $substitute->amount,
'amount_max' => $substitute->amount_max,
'units' => $substitute->units,
Expand Down
22 changes: 22 additions & 0 deletions app/OpenAPI/Schemas/ExportRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Kami\Cocktail\OpenAPI\Schemas;

use OpenApi\Attributes as OAT;
use Kami\Cocktail\External\ExportTypeEnum;
use Kami\Cocktail\External\ForceUnitConvertEnum;

#[OAT\Schema()]
class ExportRequest
{
#[OAT\Property()]
public ExportTypeEnum $type;

#[OAT\Property()]
public ForceUnitConvertEnum $units;

#[OAT\Property(property: 'bar_id')]
public int $barId;
}
56 changes: 56 additions & 0 deletions app/OpenAPI/Schemas/Subscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Kami\Cocktail\OpenAPI\Schemas;

use OpenApi\Attributes as OAT;

#[OAT\Schema()]
class Subscription
{
#[OAT\Property()]
public string $type;

#[OAT\Property()]
public string $paddle_id;

#[OAT\Property()]
public string $status;

#[OAT\Property(format: 'date-time')]
public string $created_at;

#[OAT\Property(format: 'date-time')]
public ?string $updated_at;

#[OAT\Property(format: 'date-time')]
public ?string $paused_at;

#[OAT\Property(format: 'date-time')]
public ?string $ends_at;

#[OAT\Property()]
public bool $past_due;

#[OAT\Property()]
public bool $is_recurring;

/** @var array<mixed> */
#[OAT\Property(items: new OAT\Items(type: 'object', properties: [
new OAT\Property(property: 'currency', type: 'string'),
new OAT\Property(property: 'amount', type: 'string'),
new OAT\Property(property: 'date', type: 'string', format: 'date-time'),
]))]
public array $next_billed_at;

#[OAT\Property(format: 'uri')]
public string $update_payment_url;

#[OAT\Property(format: 'uri')]
public string $cancel_url;

/** @var Transaction[] */
#[OAT\Property()]
public array $transactions;
}
38 changes: 38 additions & 0 deletions app/OpenAPI/Schemas/Transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Kami\Cocktail\OpenAPI\Schemas;

use OpenApi\Attributes as OAT;

#[OAT\Schema()]
class Transaction
{
#[OAT\Property()]
public string $total;

#[OAT\Property()]
public string $tax;

#[OAT\Property()]
public string $currency;

#[OAT\Property()]
public string $status;

#[OAT\Property()]
public string $invoice_number;

#[OAT\Property(format: 'uri')]
public string $url;

#[OAT\Property(format: 'date-time')]
public string $billed_at;

#[OAT\Property(format: 'date-time')]
public string $created_at;

#[OAT\Property(format: 'date-time')]
public ?string $updated_at;
}
25 changes: 25 additions & 0 deletions app/OpenAPI/Schemas/UserSubscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Kami\Cocktail\OpenAPI\Schemas;

use OpenApi\Attributes as OAT;

#[OAT\Schema(required: ['prices', 'customer', 'subscription'])]
class UserSubscription
{
#[OAT\Property()]
public string $prices;

/** @var array<mixed> */
#[OAT\Property(items: new OAT\Items(type: 'object', properties: [
new OAT\Property(property: 'paddle_id', type: 'string'),
new OAT\Property(property: 'paddle_email', type: 'string'),
new OAT\Property(property: 'paddle_name', type: 'string'),
], required: ['paddle_id', 'paddle_email', 'paddle_name']))]
public array $customer;

#[OAT\Property()]
public ?Subscription $subscription;
}
Loading

0 comments on commit 4b08cf6

Please sign in to comment.