-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from binaryk/search-service
Search service
- Loading branch information
Showing
18 changed files
with
1,036 additions
and
56 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,56 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Contracts; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* @author Eduard Lupacescu <[email protected]> | ||
*/ | ||
interface RestifySearchable | ||
{ | ||
const DEFAULT_PER_PAGE = 15; | ||
|
||
const MATCH_TEXT = 'text'; | ||
const MATCH_BOOL = 'bool'; | ||
const MATCH_INTEGER = 'integer'; | ||
|
||
/** | ||
* @param Request $request | ||
* @param array $fields | ||
* @return array | ||
*/ | ||
public function serializeForIndex(Request $request, array $fields = []); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getSearchableFields(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getWiths(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getInFields(); | ||
|
||
/** | ||
* Find matches in the table by given value | ||
* Returns an array like: | ||
* [ 'table_column_name' => 'type' ], type can be: text, bool, boolean, int, integer, number | ||
* e.g. [ 'id' => 'int' ]. | ||
* | ||
* To use this filter we have to send in query: | ||
* [ 'match' => [ 'id' => 1 ] ] | ||
* @return array | ||
*/ | ||
public static function getMatchByFields(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getOrderByFields(); | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Controllers; | ||
|
||
/** | ||
* @author Eduard Lupacescu <[email protected]> | ||
*/ | ||
trait RestIndexController | ||
{ | ||
} |
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
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,66 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Http\Requests; | ||
|
||
use Binaryk\LaravelRestify\Exceptions\Eloquent\EntityNotFoundException; | ||
use Binaryk\LaravelRestify\Exceptions\UnauthorizedException; | ||
use Binaryk\LaravelRestify\Repositories\Repository; | ||
use Binaryk\LaravelRestify\Restify; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @author Eduard Lupacescu <[email protected]> | ||
*/ | ||
trait InteractWithRepositories | ||
{ | ||
/** | ||
* @var Model | ||
*/ | ||
public $model; | ||
|
||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the class name of the repository being requested. | ||
* | ||
* @return Repository | ||
* @throws EntityNotFoundException | ||
* @throws UnauthorizedException | ||
*/ | ||
public function repository() | ||
{ | ||
return tap(Restify::repositoryForKey($this->route('repository')), function ($repository) { | ||
if (is_null($repository)) { | ||
throw new EntityNotFoundException(__('Repository :name not found.', [ | ||
'name' => $repository, | ||
]), 404); | ||
} | ||
|
||
if (! $repository::authorizedToViewAny($this)) { | ||
throw new UnauthorizedException(__('Unauthorized to view repository :name.', [ | ||
'name' => $repository, | ||
]), 403); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,47 +2,12 @@ | |
|
||
namespace Binaryk\LaravelRestify\Http\Requests; | ||
|
||
use Binaryk\LaravelRestify\Exceptions\Eloquent\EntityNotFoundException; | ||
use Binaryk\LaravelRestify\Exceptions\UnauthorizedException; | ||
use Binaryk\LaravelRestify\Restify; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
/** | ||
* @author Eduard Lupacescu <[email protected]> | ||
*/ | ||
class RestifyRequest extends FormRequest | ||
{ | ||
/** | ||
* Get the class name of the repository being requested. | ||
* | ||
* @return mixed | ||
*/ | ||
public function repository() | ||
{ | ||
return tap(Restify::repositoryForKey($this->route('repository')), function ($repository) { | ||
if (is_null($repository)) { | ||
throw new EntityNotFoundException(__('Repository :name not found.', [ | ||
'name' => $repository, | ||
]), 404); | ||
} | ||
|
||
if (! $repository::authorizedToViewAny($this)) { | ||
throw new UnauthorizedException(__('Unauthorized to view repository :name.', [ | ||
'name' => $repository, | ||
]), 403); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
use InteractWithRepositories; | ||
} |
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.