Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangums committed Mar 7, 2022
0 parents commit f0af620
Show file tree
Hide file tree
Showing 137 changed files with 36,500 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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

[docker-compose.yml]
indent_size = 4
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/node_modules
/public/hot
/public/storage
/public/css/app.css
/public/js/app.js
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/.idea
/.vscode
tags
14 changes: 14 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
php:
preset: laravel
version: 8
disabled:
- no_unused_imports
finder:
not-name:
- index.php
- server.php
js:
finder:
not-name:
- webpack.mix.js
css: true
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

## About Giraffe Api Service

Laravel Sanctum ...
41 changes: 41 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\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)
{
// $schedule->command('inspire')->hourly();
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
41 changes: 41 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}
61 changes: 61 additions & 0 deletions app/Filters/Filters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Filters;

use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Builder;

abstract class Filters
{
/**
* @var Request $request
*/
public Request $request;

/**
* @var Builder $builder
*/
protected Builder $builder;

/**
* @var array $filters
*/
protected array $filters;

/**
* Filters constructor.
*
* @param Request $request
*/
public function __construct(Request $request)
{
$this->request = $request;
}

/**
* Apply filters to the builder.
*
* @param Builder $builder
* @return Builder
*/
public function apply(Builder $builder): Builder
{
$this->builder = $builder;

collect($this->getFilters())->each(function (?string $value, string $filter) {
if (method_exists($this, $filter)) {
$this->$filter($value);
}
});

return $this->builder;
}

/**
* @return array
*/
private function getFilters(): array
{
return $this->request->only(array_intersect(array_keys($this->request->all()), $this->filters));
}
}
74 changes: 74 additions & 0 deletions app/Filters/MarkedIndividualFilters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Filters;

use Illuminate\Database\Eloquent\Builder;

class MarkedIndividualFilters extends Filters
{
/**
* All the filters available to filter through
*
* @var array
*/
protected array $filters = [
'max_age', 'min_age', 'species', 'gender','location',
];

public function min_age(?int $min): Builder
{
if (is_null($min)) {
return $this->builder;
}

return $this->builder->whereHas('encounters', fn(Builder $query) => $query->where('AGE', '>=', $min));
}

public function max_age(?int $max): Builder
{
if (is_null($max)) {
return $this->builder;
}

return $this->builder->whereHas('encounters', fn(Builder $query) => $query->where(fn(Builder $q) => $q->where('AGE', '<=', $max)->orWhereNull('AGE')));
}

public function species(?string $species): Builder
{
if (is_null($species)) {
return $this->builder;
}

return $this->builder->whereHas('encounters', fn(Builder $query) => $query->where('SPECIFICEPITHET', $species));
}

/**
* Filter by gender.
*
* @param string|null $gender
* @return Builder
*/
public function gender(?string $gender): Builder
{
if (is_null($gender)) {
return $this->builder;
}

$genders = [
'm' => ['m', 'M', 'male', 'Male', 'MALE'],
'f' => ['f', 'F', 'female', 'Female', 'FEMALE'],
'u' => ['u', 'U', 'unknown', 'Unknown', 'UNKNOWN', null],
];

return $this->builder->whereIn('SEX', $genders[$gender]);
}

public function location(?string $location)
{
if (is_null($location)) {
return $this->builder;
}

return $this->builder->whereHas('encounters', fn(Builder $query) => $query->where('LOCATIONID', $location));
}
}
Loading

0 comments on commit f0af620

Please sign in to comment.