-
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
Jovana Marsilio
committed
Dec 3, 2020
1 parent
55ab955
commit b15808e
Showing
16 changed files
with
663 additions
and
79 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
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,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Carbon\Carbon; | ||
|
||
class VolunteerRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
$rules = [ | ||
'volunteer.name' => 'required|string|max:255', | ||
'volunteer.birth_date' => 'required|string|size:10|date_format:d/m/Y', | ||
'volunteer.cpf' => 'required|string|size:14', | ||
'volunteer.cell_phone' => 'required|string|size:15', | ||
'volunteer.email' => 'nullable|email', | ||
'volunteer.responsible_name' => 'nullable|string|max:255', | ||
'volunteer.responsible_cpf' => 'nullable|string|size:14', | ||
'volunteer.occupation' => 'required|string|max:150', | ||
'volunteer.city_id' => 'required|numeric', | ||
'volunteer.available_time' => 'required|numeric', | ||
'volunteer_week_day' => 'required|array', | ||
'volunteer.expertise_area_id' => 'required|numeric', | ||
'volunteer.confirmation' => 'required|numeric', | ||
]; | ||
|
||
if (request()->input('volunteer.birth_date')) { | ||
// Rescues the volunteer's date of birth. | ||
$volunteerBirthDate = Carbon::createFromFormat('d/m/Y', request()->input('volunteer.birth_date')); | ||
|
||
// Is under 18 years old? | ||
if ($volunteerBirthDate->diffInYears(now()) < 18) { | ||
// Responsible is required. | ||
$rules['volunteer.responsible_name'] = 'required|string|max:255'; | ||
$rules['volunteer.responsible_cpf'] = 'required|string|size:14'; | ||
} | ||
} | ||
|
||
return $rules; | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Carbon\Carbon; | ||
|
||
class Volunteer extends Model | ||
{ | ||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'city_id', | ||
'expertise_area_id', | ||
'name', | ||
'birth_date', | ||
'cpf', | ||
'cell_phone', | ||
'email', | ||
'responsible_name', | ||
'responsible_cpf', | ||
'occupation', | ||
'available_time', | ||
'ip', | ||
'user_agent', | ||
]; | ||
|
||
/** | ||
* The attributes that should be cast. | ||
* | ||
* @var array | ||
*/ | ||
// protected $casts = [ | ||
// 'birth_date' => 'datetime:Y-m-d', | ||
// ]; | ||
|
||
/** | ||
* Volunteer week days. | ||
*/ | ||
public function volunteerWeekDays() | ||
{ | ||
return $this->hasMany('App\Models\VolunteerWeekDay', 'volunteer_id', 'id'); | ||
} | ||
|
||
/** | ||
* City. | ||
*/ | ||
public function city() | ||
{ | ||
return $this->belongsTo('App\Models\City', 'city_id', 'id'); | ||
} | ||
|
||
/** | ||
* Expertise area. | ||
*/ | ||
public function expertiseArea() | ||
{ | ||
return $this->belongsTo('App\Models\ExpertiseArea', 'expertise_area_id', 'id'); | ||
} | ||
|
||
/** | ||
* Set the volunteer's birth date. | ||
* | ||
* @param string $birthDate | ||
* @return void | ||
*/ | ||
public function setBirthDateAttribute($birthDate) | ||
{ | ||
$this->attributes['birth_date'] = Carbon::createFromFormat('d/m/Y', $birthDate)->format('Y-m-d'); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class VolunteerWeekDay extends Model | ||
{ | ||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'volunteer_id', | ||
'week_day_id', | ||
]; | ||
|
||
/** | ||
* Volunteer. | ||
*/ | ||
public function volunteer() | ||
{ | ||
return $this->belongsTo('App\Models\Volunteer', 'volunteer_id', 'id'); | ||
} | ||
|
||
/** | ||
* Week day. | ||
*/ | ||
public function weekDay() | ||
{ | ||
return $this->belongsTo('App\Models\WeekDay', 'week_day_id', '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,14 @@ | ||
<?php | ||
|
||
namespace App\Repositories; | ||
|
||
use App\Repositories\Repository; | ||
use App\Models\Volunteer; | ||
|
||
class VolunteerRepository extends Repository | ||
{ | ||
public function __construct(Volunteer $model) | ||
{ | ||
$this->model = $model; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace App\Repositories; | ||
|
||
use App\Repositories\Repository; | ||
use App\Models\VolunteerWeekDay; | ||
|
||
class VolunteerWeekDayRepository extends Repository | ||
{ | ||
public function __construct(VolunteerWeekDay $model) | ||
{ | ||
$this->model = $model; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
abstract class Service | ||
{ | ||
/** | ||
* Construtor da classe. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Resposta padrão do serviço. | ||
* | ||
* @param array $data | ||
* @return Object | ||
*/ | ||
public function response($data = []) | ||
{ | ||
// Por default o error é sempre vazio. | ||
$default = ['error' => null]; | ||
|
||
// Concatena com os dados. | ||
$data = array_merge($default, $data); | ||
|
||
// Converte para objeto. | ||
$data = (object) $data; | ||
|
||
return $data; | ||
} | ||
} |
Oops, something went wrong.