-
Notifications
You must be signed in to change notification settings - Fork 9
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
[Feature] Development programs backend #12481
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9756abc
model skeleton
petertgiles 6189323
tidy factory
petertgiles 6e91365
fix classification relationship name
petertgiles 9232627
schema update
petertgiles 13f5215
development program interest model and seeder
petertgiles 0e641fb
schema update for interest in development programs
petertgiles d2e0405
create and update
petertgiles 923ed59
validators
petertgiles 86a9a3a
phpunit tests
petertgiles b9f147c
fix seeder
petertgiles bac292e
non-localized enum
petertgiles 9acd5d2
update built schema
petertgiles 3d3dcb7
fix tests
petertgiles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,11 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum DevelopmentProgramParticipationStatus | ||
{ | ||
case NOT_INTERESTED; | ||
case INTERESTED; | ||
case ENROLLED; | ||
case COMPLETED; | ||
} |
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
37 changes: 37 additions & 0 deletions
37
api/app/GraphQL/Validators/CreateDevelopmentProgramInterestInputValidator.php
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\GraphQL\Validators; | ||
|
||
use App\Enums\DevelopmentProgramParticipationStatus; | ||
use Database\Helpers\ApiErrorEnums; | ||
use Illuminate\Validation\Rule; | ||
use Nuwave\Lighthouse\Validation\Validator; | ||
|
||
final class CreateDevelopmentProgramInterestInputValidator extends Validator | ||
{ | ||
/** | ||
* Return the validation rules. | ||
* | ||
* @return array<string, array<mixed>> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
// developmentProgramId validated in the Create/UpdateCommunityInterestInputValidator | ||
'participationStatus' => [Rule::in(array_column(DevelopmentProgramParticipationStatus::cases(), 'name'))], | ||
'completionDate' => [ | ||
'date', | ||
'required_if:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
'prohibited_unless:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
], | ||
]; | ||
} | ||
|
||
public function messages(): array | ||
{ | ||
return [ | ||
'completionDate.required_if' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_REQUIRED, | ||
'completionDate.prohibited_unless' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_PROHIBITED, | ||
]; | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
api/app/GraphQL/Validators/UpdateDevelopmentProgramInterestInputValidator.php
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,36 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Validators; | ||
|
||
use App\Enums\DevelopmentProgramParticipationStatus; | ||
use Database\Helpers\ApiErrorEnums; | ||
use Illuminate\Validation\Rule; | ||
use Nuwave\Lighthouse\Validation\Validator; | ||
|
||
final class UpdateDevelopmentProgramInterestInputValidator extends Validator | ||
{ | ||
/** | ||
* Return the validation rules. | ||
* | ||
* @return array<string, array<mixed>> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'participationStatus' => [Rule::in(array_column(DevelopmentProgramParticipationStatus::cases(), 'name'))], | ||
'completionDate' => [ | ||
'date', | ||
'required_if:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
'prohibited_unless:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
], | ||
]; | ||
} | ||
|
||
public function messages(): array | ||
{ | ||
return [ | ||
'completionDate.required_if' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_REQUIRED, | ||
'completionDate.prohibited_unless' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_PROHIBITED, | ||
]; | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
|
||
/** | ||
* Class DevelopmentProgram | ||
* | ||
* @property string $id | ||
* @property \Illuminate\Support\Carbon $created_at | ||
* @property ?\Illuminate\Support\Carbon $updated_at | ||
* @property ?\Illuminate\Support\Carbon $deleted_at | ||
* @property array $name | ||
* @property array $description_for_profile | ||
* @property array $description_for_nominations | ||
* @property string $community_id | ||
*/ | ||
class DevelopmentProgram extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $keyType = 'string'; | ||
|
||
/** | ||
* The attributes that should be cast. | ||
*/ | ||
protected $casts = [ | ||
'name' => 'array', | ||
'description_for_profile' => 'array', | ||
'description_for_nominations' => 'array', | ||
]; | ||
|
||
/** @return BelongsTo<Community, $this> */ | ||
public function community(): BelongsTo | ||
{ | ||
return $this->belongsTo(Community::class); | ||
} | ||
|
||
/** @return BelongsToMany<Classification, $this> */ | ||
public function eligibleClassifications(): BelongsToMany | ||
{ | ||
return $this->belongsToMany(Classification::class); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Enums\DevelopmentProgramParticipationStatus; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
/** | ||
* Class DevelopmentProgramInterest | ||
* | ||
* @property string $id | ||
* @property \Illuminate\Support\Carbon $created_at | ||
* @property ?\Illuminate\Support\Carbon $updated_at | ||
* @property ?\Illuminate\Support\Carbon $deleted_at | ||
* @property string $development_program_id | ||
* @property string $community_interest_id | ||
* @property string $participation_status | ||
* @property ?\Illuminate\Support\Carbon $completion_date | ||
*/ | ||
class DevelopmentProgramInterest extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $keyType = 'string'; | ||
|
||
/** | ||
* The attributes that should be cast. | ||
*/ | ||
protected $casts = [ | ||
'participation_status' => DevelopmentProgramParticipationStatus::class, | ||
'completion_date' => 'datetime', | ||
]; | ||
|
||
/** @return BelongsTo<CommunityInterest, $this> */ | ||
public function communityInterest(): BelongsTo | ||
{ | ||
return $this->belongsTo(CommunityInterest::class); | ||
} | ||
|
||
/** @return BelongsTo<DevelopmentProgram, $this> */ | ||
public function developmentProgram(): BelongsTo | ||
{ | ||
return $this->belongsTo(DevelopmentProgram::class); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Classification; | ||
use App\Models\Community; | ||
use App\Models\DevelopmentProgram; | ||
use Database\Helpers\FactoryHelpers; | ||
use ErrorException; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class DevelopmentProgramFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = DevelopmentProgram::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'name' => FactoryHelpers::toFakeLocalizedString($this->faker->company()), | ||
'description_for_profile' => FactoryHelpers::toFakeLocalizedString($this->faker->sentence()), | ||
'description_for_nominations' => FactoryHelpers::toFakeLocalizedString($this->faker->sentence()), | ||
'community_id' => function () { | ||
$community = Community::inRandomOrder()->firstOr(fn () => Community::factory()->withWorkStreams()->create()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh this is cool! I did not know about |
||
|
||
return $community->id; | ||
}, | ||
]; | ||
} | ||
|
||
public function configure() | ||
{ | ||
return $this | ||
->afterMaking(function (DevelopmentProgram $model) { | ||
// https://laravel.com/docs/10.x/eloquent-factories#belongs-to-relationships | ||
if (is_null($model->community_id)) { | ||
throw new ErrorException('community_id must be set to use this factory. Try calling this factory with the `for` method to specify the parent community.'); | ||
} | ||
}); | ||
} | ||
|
||
public function withEligibleClassifications(?int $min = 1, ?int $max = 3) | ||
{ | ||
$count = $this->faker->numberBetween($min, $max); | ||
|
||
return $this->afterCreating(function (DevelopmentProgram $program) use ($count) { | ||
$classifications = Classification::inRandomOrder()->limit($count)->get(); | ||
$program->eligibleClassifications()->sync($classifications); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it's a bit awkward that we can't validate this member of the input in its own validator. We don't have the community_id at this level and having two validators for the same field doesn't seem to work in Laravel.