-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f4f517
commit eba4fc2
Showing
17 changed files
with
726 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
APP_ENV=testing | ||
APP_DEBUG=true | ||
APP_KEY=base64:AJ/ZQwE0Mr8+LWlZALhhlHkE8SeHz4OgdqrbzENI0e4= | ||
|
||
DB_CONNECTION=sqlite | ||
DB_DATABASE=test.sqlite | ||
|
||
BROADCAST_DRIVER=log | ||
CACHE_DRIVER=array | ||
SESSION_DRIVER=array | ||
QUEUE_DRIVER=sync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\ListModel; | ||
use Illuminate\Http\Request; | ||
use Validator; | ||
|
||
class ListController extends Controller | ||
{ | ||
public function index(Request $request, \App\Search\ListSearch $listSearch) | ||
{ | ||
return response()->json($listSearch->search($request)); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$validator = Validator::make($request->all(), [ | ||
'name' => 'required|max:191', | ||
// TODO: not sure if max int can be save in db | ||
'price' => 'required|integer|digits_between:0,' . PHP_INT_MAX . '', | ||
'isOnSale' => 'required|boolean', | ||
'city_id' => 'required|exists:cities,id', | ||
'developer_id' => 'required|exists:developers,id', | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return response()->json($validator->errors()); | ||
} | ||
|
||
return response()->json(ListModel::create($request->all())); | ||
} | ||
|
||
public function show($id) | ||
{ | ||
return response()->json(ListModel::findOrFail($id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use App\Search\ListSearch; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ListSearchServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind('App\Search\ListSearch', function ($app) { | ||
return new ListSearch(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
namespace App\Search; | ||
|
||
use App\ListModel; | ||
use Illuminate\Http\Request; | ||
|
||
class ListSearch | ||
{ | ||
private $lists; | ||
|
||
public function __construct() | ||
{ | ||
$this->lists = ListModel::query()->with('city'); | ||
} | ||
|
||
public function search(Request $request) | ||
{ | ||
if ($request->has('isOnSale')) { | ||
$this->handleIsOnSale($request->input('isOnSale')); | ||
} | ||
if ($request->has('country')) { | ||
$this->handleCountry($request->input('country')); | ||
} | ||
if ($request->has('price_less_than')) { | ||
$this->handlePriceLessThan($request->input('price_less_than')); | ||
} | ||
|
||
return $this->lists->get(); | ||
} | ||
|
||
private function handleIsOnSale($isOnSale) | ||
{ | ||
$this->lists->isOnSale($isOnSale); | ||
} | ||
|
||
private function handleCountry($country) | ||
{ | ||
$this->lists->whereHas('city', function($query) use ($country) { | ||
$query->where('country', $country); | ||
}); | ||
} | ||
|
||
private function handlePriceLessThan($price) | ||
{ | ||
$this->lists->priceLessThan($price); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.