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

Add groups to courses #11

Closed
wants to merge 25 commits into from
Closed

Add groups to courses #11

wants to merge 25 commits into from

Conversation

machadovilaca
Copy link
Member

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.

@fntneves fntneves changed the title Work Groups Add groups to courses Jul 24, 2018
@fntneves
Copy link
Member

Did you implement tests for this feature?
If not, this is why the "cross" is appearing. However, I will look at it for a first review and then you work on tests.

@machadovilaca
Copy link
Member Author

@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',
Copy link
Member Author

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.

@fntneves
Copy link
Member

fntneves commented Sep 4, 2018

Tests are failing, can you check what is going on?

@machadovilaca machadovilaca force-pushed the pm-jv-work_groups branch 3 times, most recently from 9656e37 to 74f4745 Compare September 7, 2018 19:03
@machadovilaca
Copy link
Member Author

machadovilaca commented Sep 7, 2018

@fntneves Resolvido, tenho de ir adicionando o resto agora

@djcouto djcouto self-requested a review September 10, 2018 10:59
Copy link
Member

@djcouto djcouto left a 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.

app/Http/Controllers/Admin/CourseController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/CourseController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/CourseController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/CourseController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/CourseController.php Outdated Show resolved Hide resolved
public/css/app.css Outdated Show resolved Hide resolved
@machadovilaca machadovilaca force-pushed the pm-jv-work_groups branch 3 times, most recently from 7e3269c to 25367dc Compare September 16, 2018 14:38
app/Exceptions/UserHasAlreadyAnInviteInGroupException.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/GroupController.php Outdated Show resolved Hide resolved
app/Http/Controllers/GroupController.php Outdated Show resolved Hide resolved
app/Http/Controllers/GroupController.php Outdated Show resolved Hide resolved
tests/Feature/InvitationTest.php Show resolved Hide resolved
tests/Unit/GroupTest.php Outdated Show resolved Hide resolved
tests/Unit/GroupTest.php Outdated Show resolved Hide resolved
resources/views/admin/groups/index.blade.php Show resolved Hide resolved
*
* @return \Illuminate\View\View
*/
public function index()
Copy link
Member

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?

Copy link
Member Author

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

@machadovilaca machadovilaca force-pushed the pm-jv-work_groups branch 2 times, most recently from 7032a57 to 53b84c9 Compare October 5, 2018 19:36
/** @test */
public function testStudentHasOnlyOneInvitationToEachGroup()
{
$student = factory(Student::class)->create();
Copy link
Member

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();
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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();
Copy link
Member

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?

Copy link
Member

@hmatalonga hmatalonga left a 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);
Copy link
Member

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 😉

Copy link
Member

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());
Copy link
Member

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());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fntneves fntneves closed this Jun 21, 2019
@fntneves fntneves deleted the pm-jv-work_groups branch July 2, 2019 13:19
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.

4 participants