Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add Show Model and CRUD Endpoints #103

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions .github/assets/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,55 @@ paths:
format: date-time
- name: end_date
in: query
description: End date of the broadcast schedule.
description: End date of the broadcast schedule. End date must be less than 30 days from today if not logged in
schema:
type: string
format: date-time
- name: days
- name: live
in: query
description: Number of days for which to return the broadcast schedule.
description: If only live shows or not live shows should be returned.
schema:
type: boolean
- name: moderator[]
in: query
description: Array of user ids which shows should be returned.
schema:
type: array
items:
type: integer
- name: primary
in: query
description: If only show should returned where `moderator[]` is primary.
schema:
type: boolean
- name: sort
in: query
schema:
type: string
enum:
- id
- id:asc
- id:desc
- start_date
- start_date:asc
- start_date:desc
- end_date
- end_date:asc
- end_date:desc
default: start_date
- name: per_page
in: query
description: Items to load per page.
schema:
maximum: 30
type: integer
maximum: 50
default: 25
- name: page
in: query
description: Page to load.
schema:
type: integer
default: 1
responses:
"200":
description: OK
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,32 @@
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Validator;

class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;

/**
* Validates the given parameters based on the provided casts and rules.
*
* @param array $params The parameters to be validated.
* @param array $casts The casting rules for the parameters.
* @param array $rules The validation rules for the parameters.
* @return array The validated parameters.
*/
protected function validateParams($params, $casts, $rules): array
{
foreach ($casts as $key => $cast) {
if (isset($params[$key])) {
if ($cast === 'boolean') {
$params[$key] = filter_var($params[$key], FILTER_VALIDATE_BOOLEAN);
} else {
settype($params[$key], $cast);
}
}
}

return Validator::make($params, $rules)->validate();
}
}
Loading
Loading