<commit_before><?php namespace App\Http\Controllers;

use App\Models\AssignmentUpdate;
use App\Models\User;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class AssignmentUpdatesController extends Controller
{
    public function getMyUpdates()
    {
        $assignmentsUpdates = Auth::user()->assignments->map(
            function($assignment) {
                return $assignment->updates;
            }
        )->flatten()->pluck('id');

        $updatesWithBooks = AssignmentUpdate::whereIn('id', $assignmentsUpdates)
            ->orderBy('created_at', 'desc')
            ->with('assignment.book')->get();

        return response(['updates' => $updatesWithBooks], 200);
    }

    public function getMyStudentUpdates()
    {
        $assignmentsUpdates = User::where('role', 'student')->get()
            ->map(function($user) {
                return $user->assignments;
            })->flatten()->map(
            function($assignment) {
                return $assignment->updates;
            }
        )->flatten()->pluck('id');

        $updatesWithBooks = AssignmentUpdate::whereIn('id', $assignmentsUpdates)
            ->orderBy('created_at', 'desc')
            ->with(['assignment.book', 'assignment.user'])->get();

        return response(['updates' => $updatesWithBooks], 200);
    }

    public function getUpdatesForStudent($studentId)
    {
        $assignmentsUpdateIds = User::find($studentId)->assignments->pluck('id');

        $updatesWithBooks = AssignmentUpdate::whereIn('assignment_id', $assignmentsUpdateIds)
            ->orderBy('created_at', 'desc')
            ->with(['assignment.book', 'assignment.response'])
            ->get();<commit_msg>return only updates of teacher's students, not all<commit_after><?php namespace App\Http\Controllers;

use App\Models\AssignmentUpdate;
use App\Models\User;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class AssignmentUpdatesController extends Controller
{
    public function getMyUpdates()
    {
        $assignmentsUpdates = Auth::user()->assignments->map(
            function($assignment) {
                return $assignment->updates;
            }
        )->flatten()->pluck('id');

        $updatesWithBooks = AssignmentUpdate::whereIn('id', $assignmentsUpdates)
            ->orderBy('created_at', 'desc')
            ->with('assignment.book')->get();

        return response(['updates' => $updatesWithBooks], 200);
    }

    public function getMyStudentUpdates()
    {
        $teacher = Auth::user()->teacher;
        $groups = $teacher->groups;
        
        $assignmentsUpdates = $groups->map(function($group) { return $group->studentGroups; })
            ->flatten()
            ->map(function($studentGroup) { return $studentGroup->student; })
            ->map(function($user) {return $user->assignments;})
            ->flatten()->map(function($assignment) { return $assignment->updates; })
            ->flatten()
            ->pluck('id');

        $updatesWithBooks = AssignmentUpdate::whereIn('id', $assignmentsUpdates)
            ->orderBy('created_at', 'desc')
            ->with(['assignment.book', 'assignment.user'])->get();

        return response(['updates' => $updatesWithBooks], 200);
    }

    public function getUpdatesForStudent($studentId)
    {
        $assignmentsUpdateIds = User::find($studentId)->assignments->pluck('id');

        $updatesWithBooks = AssignmentUpdate::whereIn('assignment_id', $assignmentsUpdateIds)
            ->orderBy('created_at', 'desc')
            ->with(['assignment.book', 'assignment.response'])
            ->get();
{'fraction_non_alphanumeric': 0.1547300908605024, 'fraction_numerical': 0.003206841261357563, 'mean_word_length': 2.870734229576008, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2490186', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1042, 'n_words': 167}