Skip to content

Commit

Permalink
Merge pull request #25 from karlomikus/develop
Browse files Browse the repository at this point in the history
Stable release
  • Loading branch information
karlomikus committed Nov 28, 2022
2 parents 0adc562 + 7f5c7ef commit 30909e5
Show file tree
Hide file tree
Showing 68 changed files with 281 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: php artisan key:generate

- name: Check coding style
run: vendor/bin/ecs check
run: vendor/bin/ecs --clear-cache

- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit tests/
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.0.0
- Cover all endpoints with tests
- Add coding style

# v0.5.3
- Update OpenApi spec and endpoints
- Delete responses now return 204
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/BarExportCocktails.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Kami\Cocktail\Console\Commands;

use Illuminate\Console\Command;
use Kami\Cocktail\Models\Cocktail;
use Symfony\Component\Yaml\Yaml;
use Kami\Cocktail\Models\Cocktail;

class BarExportCocktails extends Command
{
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/BarSearchRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Kami\Cocktail\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Kami\Cocktail\SearchActions;
use Illuminate\Support\Facades\Artisan;

class BarSearchRefresh extends Command
{
Expand Down
24 changes: 12 additions & 12 deletions app/Console/Commands/OpenBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

namespace Kami\Cocktail\Console\Commands;

use Throwable;
use Illuminate\Support\Str;
use Kami\Cocktail\Models\Tag;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Artisan;
use Kami\Cocktail\Models\Image;
use Kami\Cocktail\SearchActions;
use Symfony\Component\Yaml\Yaml;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Kami\Cocktail\Models\Cocktail;
use Kami\Cocktail\Models\CocktailIngredient;
use Kami\Cocktail\Models\CocktailIngredientSubstitute;
use Kami\Cocktail\Models\Image;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Hash;
use Kami\Cocktail\Models\Ingredient;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Artisan;
use Kami\Cocktail\Models\CocktailIngredient;
use Kami\Cocktail\Models\IngredientCategory;
use Kami\Cocktail\Models\Tag;
use Kami\Cocktail\SearchActions;
use Symfony\Component\Yaml\Yaml;
use Throwable;
use Kami\Cocktail\Models\CocktailIngredientSubstitute;

class OpenBar extends Command
{
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/ScrapIBACocktails.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Kami\Cocktail\Console\Commands;

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

class ScrapIBACocktails extends Command
{
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/TestScrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Kami\Cocktail\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpClient\CachingHttpClient;
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
{
Expand Down
6 changes: 3 additions & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Kami\Cocktail\Exceptions;

use Illuminate\Database\Eloquent\ModelNotFoundException;
use Throwable;
use Illuminate\Database\RecordsNotFoundException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;

class Handler extends ExceptionHandler
{
Expand Down
13 changes: 7 additions & 6 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Http\Request;
use Kami\Cocktail\Models\User;
use Kami\Cocktail\SearchActions;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Kami\Cocktail\Http\Requests\RegisterRequest;
use Kami\Cocktail\Http\Resources\UserResource;
use Kami\Cocktail\Models\User;
use Kami\Cocktail\SearchActions;
use Kami\Cocktail\Http\Requests\RegisterRequest;

class AuthController extends Controller
{
public function authenticate(Request $request)
public function authenticate(Request $request): JsonResponse
{
$credentials = $request->validate([
'email' => ['required', 'email'],
Expand All @@ -30,14 +31,14 @@ public function authenticate(Request $request)
abort(404, 'User not found. Check your username and password and try again.');
}

public function logout(Request $request)
public function logout(Request $request): JsonResponse
{
$request->user()->tokens()->delete();

return response()->json(['data' => ['success' => true]]);
}

public function register(RegisterRequest $req)
public function register(RegisterRequest $req): JsonResponse
{
if (config('bar-assistant.allow_registration') == false) {
abort(404, 'Registrations are closed.');
Expand Down
26 changes: 14 additions & 12 deletions app/Http/Controllers/CocktailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Throwable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Kami\Cocktail\Models\Cocktail;
use Kami\Cocktail\Services\CocktailService;
use Illuminate\Http\Resources\Json\JsonResource;
use Kami\Cocktail\Http\Requests\CocktailRequest;
use Kami\Cocktail\Http\Resources\CocktailResource;
use Kami\Cocktail\Http\Resources\SuccessActionResource;
use Kami\Cocktail\Models\Cocktail;
use Kami\Cocktail\Services\CocktailService;
use Throwable;

class CocktailController extends Controller
{
Expand All @@ -22,7 +24,7 @@ class CocktailController extends Controller
* - user_id -> Filter by user id
* - favorites -> Filter by user favorites
*/
public function index(Request $request)
public function index(Request $request): JsonResource
{
$cocktails = Cocktail::with('ingredients.ingredient', 'images', 'tags');

Expand All @@ -42,7 +44,7 @@ public function index(Request $request)
/**
* Return a single random cocktail
*/
public function random()
public function random(): JsonResource
{
$cocktail = Cocktail::inRandomOrder()
->firstOrFail()
Expand All @@ -54,7 +56,7 @@ public function random()
/**
* Show a single cocktail by it's id or URL slug
*/
public function show(int|string $idOrSlug)
public function show(int|string $idOrSlug): JsonResource
{
$cocktail = Cocktail::where('id', $idOrSlug)
->orWhere('slug', $idOrSlug)
Expand Down Expand Up @@ -97,7 +99,7 @@ public function store(CocktailService $cocktailService, CocktailRequest $request
/**
* Update a single cocktail by id
*/
public function update(CocktailService $cocktailService, CocktailRequest $request, int $id)
public function update(CocktailService $cocktailService, CocktailRequest $request, int $id): JsonResource
{
try {
$cocktail = $cocktailService->updateCocktail(
Expand Down Expand Up @@ -125,7 +127,7 @@ public function update(CocktailService $cocktailService, CocktailRequest $reques
/**
* Delete a single cocktail by id
*/
public function delete(int $id)
public function delete(int $id): Response
{
Cocktail::findOrFail($id)->delete();

Expand All @@ -136,7 +138,7 @@ public function delete(int $id)
* Show all cocktails that current user can make with
* the ingredients he added to his shelf
*/
public function userShelf(CocktailService $cocktailService, Request $request)
public function userShelf(CocktailService $cocktailService, Request $request): JsonResource
{
$cocktails = $cocktailService->getCocktailsByUserIngredients($request->user()->id)
->load('ingredients.ingredient', 'images', 'tags');
Expand All @@ -147,7 +149,7 @@ public function userShelf(CocktailService $cocktailService, Request $request)
/**
* Favorite a cocktail by id
*/
public function toggleFavorite(CocktailService $cocktailService, Request $request, int $id)
public function toggleFavorite(CocktailService $cocktailService, Request $request, int $id): JsonResource
{
$isFavorite = $cocktailService->toggleFavorite($request->user(), $id);

Expand All @@ -157,7 +159,7 @@ public function toggleFavorite(CocktailService $cocktailService, Request $reques
/**
* Show all cocktails that current user added to his favorites
*/
public function userFavorites(Request $request)
public function userFavorites(Request $request): JsonResource
{
$cocktails = $request->user()->favorites->pluck('cocktail');

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/GlassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Response;
use Kami\Cocktail\Models\Glass;
use Illuminate\Http\JsonResponse;
use Kami\Cocktail\Http\Requests\GlassRequest;
use Kami\Cocktail\Http\Resources\GlassResource;
use Kami\Cocktail\Models\Glass;
use Illuminate\Http\Resources\Json\JsonResource;

class GlassController extends Controller
{
Expand Down
15 changes: 8 additions & 7 deletions app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,37 @@
namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Http\Request;
use Kami\Cocktail\Http\Requests\ImageRequest;
use Kami\Cocktail\Http\Resources\ImageResource;
use Kami\Cocktail\Http\Resources\SuccessActionResource;
use Illuminate\Http\Response;
use Kami\Cocktail\Models\Image;
use Kami\Cocktail\Services\ImageService;
use Kami\Cocktail\Http\Requests\ImageRequest;
use Kami\Cocktail\Http\Resources\ImageResource;
use Illuminate\Http\Resources\Json\JsonResource;

class ImageController extends Controller
{
public function show(int $id)
public function show(int $id): JsonResource
{
$image = Image::findOrFail($id);

return new ImageResource($image);
}

public function store(ImageService $imageservice, ImageRequest $request)
public function store(ImageService $imageservice, ImageRequest $request): JsonResource
{
$images = $imageservice->uploadAndSaveImages($request->images);

return ImageResource::collection($images);
}

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

return new ImageResource($image);
}

public function delete(int $id)
public function delete(int $id): Response
{
Image::findOrFail($id)->delete();

Expand Down
16 changes: 9 additions & 7 deletions app/Http/Controllers/IngredientCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@

namespace Kami\Cocktail\Http\Controllers;

use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Kami\Cocktail\Models\IngredientCategory;
use Illuminate\Http\Resources\Json\JsonResource;
use Kami\Cocktail\Http\Requests\IngredientCategoryRequest;
use Kami\Cocktail\Http\Resources\IngredientCategoryResource;
use Kami\Cocktail\Http\Resources\SuccessActionResource;
use Kami\Cocktail\Models\IngredientCategory;

class IngredientCategoryController extends Controller
{
public function index()
public function index(): JsonResource
{
$categories = IngredientCategory::all();

return IngredientCategoryResource::collection($categories);
}

public function show(int $id)
public function show(int $id): JsonResource
{
$category = IngredientCategory::findOrFail($id);

return new IngredientCategoryResource($category);
}

public function store(IngredientCategoryRequest $request)
public function store(IngredientCategoryRequest $request): JsonResponse
{
$category = new IngredientCategory();
$category->name = $request->post('name');
Expand All @@ -38,7 +40,7 @@ public function store(IngredientCategoryRequest $request)
->header('Location', route('ingredient-categories.show', $category->id));
}

public function update(IngredientCategoryRequest $request, int $id)
public function update(IngredientCategoryRequest $request, int $id): JsonResource
{
$category = IngredientCategory::findOrFail($id);
$category->name = $request->post('name');
Expand All @@ -48,7 +50,7 @@ public function update(IngredientCategoryRequest $request, int $id)
return new IngredientCategoryResource($category);
}

public function delete(int $id)
public function delete(int $id): Response
{
IngredientCategory::findOrFail($id)->delete();

Expand Down
Loading

0 comments on commit 30909e5

Please sign in to comment.