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(Routes file & Student CRUD's first mehods) #25

Merged
merged 2 commits into from
Nov 2, 2023

Conversation

j-obiols
Copy link
Contributor

@j-obiols j-obiols commented Oct 31, 2023

This pull request:

1 - According an approach by @elpupas, creates a routes file named v1.php instead of api.php (v1 stands for version 1) and modifies accordingly the file RouteServiceProvider.php, to indicate this file's location and to set API calls prefixes (api/v1).

2 - Studying and developing an approach by @androsrivas, this pull request sets an abstract class named UserRequest that extends FormRequest and defines User's register validation rules.

In this abstract class, we have overwritten the method failedValidation(...) from original FormRequest class, in order to send validation errors messages to API calls when needed.

To Store Admins, Students or Recruiters, other Form Requests will be created extending User Request and setting new validation register rules for each case.

A first version of StoreStudentRequest is already included in this commit. Notice that, in order to send all validation rules to the Controller when required, we've had to modify the function rules(). Now it will return an array merging the Parent::rules with this class own validation rules.

With this approach:

a) Store methods in each model's controller are simpler.
b) Each StoreModelRequest is also simpler, as it doesn't have to rewrite User validation rules, it just has to call for them.

3 - In Store methods, we create a $user and then, we a create a $user -> student (the relation being previously defined in the Models...). This way the foreign Key is set automatically. This system can be applied to admins and recruiters.

As two entities must be created, a DB::transaction is implemented to avoid database inconsistency, following a proposal by @CloudSalander.

@CloudSalander
Copy link
Collaborator

It's really nice to see how you increase your technical level with the approach that you're using on that feature.
Great.!
Can you fix the two littles conflicts that we have?

Thanks :)

@j-obiols
Copy link
Contributor Author

j-obiols commented Nov 2, 2023

Hello, I have tried to solve the conflicts by accepting develop branch settings about Laravel Pint, but I believe there is something there to be fixed...In my branch I had the latest version (5) because I ran composer update after one pull, and in composer is set v.4...

@j-obiols j-obiols removed the request for review from pupadevs November 2, 2023 11:49
@CloudSalander
Copy link
Collaborator

Okey, we will check Pint issues. Now, for the sake of the work of your partners I will merge the branch.
Thank you!

@CloudSalander CloudSalander merged commit d19a68b into develop Nov 2, 2023
1 check passed
@j-obiols j-obiols deleted the feature/student-crud branch November 13, 2023 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants