This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #57 from improv-ee/feature/order-form
New functionality - GigAds for hiring performers
- Loading branch information
Showing
43 changed files
with
1,743 additions
and
181 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,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\V1\Gig\CategoryResource; | ||
use App\Orm\GigCategory; | ||
use Spatie\QueryBuilder\QueryBuilder; | ||
|
||
|
||
/** | ||
* @group Gigs | ||
* | ||
* Gig categories categorize gig ads | ||
* Examples: Performance, workshop | ||
*/ | ||
class GigCategoryController extends Controller | ||
{ | ||
/** | ||
* List all Gig categories | ||
*/ | ||
public function index() | ||
{ | ||
|
||
$categories = QueryBuilder::for(GigCategory::class) | ||
->orderBy('order', 'asc') | ||
->paginate(15); | ||
|
||
return CategoryResource::collection($categories); | ||
} | ||
} |
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,131 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\Gigad\DeleteGigadRequest; | ||
use App\Http\Requests\Gigad\StoreGigadRequest; | ||
use App\Http\Requests\Gigad\UpdateGigadRequest; | ||
use App\Http\Resources\V1\GigadResource; | ||
use App\Http\Services\GigadStorageService; | ||
use App\Orm\Gigad; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
use Spatie\QueryBuilder\AllowedFilter; | ||
use Spatie\QueryBuilder\QueryBuilder; | ||
|
||
/** | ||
* Control Gig Ads | ||
* | ||
* A Gig Ad is an advertisement from an organization to accept types of Gigs. | ||
* For example, an organization might offer companies 'shows for hire', where they perform | ||
* at the time and place of the customers choosing | ||
* | ||
* @group Gigs | ||
*/ | ||
class GigadController extends Controller | ||
{ | ||
/** | ||
* @var GigadStorageService | ||
*/ | ||
private GigadStorageService $gigadStorageService; | ||
|
||
/** | ||
* @param GigadStorageService $gigadStorageService | ||
*/ | ||
public function __construct(GigadStorageService $gigadStorageService) | ||
{ | ||
$this->gigadStorageService = $gigadStorageService; | ||
} | ||
|
||
|
||
/** | ||
* Show Gigad details | ||
* | ||
* @param Gigad $gigad | ||
* @return JsonResource | ||
*/ | ||
public function show(Gigad $gigad): JsonResource | ||
{ | ||
return new GigadResource($gigad); | ||
} | ||
|
||
/** | ||
* List all Gigads | ||
* | ||
* @param Request $request | ||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
|
||
$gigads = QueryBuilder::for(Gigad::class) | ||
->allowedFilters([ | ||
AllowedFilter::exact('is_public'), | ||
AllowedFilter::exact('gig_category_id'), | ||
AllowedFilter::exact('organization.uid') | ||
]) | ||
->orderBy('id', 'asc') | ||
->onlyMine($request->input('onlyMine', false)) | ||
->paginate(15); | ||
|
||
return GigadResource::collection($gigads); | ||
} | ||
|
||
/** | ||
* Create a new Gigad | ||
* | ||
* @param StoreGigadRequest $request | ||
* @return GigadResource | ||
* @authenticated | ||
* @bodyParam description string Long (markdown-enabled) description of the organization | ||
* @bodyParam is_public boolean Whether or not to show this publicly | ||
* @bodyParam link string Link to "read more" | ||
* @bodyParam int gig_category_id Numeric category ID | ||
* @bodyParam string organization_uid Organization who owns this | ||
*/ | ||
public function store(StoreGigadRequest $request) | ||
{ | ||
|
||
$gigad = new Gigad; | ||
$gigad->setToken(); | ||
|
||
$this->gigadStorageService->update($gigad,$request); | ||
|
||
return new GigadResource($gigad); | ||
} | ||
|
||
/** | ||
* Update an ad | ||
* | ||
* @param Gigad $gigad | ||
* @param UpdateGigadRequest $request | ||
* @return GigadResource | ||
* @bodyParam description string Long (markdown-enabled) description of the organization | ||
* @bodyParam is_public boolean Whether or not to show this publicly | ||
* @bodyParam link string Link to "read more" | ||
* @bodyParam int gig_category_id Numeric category ID | ||
* @bodyParam string organization_uid Organization who owns this | ||
* @authenticated | ||
*/ | ||
public function update(Gigad $gigad, UpdateGigadRequest $request) | ||
{ | ||
|
||
$this->gigadStorageService->update($gigad,$request); | ||
return new GigadResource($gigad); | ||
} | ||
|
||
|
||
/** | ||
* Delete a Gigad | ||
* | ||
* @param Gigad $gigad | ||
* @param DeleteGigadRequest $request | ||
* @throws \Exception | ||
* @authenticated | ||
*/ | ||
public function destroy(Gigad $gigad, DeleteGigadRequest $request) | ||
{ | ||
$gigad->delete(); | ||
} | ||
} |
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\Requests\Gigad; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class DeleteGigadRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
|
||
$gigadOrganizations = $this->gigad->organization()->get()->pluck('id')->toArray(); | ||
foreach (Auth::user()->organizations()->get() as $organization) { | ||
if (in_array($organization->id, $gigadOrganizations)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Gigad; | ||
|
||
class StoreGigadRequest extends UpdateGigadRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Gigad; | ||
|
||
use App\Rules\Base64HeaderImage; | ||
use App\Rules\ContainsMyOrganization; | ||
|
||
class UpdateGigadRequest extends DeleteGigadRequest | ||
{ | ||
|
||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'link' => 'max:255|nullable|min:5|url', | ||
'description' => 'max:500|nullable', | ||
'organization_uid' => ['required', 'exists:organizations,uid', new ContainsMyOrganization], | ||
'images.header.content' => ['nullable', new Base64HeaderImage], | ||
'is_public' => 'required|bool', | ||
'gig_category_id' => ['required', 'int', 'exists:gig_categories,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources\V1\Gig; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
/** | ||
* @package App\Http\Resources\V1\Gig | ||
*/ | ||
class CategoryResource extends JsonResource | ||
{ | ||
|
||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function toArray($request) | ||
{ | ||
|
||
return [ | ||
'id' => $this['id'], | ||
'name' => $this['name'], | ||
'description' => $this['description'], | ||
'order'=> $this['order'], | ||
'ads' => $this->gigads->count() | ||
]; | ||
} | ||
|
||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources\V1; | ||
|
||
use App\Http\Resources\V1\Image\HeaderImageResource; | ||
use App\Orm\GigCategory; | ||
use App\Orm\Organization; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
/** | ||
* @property Organization $organization | ||
* @property GigCategory $category | ||
* @package App\Http\Resources\V1 | ||
*/ | ||
class GigadResource extends JsonResource | ||
{ | ||
|
||
|
||
|
||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function toArray($request) | ||
{ | ||
|
||
return [ | ||
'uid' => $this['uid'], | ||
'category' => [ | ||
'id' => $this->category->id, | ||
'name' => $this->category->name | ||
], | ||
'organization' => [ | ||
'uid' => $this->organization->uid, | ||
'name' => $this->organization->name | ||
], | ||
'link'=> $this['link'], | ||
'description' => $this['description'], | ||
'times' => [ | ||
'updated_at'=>$this['updated_at']->toIso8601String() | ||
], | ||
'is_public' => $this['is_public'], | ||
'images' => new HeaderImageResource($this) | ||
]; | ||
} | ||
|
||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Services; | ||
|
||
use App\Http\Requests\Gigad\UpdateGigadRequest; | ||
use App\Http\Services\Traits\SavesMediaTrait; | ||
use App\Orm\Gigad; | ||
use App\Orm\Organization; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class GigadStorageService | ||
{ | ||
use SavesMediaTrait; | ||
|
||
/** | ||
* @param Gigad $gigad | ||
* @param UpdateGigadRequest $request | ||
* @return Gigad | ||
*/ | ||
public function update(Gigad $gigad, UpdateGigadRequest $request): Gigad | ||
{ | ||
$gigad->link = $request->input('link'); | ||
$gigad->description = $request->input('description'); | ||
$gigad->organization_id = Organization::where('uid', $request->input('organization_uid'))->first()->id; | ||
$gigad->gig_category_id = $request->input('gig_category_id'); | ||
$gigad->is_public = $request->input('is_public', false); | ||
|
||
DB::transaction(function () use ($gigad, $request) { | ||
$gigad->save(); | ||
|
||
$this->syncMedia($request, $gigad); | ||
}); | ||
|
||
|
||
return $gigad; | ||
} | ||
} |
Oops, something went wrong.