-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add groups to courses #11
Conversation
Did you implement tests for this feature? |
@fntneves, no we did not. I can work on them during the next days, any tips for how to write them? What features should I test? For example, can I in a single test verify group creation, invitations, accepting and refusing that invitation and test group size limite? |
@@ -28,6 +28,8 @@ public function rules() | |||
'enrollments_end_at' => 'required|date|after:enrollments_start_at', | |||
'exchanges_start_at' => 'required|date|after_or_equal:enrollments_start_at', | |||
'exchanges_end_at' => 'required|date|after:exchanges_start_at', | |||
//'groups_creation_start_at' => 'required|date|after_or_equal:exchanges_end_at', |
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.
@fntneves I left this commented for testing purposes but anyway we need to discuss this, I thought this restriction would fit the feature but want to know your opinion, probably should change "after_or_equal" to "after" though.
45d15e6
to
0766472
Compare
Tests are failing, can you check what is going on? |
9656e37
to
74f4745
Compare
@fntneves Resolvido, tenho de ir adicionando o resto agora |
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.
First of all great work! It's a big MR to a project that brings a really important and needed feature.
My firsts comments are very similar, they are related to missing database transactions, some code refactor and request validation files, etc.
After you resolve this questions I will come back a new review.
I take a quick lock at the tests and I noticed that there a few features tests missing. You should make tests to each store
, update
and destroy
method that you have created. Also, I noticed you have an exception but don't have a test for it, so that is missing too. Notice that the code coverage reduce 15% so, there stills some work to do 😄
Read the comments and discuss with me any problem or any question that you have any doubt or don't agree with. I'll be watching this MR.
database/migrations/2018_07_13_232043_create_memberships_table.php
Outdated
Show resolved
Hide resolved
database/migrations/2018_07_13_232043_create_memberships_table.php
Outdated
Show resolved
Hide resolved
database/migrations/2018_07_21_144829_create_invitations_table.php
Outdated
Show resolved
Hide resolved
7e3269c
to
25367dc
Compare
* | ||
* @return \Illuminate\View\View | ||
*/ | ||
public function index() |
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.
This method really needs a refactor. From where I see it this is what this method needs:
- Get the courses which the authenticated student has enrolled. ( Student::enrolledCourses )
- For each course get only available groups, right? ( Course::availableGroups )
- For each group get the number of invitations, that is being correctly done.
What do you think?
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.
We should discuss this personally
7032a57
to
53b84c9
Compare
53b84c9
to
70a6a87
Compare
bd8ea13
to
ac14f29
Compare
/** @test */ | ||
public function testStudentHasOnlyOneInvitationToEachGroup() | ||
{ | ||
$student = factory(Student::class)->create(); |
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.
add this at the top and remove the try and catch statement
$this->expectException(UserHasAlreadyAnInviteInGroupException::class)
|
||
public function testStudentHasOnlyOneMembershipPerCourse() | ||
{ | ||
$student = factory(Student::class)->create(); |
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.
add this at the top and remove the try and catch statement
$this->expectException(UserHasAlreadyGroupInCourseException::class)
@@ -29,6 +29,18 @@ public function boot() | |||
Validator::extend('student_number', function ($attribute, $value, $parameters, $validator) { | |||
return preg_match('/^(a|pg)[0-9]+$/i', $value) === 1; | |||
}); | |||
|
|||
Validator::extend('greater_or_equal_than_field', function ($attribute, $value, $parameters, $validator) { |
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.
This is how this validation is implemented in laravel 5.7
Maybe you should take a look to make this method similar, just to guarantee we are not missing any case.
https://github.com/laravel/framework/blob/ac745730492ef23a04ce614228d11e496feb625d/src/Illuminate/Validation/Concerns/ValidatesAttributes.php#L879
return $value >= $min_value; | ||
}); | ||
|
||
Validator::replacer('greater_or_equal_than_field', function ($message, $attribute, $rule, $parameters) { |
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.
Same as in the above comment.
https://github.com/laravel/framework/blob/adc49acbefe26f03cd8740003d17d7baf154626e/src/Illuminate/Validation/Concerns/ReplacesAttributes.php#L287
return $group; | ||
}); | ||
|
||
if ($group == null) { |
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.
This case never happens, remove it.
flash('You have successfully joined a group.')->success(); | ||
} catch (UserHasAlreadyGroupInCourseException $e) { | ||
flash('You already have a group.')->error(); | ||
$group->delete(); |
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.
Creating a record and delete it? 2 queries? Hum...
You should check for the existing a group in this course which this user as membership. In this way, this exception is no longer need because the validation is done before...
But what do you think? Is this work worthy?
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.
I have added a couple of suggestions, feel free to skip them if they are not doable at this stage...
public function update(UpdateRequest $request, $id) | ||
{ | ||
DB::transaction(function () use ($request, $id) { | ||
$course = Course::findOrFail($id); |
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.
@djcouto What would you say about using implicit binding for all these resource methods?
This way we could skip calling findOrFail
altogether or even resolve some specific case via middleware if necessary.
So what do you think would be beneficial at this stage applying this refactor?
This is simply a suggestion that can be taken in consideration for every controller 😉
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.
I think is a good suggestion, it cleans some code. My only concerns are if it will get a little messy at the RouteServiceProvider
, but for now, it seems a good approach.
If you choose to do this refactor please don't forget to customize the resolution logic using the method Route::bind
so you can assure that it runs inside a transaction.
DB::transaction(function () use ($request, $id) { | ||
$course = Course::findOrFail($id); | ||
|
||
$course->fill($request->all()); |
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.
Another suggestion of the same nature... Mostly to reduce the length of the code 😄
Instead of these:
$course->fill($request->all());
$course->save();
To this:
$course = tap($course)->update($request->all());
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.
👍
This pull request allows work groups creation.
Admins can setup courses group sizes and the group creation period, they can also view existing groups for each course.
Students can create groups for courses with minimum group size bigger than zero, after group creation they can invite other students to join his group. Invitations are not limited but the number of group elements can not exceed maximum defined group size.