first commit
This commit is contained in:
15
.editorconfig
Normal file
15
.editorconfig
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
21
.env.example
Normal file
21
.env.example
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
APP_NAME=Coupon
|
||||||
|
APP_ENV=local
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_URL=http://localhost
|
||||||
|
APP_TIMEZONE=UTC
|
||||||
|
|
||||||
|
LOG_CHANNEL=stack
|
||||||
|
LOG_SLACK_WEBHOOK_URL=
|
||||||
|
|
||||||
|
DB_CONNECTION=mysql
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=homestead
|
||||||
|
DB_USERNAME=homestead
|
||||||
|
DB_PASSWORD=secret
|
||||||
|
|
||||||
|
CACHE_DRIVER=file
|
||||||
|
QUEUE_CONNECTION=database
|
||||||
|
|
||||||
|
JWT_SECRET=
|
||||||
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/vendor
|
||||||
|
/.idea
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
.env
|
||||||
|
.phpunit.result.cache
|
||||||
6
.styleci.yml
Normal file
6
.styleci.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
php:
|
||||||
|
preset: laravel
|
||||||
|
disabled:
|
||||||
|
- unused_use
|
||||||
|
js: true
|
||||||
|
css: true
|
||||||
24
README.md
Normal file
24
README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Lumen PHP Framework
|
||||||
|
|
||||||
|
[](https://travis-ci.org/laravel/lumen-framework)
|
||||||
|
[](https://packagist.org/packages/laravel/lumen-framework)
|
||||||
|
[](https://packagist.org/packages/laravel/lumen-framework)
|
||||||
|
[](https://packagist.org/packages/laravel/lumen-framework)
|
||||||
|
|
||||||
|
Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching.
|
||||||
|
|
||||||
|
## Official Documentation
|
||||||
|
|
||||||
|
Documentation for the framework can be found on the [Lumen website](https://lumen.laravel.com/docs).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Thank you for considering contributing to Lumen! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
|
||||||
|
|
||||||
|
## Security Vulnerabilities
|
||||||
|
|
||||||
|
If you discover a security vulnerability within Lumen, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The Lumen framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
||||||
0
app/Console/Commands/.gitkeep
Normal file
0
app/Console/Commands/.gitkeep
Normal file
29
app/Console/Kernel.php
Normal file
29
app/Console/Kernel.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console;
|
||||||
|
|
||||||
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
|
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
|
class Kernel extends ConsoleKernel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The Artisan commands provided by your application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $commands = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the application's command schedule.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function schedule(Schedule $schedule)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Events/CouponWasCollectedEvent.php
Normal file
43
app/Events/CouponWasCollectedEvent.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class CouponWasCollectedEvent extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The coupon referrer.
|
||||||
|
*
|
||||||
|
* @var \App\Models\Coupon
|
||||||
|
*/
|
||||||
|
public $coupon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param Coupon $coupon
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Coupon $coupon)
|
||||||
|
{
|
||||||
|
$this->coupon = $coupon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function broadcastOn()
|
||||||
|
{
|
||||||
|
return ['brand-'.$this->coupon->brand_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function broadcastWith()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'coupon' => $this->coupon,
|
||||||
|
'user' => $this->coupon->user
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Events/CouponsGenerationEvent.php
Normal file
31
app/Events/CouponsGenerationEvent.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use App\Models\CouponOrder;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class CouponsGenerationEvent extends Event implements ShouldQueue
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The coupon order referrer.
|
||||||
|
*
|
||||||
|
* @var \App\Models\CouponOrder
|
||||||
|
*/
|
||||||
|
public $couponOrder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param CouponOrder $couponOrder
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(CouponOrder $couponOrder)
|
||||||
|
{
|
||||||
|
$this->couponOrder = $couponOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
app/Events/Event.php
Normal file
10
app/Events/Event.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
abstract class Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
}
|
||||||
54
app/Exceptions/Handler.php
Normal file
54
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Access\AuthorizationException;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class Handler extends ExceptionHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A list of the exception types that should not be reported.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $dontReport = [
|
||||||
|
AuthorizationException::class,
|
||||||
|
HttpException::class,
|
||||||
|
ModelNotFoundException::class,
|
||||||
|
ValidationException::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report or log an exception.
|
||||||
|
*
|
||||||
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||||
|
*
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function report(Throwable $exception)
|
||||||
|
{
|
||||||
|
parent::report($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render an exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function render($request, Throwable $exception)
|
||||||
|
{
|
||||||
|
return parent::render($request, $exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Http/Controllers/Controller.php
Normal file
19
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||||
|
|
||||||
|
class Controller extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @OA\Info(
|
||||||
|
* title="Example API",
|
||||||
|
* version="1.0",
|
||||||
|
* @OA\Contact(
|
||||||
|
* email="support@example.com",
|
||||||
|
* name="Support Team"
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
}
|
||||||
169
app/Http/Controllers/CouponController.php
Normal file
169
app/Http/Controllers/CouponController.php
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Events\CouponsGenerationEvent;
|
||||||
|
use App\Events\CouponWasCollectedEvent;
|
||||||
|
use App\Http\Resources\CouponResource;
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use App\Models\CouponOrder;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CouponController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a coupon code for the user, based on the selected brand, if available.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/get-coupon",
|
||||||
|
* operationId="/get-coupon",
|
||||||
|
* tags={"getCoupon"},
|
||||||
|
* security={ {"bearer": {} }},
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="brand_id",
|
||||||
|
* in="query",
|
||||||
|
* description="ID of the brand for which the coupon is requested.",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(type="integer")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="200",
|
||||||
|
* description="Returns the coupon code",
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="401",
|
||||||
|
* description="Error: Not authenticated.",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* @OA\Property(property="message", type="string", example="Token expired.")
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="403",
|
||||||
|
* description="Error: Not authorized.",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* @OA\Property(property="message", type="string", example="Not authorized.")
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function getCoupon(Request $request){
|
||||||
|
if($request->auth['role'] != 'customer'){
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'Not authorized.'
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->validate($request, [
|
||||||
|
'brand_id' => 'required|numeric'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = User::find(['id', $request->auth['id']])->first();
|
||||||
|
|
||||||
|
if(empty($user)){
|
||||||
|
$user = User::create([
|
||||||
|
'id' => $request->auth['id']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$coupon = Coupon::where(['brand_id' => $data['brand_id'], 'user_id' => null])->first();
|
||||||
|
|
||||||
|
if(empty($coupon)){
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'No coupon found.'
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$coupon->user_id = $request->auth['id'];
|
||||||
|
$coupon->collected_at = date("Y-m-d H:i:s");;
|
||||||
|
$coupon->save();
|
||||||
|
|
||||||
|
event(new CouponWasCollectedEvent($coupon));
|
||||||
|
|
||||||
|
return new CouponResource($coupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates coupon codes for a brand.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/generate-coupons",
|
||||||
|
* operationId="/generate-coupons",
|
||||||
|
* tags={"generateCoupons"},
|
||||||
|
* security={ {"bearer": {} }},
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="quantity",
|
||||||
|
* in="query",
|
||||||
|
* description="Quantity of coupons to be generated.",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(type="integer")
|
||||||
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="prefix",
|
||||||
|
* in="query",
|
||||||
|
* description="Prefix to be used in the coupon codes.",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(type="string")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="200",
|
||||||
|
* description="Success.",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* @OA\Property(property="message", type="string", example="Coupon code(s) generation job sent.")
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="401",
|
||||||
|
* description="Error: Not authenticated.",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* @OA\Property(property="message", type="string", example="Token expired.")
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="403",
|
||||||
|
* description="Error: Not authorized.",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* @OA\Property(property="message", type="string", example="Not authorized.")
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function generateCoupons(Request $request){
|
||||||
|
if($request->auth['role'] != 'brand'){
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'Not authorized.'
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->validate($request, [
|
||||||
|
'quantity' => 'required|numeric',
|
||||||
|
'prefix' => 'sometimes|string'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data['brand_id'] = $request->auth['id'];
|
||||||
|
|
||||||
|
$couponOrder = CouponOrder::create($data);
|
||||||
|
|
||||||
|
event(new CouponsGenerationEvent($couponOrder));
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Coupon code(s) generation job sent.'
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
44
app/Http/Middleware/Authenticate.php
Normal file
44
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||||
|
|
||||||
|
class Authenticate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The authentication guard factory instance.
|
||||||
|
*
|
||||||
|
* @var \Illuminate\Contracts\Auth\Factory
|
||||||
|
*/
|
||||||
|
protected $auth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new middleware instance.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Auth $auth)
|
||||||
|
{
|
||||||
|
$this->auth = $auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @param string|null $guard
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next, $guard = null)
|
||||||
|
{
|
||||||
|
if ($this->auth->guard($guard)->guest()) {
|
||||||
|
return response('Unauthorized.', 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Middleware/JwtMiddleware.php
Normal file
38
app/Http/Middleware/JwtMiddleware.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Exception;
|
||||||
|
use Firebase\JWT\JWT;
|
||||||
|
use Firebase\JWT\ExpiredException;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class JwtMiddleware
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
$token = $request->header('Authorization');
|
||||||
|
|
||||||
|
if(!$token) {
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'Token missing.'
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$auth = JWT::decode(explode(" ", $token)[1], env('JWT_SECRET'), ['HS256']);
|
||||||
|
$request->auth = (array)$auth;
|
||||||
|
} catch(ExpiredException $e) {
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'Token expired.'
|
||||||
|
], 400);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'Error decoding token.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Http/Resources/CouponResource.php
Normal file
22
app/Http/Resources/CouponResource.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class CouponResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
[
|
||||||
|
'code' => $this->code
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/Jobs/ExampleJob.php
Normal file
26
app/Jobs/ExampleJob.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
class ExampleJob extends Job
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Jobs/Job.php
Normal file
24
app/Jobs/Job.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
abstract class Job implements ShouldQueue
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Queueable Jobs
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This job base class provides a central location to place any logic that
|
||||||
|
| is shared across all of your jobs. The trait included with the class
|
||||||
|
| provides access to the "queueOn" and "delay" queue helper methods.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
}
|
||||||
31
app/Listeners/BrandNotificationListener.php
Normal file
31
app/Listeners/BrandNotificationListener.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\CouponWasCollectedEvent;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
|
class BrandNotificationListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param \App\Events\CouponWasCollectedEvent $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(CouponWasCollectedEvent $event)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Listeners/CouponsGenerationListener.php
Normal file
38
app/Listeners/CouponsGenerationListener.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Events\CouponsGenerationEvent;
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
|
class CouponsGenerationListener implements ShouldQueue
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param \App\Events\CouponsGenerationEvent $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(CouponsGenerationEvent $event)
|
||||||
|
{
|
||||||
|
for($i = 0; $i < $event->couponOrder->quantity; $i++){
|
||||||
|
Coupon::create([
|
||||||
|
'brand_id' => $event->couponOrder->brand_id,
|
||||||
|
'coupon_order_id' => $event->couponOrder->id,
|
||||||
|
'code' => uniqid($event->couponOrder->prefix, true)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
app/Models/Coupon.php
Normal file
53
app/Models/Coupon.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Coupon extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'brand_id',
|
||||||
|
'coupon_order_id',
|
||||||
|
'user_id',
|
||||||
|
'code',
|
||||||
|
'collected_at'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes excluded from the model's JSON form.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $hidden = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the related CouponOrder object.
|
||||||
|
*
|
||||||
|
* @var CouponOrder
|
||||||
|
*/
|
||||||
|
public function couponOrder()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(CouponOrder::class, 'coupon_order_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the related User object.
|
||||||
|
*
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
36
app/Models/CouponOrder.php
Normal file
36
app/Models/CouponOrder.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class CouponOrder extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'brand_id',
|
||||||
|
'quantity',
|
||||||
|
'prefix'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes excluded from the model's JSON form.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $hidden = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
public function coupons()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Coupon::class, 'coupon_order_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Models/User.php
Normal file
38
app/Models/User.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Authenticatable;
|
||||||
|
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
||||||
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Laravel\Lumen\Auth\Authorizable;
|
||||||
|
|
||||||
|
class User extends Model implements AuthenticatableContract, AuthorizableContract
|
||||||
|
{
|
||||||
|
use Authenticatable, Authorizable, HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'id', 'profile',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes excluded from the model's JSON form.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $hidden = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
public function coupons()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Coupon::class, 'user_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Providers/AppServiceProvider.php
Normal file
18
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class AppServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register any application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Providers/AuthServiceProvider.php
Normal file
39
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class AuthServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register any application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boot the authentication services for the application.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
// Here you may define how you wish users to be authenticated for your Lumen
|
||||||
|
// application. The callback which receives the incoming request instance
|
||||||
|
// should return either a User instance or null. You're free to obtain
|
||||||
|
// the User instance via an API token or any other method necessary.
|
||||||
|
|
||||||
|
$this->app['auth']->viaRequest('api', function ($request) {
|
||||||
|
if ($request->input('api_token')) {
|
||||||
|
return User::where('api_token', $request->input('api_token'))->first();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Providers/EventServiceProvider.php
Normal file
22
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
|
class EventServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The event listener mappings for the application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $listen = [
|
||||||
|
\App\Events\CouponsGenerationEvent::class => [
|
||||||
|
\App\Listeners\CouponsGenerationListener::class,
|
||||||
|
],
|
||||||
|
\App\Events\CouponWasCollectedEvent::class => [
|
||||||
|
\App\Listeners\BrandNotificationListener::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
35
artisan
Executable file
35
artisan
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\ArgvInput;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Create The Application
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| First we need to get an application instance. This creates an instance
|
||||||
|
| of the application / container and bootstraps the application so it
|
||||||
|
| is ready to receive HTTP / Console requests from the environment.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app = require __DIR__.'/bootstrap/app.php';
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Run The Artisan Application
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When we run the console application, the current CLI command will be
|
||||||
|
| executed in this console and the response sent back to a terminal
|
||||||
|
| or another output device for the developers. Here goes nothing!
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$kernel = $app->make(
|
||||||
|
'Illuminate\Contracts\Console\Kernel'
|
||||||
|
);
|
||||||
|
|
||||||
|
exit($kernel->handle(new ArgvInput, new ConsoleOutput));
|
||||||
123
bootstrap/app.php
Normal file
123
bootstrap/app.php
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__.'/../vendor/autoload.php';
|
||||||
|
|
||||||
|
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
|
||||||
|
dirname(__DIR__)
|
||||||
|
))->bootstrap();
|
||||||
|
|
||||||
|
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Create The Application
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here we will load the environment and create the application instance
|
||||||
|
| that serves as the central piece of this framework. We'll use this
|
||||||
|
| application as an "IoC" container and router for this framework.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app = new Laravel\Lumen\Application(
|
||||||
|
dirname(__DIR__)
|
||||||
|
);
|
||||||
|
|
||||||
|
$app->withFacades();
|
||||||
|
|
||||||
|
$app->withEloquent();
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register Container Bindings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Now we will register a few bindings in the service container. We will
|
||||||
|
| register the exception handler and the console kernel. You may add
|
||||||
|
| your own bindings here if you like or you can make another file.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app->singleton(
|
||||||
|
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
||||||
|
App\Exceptions\Handler::class
|
||||||
|
);
|
||||||
|
|
||||||
|
$app->singleton(
|
||||||
|
Illuminate\Contracts\Console\Kernel::class,
|
||||||
|
App\Console\Kernel::class
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register Config Files
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Now we will register the "app" configuration file. If the file exists in
|
||||||
|
| your configuration directory it will be loaded; otherwise, we'll load
|
||||||
|
| the default version. You may register other files below as needed.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app->configure('app');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register Middleware
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Next, we will register the middleware with the application. These can
|
||||||
|
| be global middleware that run before and after each request into a
|
||||||
|
| route or middleware that'll be assigned to some specific routes.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// $app->middleware([
|
||||||
|
// App\Http\Middleware\ExampleMiddleware::class
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
$app->routeMiddleware([
|
||||||
|
'jwt' => App\Http\Middleware\JwtMiddleware::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register Service Providers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here we will register all of the application's service providers which
|
||||||
|
| are used to bind services into the container. Service providers are
|
||||||
|
| totally optional, so you are not required to uncomment this line.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// $app->register(App\Providers\AppServiceProvider::class);
|
||||||
|
// $app->register(App\Providers\AuthServiceProvider::class);
|
||||||
|
$app->register(App\Providers\EventServiceProvider::class);
|
||||||
|
$app->register(\SwaggerLume\ServiceProvider::class);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Load The Application Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Next we will include the routes file so that they can all be added to
|
||||||
|
| the application. This will provide all of the URLs the application
|
||||||
|
| can respond to, as well as the controllers that may handle them.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app->router->group([
|
||||||
|
'namespace' => 'App\Http\Controllers',
|
||||||
|
], function ($router) {
|
||||||
|
require __DIR__.'/../routes/web.php';
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Load Swagger config
|
||||||
|
|--------------------------------------------------------------------------|
|
||||||
|
*/
|
||||||
|
$app->configure('swagger-lume');
|
||||||
|
|
||||||
|
return $app;
|
||||||
42
composer.json
Normal file
42
composer.json
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "laravel/lumen",
|
||||||
|
"description": "The Laravel Lumen Framework.",
|
||||||
|
"keywords": ["framework", "laravel", "lumen"],
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "project",
|
||||||
|
"require": {
|
||||||
|
"php": "^7.3|^8.0",
|
||||||
|
"darkaonline/swagger-lume": "^8.0",
|
||||||
|
"firebase/php-jwt": "^5.4",
|
||||||
|
"laravel/lumen-framework": "^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"fakerphp/faker": "^1.9.1",
|
||||||
|
"mockery/mockery": "^1.3.1",
|
||||||
|
"phpunit/phpunit": "^9.3"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\": "app/",
|
||||||
|
"Database\\Factories\\": "database/factories/",
|
||||||
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"classmap": [
|
||||||
|
"tests/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"preferred-install": "dist",
|
||||||
|
"sort-packages": true,
|
||||||
|
"optimize-autoloader": true
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true,
|
||||||
|
"scripts": {
|
||||||
|
"post-root-package-install": [
|
||||||
|
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
7120
composer.lock
generated
Normal file
7120
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
204
config/swagger-lume.php
Normal file
204
config/swagger-lume.php
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'api' => [
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Edit to set the api's title
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'title' => 'Swagger Lume API',
|
||||||
|
],
|
||||||
|
|
||||||
|
'routes' => [
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Route for accessing api documentation interface
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'api' => '/api/documentation',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Route for accessing parsed swagger annotations.
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'docs' => '/docs',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Route for Oauth2 authentication callback.
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'oauth2_callback' => '/api/oauth2-callback',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Route for serving assets
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'assets' => '/swagger-ui-assets',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Middleware allows to prevent unexpected access to API documentation
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'middleware' => [
|
||||||
|
'api' => [],
|
||||||
|
'asset' => [],
|
||||||
|
'docs' => [],
|
||||||
|
'oauth2_callback' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'paths' => [
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Absolute path to location where parsed swagger annotations will be stored
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'docs' => storage_path('api-docs'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| File name of the generated json documentation file
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'docs_json' => 'api-docs.json',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Absolute path to directory containing the swagger annotations are stored.
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'annotations' => base_path('app'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Absolute path to directories that you would like to exclude from swagger generation
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'excludes' => [],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Edit to set the swagger scan base path
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'base' => env('L5_SWAGGER_BASE_PATH', null),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Absolute path to directory where to export views
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'views' => base_path('resources/views/vendor/swagger-lume'),
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| API security definitions. Will be generated into documentation file.
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'security' => [
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Examples of Security definitions
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
'api_key_security_example' => [ // Unique name of security
|
||||||
|
'type' => 'apiKey', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
|
||||||
|
'description' => 'A short description for security scheme',
|
||||||
|
'name' => 'api_key', // The name of the header or query parameter to be used.
|
||||||
|
'in' => 'header', // The location of the API key. Valid values are "query" or "header".
|
||||||
|
],
|
||||||
|
'oauth2_security_example' => [ // Unique name of security
|
||||||
|
'type' => 'oauth2', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
|
||||||
|
'description' => 'A short description for oauth2 security scheme.',
|
||||||
|
'flow' => 'implicit', // The flow used by the OAuth2 security scheme. Valid values are "implicit", "password", "application" or "accessCode".
|
||||||
|
'authorizationUrl' => 'http://example.com/auth', // The authorization URL to be used for (implicit/accessCode)
|
||||||
|
//'tokenUrl' => 'http://example.com/auth' // The authorization URL to be used for (password/application/accessCode)
|
||||||
|
'scopes' => [
|
||||||
|
'read:projects' => 'read your projects',
|
||||||
|
'write:projects' => 'modify projects in your account',
|
||||||
|
]
|
||||||
|
],*/
|
||||||
|
|
||||||
|
/* Open API 3.0 support
|
||||||
|
'passport' => [ // Unique name of security
|
||||||
|
'type' => 'oauth2', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
|
||||||
|
'description' => 'Laravel passport oauth2 security.',
|
||||||
|
'in' => 'header',
|
||||||
|
'scheme' => 'https',
|
||||||
|
'flows' => [
|
||||||
|
"password" => [
|
||||||
|
"authorizationUrl" => config('app.url') . '/oauth/authorize',
|
||||||
|
"tokenUrl" => config('app.url') . '/oauth/token',
|
||||||
|
"refreshUrl" => config('app.url') . '/token/refresh',
|
||||||
|
"scopes" => []
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
*/
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Turn this off to remove swagger generation on production
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'generate_always' => env('SWAGGER_GENERATE_ALWAYS', false),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Edit to set the swagger version number
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'swagger_version' => env('SWAGGER_VERSION', '3.0'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Edit to trust the proxy's ip address - needed for AWS Load Balancer
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'proxy' => false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Configs plugin allows to fetch external configs instead of passing them to SwaggerUIBundle.
|
||||||
|
| See more at: https://github.com/swagger-api/swagger-ui#configs-plugin
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
'additional_config_url' => null,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically),
|
||||||
|
| 'method' (sort by HTTP method).
|
||||||
|
| Default is the order returned by the server unchanged.
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
'operations_sort' => env('L5_SWAGGER_OPERATIONS_SORT', null),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Uncomment to pass the validatorUrl parameter to SwaggerUi init on the JS
|
||||||
|
| side. A null value here disables validation.
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
'validator_url' => null,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Uncomment to add constants which can be used in anotations
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'constants' => [
|
||||||
|
// 'SWAGGER_LUME_CONST_HOST' => env('SWAGGER_LUME_CONST_HOST', 'http://my-default-host.com'),
|
||||||
|
],
|
||||||
|
];
|
||||||
29
database/factories/UserFactory.php
Normal file
29
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class UserFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = User::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'email' => $this->faker->unique()->safeEmail,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
0
database/migrations/.gitkeep
Normal file
0
database/migrations/.gitkeep
Normal file
35
database/migrations/2021_09_05_153436_create_users_table.php
Normal file
35
database/migrations/2021_09_05_153436_create_users_table.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateUsersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('users', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->json('profile')->nullable();
|
||||||
|
|
||||||
|
$table->index('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('users');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateCouponOrdersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('coupon_orders', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unsignedBigInteger('brand_id');
|
||||||
|
$table->integer('quantity');
|
||||||
|
$table->string('prefix')->nullable();
|
||||||
|
|
||||||
|
$table->index('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('coupon_orders');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateCouponsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('coupons', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unsignedBigInteger('brand_id');
|
||||||
|
$table->unsignedBigInteger('coupon_order_id');
|
||||||
|
$table->unsignedBigInteger('user_id')->nullable();
|
||||||
|
$table->string('code')->unique();
|
||||||
|
$table->timestamp('collected_at')->nullable();
|
||||||
|
|
||||||
|
$table->foreign('user_id')->references('id')->on('users');
|
||||||
|
|
||||||
|
$table->index('id');
|
||||||
|
$table->index('code');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('coupons');
|
||||||
|
}
|
||||||
|
}
|
||||||
36
database/migrations/2021_09_05_155444_create_jobs_table.php
Normal file
36
database/migrations/2021_09_05_155444_create_jobs_table.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateJobsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('jobs', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->string('queue')->index();
|
||||||
|
$table->longText('payload');
|
||||||
|
$table->unsignedTinyInteger('attempts');
|
||||||
|
$table->unsignedInteger('reserved_at')->nullable();
|
||||||
|
$table->unsignedInteger('available_at');
|
||||||
|
$table->unsignedInteger('created_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('jobs');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateFailedJobsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('uuid')->unique();
|
||||||
|
$table->text('connection');
|
||||||
|
$table->text('queue');
|
||||||
|
$table->longText('payload');
|
||||||
|
$table->longText('exception');
|
||||||
|
$table->timestamp('failed_at')->useCurrent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('failed_jobs');
|
||||||
|
}
|
||||||
|
}
|
||||||
18
database/seeders/DatabaseSeeder.php
Normal file
18
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class DatabaseSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
// $this->call('UsersTableSeeder');
|
||||||
|
}
|
||||||
|
}
|
||||||
17
phpunit.xml
Normal file
17
phpunit.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Application Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<php>
|
||||||
|
<env name="APP_ENV" value="testing"/>
|
||||||
|
<env name="CACHE_DRIVER" value="array"/>
|
||||||
|
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||||
|
</php>
|
||||||
|
</phpunit>
|
||||||
21
public/.htaccess
Normal file
21
public/.htaccess
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<IfModule mod_rewrite.c>
|
||||||
|
<IfModule mod_negotiation.c>
|
||||||
|
Options -MultiViews -Indexes
|
||||||
|
</IfModule>
|
||||||
|
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
|
# Handle Authorization Header
|
||||||
|
RewriteCond %{HTTP:Authorization} .
|
||||||
|
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
||||||
|
|
||||||
|
# Redirect Trailing Slashes If Not A Folder...
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{REQUEST_URI} (.+)/$
|
||||||
|
RewriteRule ^ %1 [L,R=301]
|
||||||
|
|
||||||
|
# Handle Front Controller...
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^ index.php [L]
|
||||||
|
</IfModule>
|
||||||
28
public/index.php
Normal file
28
public/index.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Create The Application
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| First we need to get an application instance. This creates an instance
|
||||||
|
| of the application / container and bootstraps the application so it
|
||||||
|
| is ready to receive HTTP / Console requests from the environment.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app = require __DIR__.'/../bootstrap/app.php';
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Run The Application
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Once we have the application, we can handle the incoming request
|
||||||
|
| through the kernel, and send the associated response back to
|
||||||
|
| the client's browser allowing them to enjoy the creative
|
||||||
|
| and wonderful application we have prepared for them.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app->run();
|
||||||
0
resources/views/.gitkeep
Normal file
0
resources/views/.gitkeep
Normal file
101
resources/views/vendor/swagger-lume/index.blade.php
vendored
Normal file
101
resources/views/vendor/swagger-lume/index.blade.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<!-- HTML for static distribution bundle build -->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{{config('swagger-lume.api.title')}}</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{{ swagger_lume_asset('swagger-ui.css') }}" >
|
||||||
|
<link rel="icon" type="image/png" href="{{ swagger_lume_asset('favicon-32x32.png') }}" sizes="32x32" />
|
||||||
|
<link rel="icon" type="image/png" href="{{ swagger_lume_asset('favicon-16x16.png') }}" sizes="16x16" />
|
||||||
|
<style>
|
||||||
|
html
|
||||||
|
{
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: -moz-scrollbars-vertical;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
*,
|
||||||
|
*:before,
|
||||||
|
*:after
|
||||||
|
{
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin:0;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||||
|
<defs>
|
||||||
|
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||||
|
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="locked">
|
||||||
|
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="close">
|
||||||
|
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||||
|
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||||
|
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||||
|
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
<symbol viewBox="0 0 24 24" id="expand">
|
||||||
|
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||||
|
</symbol>
|
||||||
|
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<div id="swagger-ui"></div>
|
||||||
|
|
||||||
|
<script src="{{ swagger_lume_asset('swagger-ui-bundle.js') }}"> </script>
|
||||||
|
<script src="{{ swagger_lume_asset('swagger-ui-standalone-preset.js') }}"> </script>
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
// Build a system
|
||||||
|
const ui = SwaggerUIBundle({
|
||||||
|
dom_id: '#swagger-ui',
|
||||||
|
|
||||||
|
url: "{!! $urlToDocs !!}",
|
||||||
|
operationsSorter: {!! isset($operationsSorter) ? '"' . $operationsSorter . '"' : 'null' !!},
|
||||||
|
configUrl: {!! isset($additionalConfigUrl) ? '"' . $additionalConfigUrl . '"' : 'null' !!},
|
||||||
|
validatorUrl: {!! isset($validatorUrl) ? '"' . $validatorUrl . '"' : 'null' !!},
|
||||||
|
oauth2RedirectUrl: "{{ route('swagger-lume.oauth2_callback') }}",
|
||||||
|
|
||||||
|
presets: [
|
||||||
|
SwaggerUIBundle.presets.apis,
|
||||||
|
SwaggerUIStandalonePreset
|
||||||
|
],
|
||||||
|
|
||||||
|
plugins: [
|
||||||
|
SwaggerUIBundle.plugins.DownloadUrl
|
||||||
|
],
|
||||||
|
|
||||||
|
layout: "StandaloneLayout"
|
||||||
|
})
|
||||||
|
|
||||||
|
window.ui = ui
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
28
routes/web.php
Normal file
28
routes/web.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/** @var \Laravel\Lumen\Routing\Router $router */
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here is where you can register all of the routes for an application.
|
||||||
|
| It is a breeze. Simply tell Lumen the URIs it should respond to
|
||||||
|
| and give it the Closure to call when that URI is requested.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
$router->group(['middleware' => 'jwt'], function() use ($router) {
|
||||||
|
/*
|
||||||
|
| Route for a brand to generate a coupon codes
|
||||||
|
*/
|
||||||
|
$router->post('/generate-coupons', ['uses' => 'CouponController@generateCoupons']);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Route for the user to retrieve a coupon code
|
||||||
|
*/
|
||||||
|
$router->get('/get-coupon', ['uses' => 'CouponController@getCoupon']);
|
||||||
|
});
|
||||||
|
|
||||||
159
storage/api-docs/api-docs.json
Normal file
159
storage/api-docs/api-docs.json
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.0.0",
|
||||||
|
"info": {
|
||||||
|
"title": "Example API",
|
||||||
|
"contact": {
|
||||||
|
"name": "Support Team",
|
||||||
|
"email": "support@example.com"
|
||||||
|
},
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"/get-coupon": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"getCoupon"
|
||||||
|
],
|
||||||
|
"summary": "Retrieve a coupon code for the user, based on the selected brand, if available.",
|
||||||
|
"operationId": "/get-coupon",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "brand_id",
|
||||||
|
"in": "query",
|
||||||
|
"description": "ID of the brand for which the coupon is requested.",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Returns the coupon code"
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Error: Not authenticated.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Token expired."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"403": {
|
||||||
|
"description": "Error: Not authorized.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Not authorized."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"bearer": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/generate-coupons": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"generateCoupons"
|
||||||
|
],
|
||||||
|
"summary": "Generates coupon codes for a brand.",
|
||||||
|
"operationId": "/generate-coupons",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "quantity",
|
||||||
|
"in": "query",
|
||||||
|
"description": "Quantity of coupons to be generated.",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "prefix",
|
||||||
|
"in": "query",
|
||||||
|
"description": "Prefix to be used in the coupon codes.",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Success.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Coupon code(s) generation job sent."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Error: Not authenticated.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Token expired."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"403": {
|
||||||
|
"description": "Error: Not authorized.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Not authorized."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"bearer": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
storage/app/.gitignore
vendored
Normal file
2
storage/app/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
3
storage/framework/cache/.gitignore
vendored
Normal file
3
storage/framework/cache/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*
|
||||||
|
!data/
|
||||||
|
!.gitignore
|
||||||
2
storage/framework/cache/data/.gitignore
vendored
Normal file
2
storage/framework/cache/data/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
2
storage/framework/views/.gitignore
vendored
Normal file
2
storage/framework/views/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
2
storage/logs/.gitignore
vendored
Normal file
2
storage/logs/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
21
tests/ExampleTest.php
Normal file
21
tests/ExampleTest.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Laravel\Lumen\Testing\DatabaseMigrations;
|
||||||
|
use Laravel\Lumen\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class ExampleTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A basic test example.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExample()
|
||||||
|
{
|
||||||
|
$this->get('/');
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->app->version(), $this->response->getContent()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
tests/TestCase.php
Normal file
16
tests/TestCase.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Laravel\Lumen\Testing\TestCase as BaseTestCase;
|
||||||
|
|
||||||
|
abstract class TestCase extends BaseTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates the application.
|
||||||
|
*
|
||||||
|
* @return \Laravel\Lumen\Application
|
||||||
|
*/
|
||||||
|
public function createApplication()
|
||||||
|
{
|
||||||
|
return require __DIR__.'/../bootstrap/app.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user