Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
jringeisen committed Feb 14, 2024
2 parents 93c3ea8 + 49f63a1 commit b830219
Show file tree
Hide file tree
Showing 22 changed files with 428 additions and 35 deletions.
27 changes: 27 additions & 0 deletions app/Http/Controllers/ImpersonationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Laravel\Nova\Contracts\ImpersonatesUsers;

class ImpersonationController extends Controller
{
public function start(Request $request, User $user, ImpersonatesUsers $impersonator)
{
$this->authorize('view', $user);

$impersonator->impersonate($request, Auth::guard(), $user);

return redirect(route('student.prompts.index'));
}

public function stop(Request $request, ImpersonatesUsers $impersonator)
{
$impersonator->stopImpersonating($request, Auth::guard(), User::class);

return redirect('/');
}
}
12 changes: 11 additions & 1 deletion app/Http/Middleware/IsParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ class IsParent
*/
public function handle(Request $request, Closure $next): Response
{
if (! $request->user()->isParent()) {
$user = $request->user();

if ($user->isStudent()) {
return redirect(RouteServiceProvider::STUDENT_HOME);
}

if ($request->route()->named('parent.users.create') || $request->route()->named('parent.users.store')) {
return $next($request);
}

if (! $user->students()->count()) {
return redirect()->route('parent.users.create', ['status' => 'onboarding']);
}

return $next($request);
}
}
8 changes: 4 additions & 4 deletions app/Services/Adapters/AI/OpenAI/OpenAIAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public function request(bool $isString = false): AIContentDto
$chatCreationOptions = [
'model' => self::MODEL,
'messages' => $this->messages->toArray(),
'user' => 'user-' . $this->user->id,
'user' => 'user-'.$this->user->id,
];

if (!$isString) {
if (! $isString) {
$chatCreationOptions['response_format'] = ['type' => 'json_object'];
}

Expand Down Expand Up @@ -102,7 +102,7 @@ function () {
->createStreamed([
'model' => self::MODEL,
'messages' => $this->messages->toArray(),
'user' => 'user-' . $this->user->id,
'user' => 'user-'.$this->user->id,
]);

$message = '';
Expand All @@ -129,7 +129,7 @@ function () {
);
}

echo 'data: ' . json_encode($data, JSON_THROW_ON_ERROR) . "\n\n";
echo 'data: '.json_encode($data, JSON_THROW_ON_ERROR)."\n\n";

ob_flush();
flush();
Expand Down
4 changes: 4 additions & 0 deletions app/Services/StudentInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Laravel\Nova\Contracts\ImpersonatesUsers;

class StudentInertiaRequests
{
public function __invoke(Request $request): array
{
$impersonator = app(ImpersonatesUsers::class);

return [
'auth' => [
'type' => 'student',
'user' => $request->user(),
'navigation' => $this->navigation(),
'subjects' => $this->subjects(),
'isImpersonated' => $impersonator->impersonating($request),
'motivationalMessage' => $request->routeIs('student.dashboard')
? (new MotivationalMessageService($request->user()))->generate()
: null,
Expand Down
2 changes: 1 addition & 1 deletion app/Services/UserInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function students(): ?array
protected function navigation(): array
{
return [
['name' => 'Dashboard', 'href' => route('parent.dashboard'), 'icon' => 'home-icon', 'current' => request()->routeIs('dashboard')],
['name' => 'Dashboard', 'href' => route('parent.dashboard'), 'icon' => 'home-icon', 'current' => request()->routeIs('parent.dashboard')],
['name' => 'Students', 'href' => route('parent.users.index'), 'icon' => 'users-icon', 'current' => request()->routeIs('parent.users.*')],
['name' => 'Feedback', 'href' => route('feedback.index'), 'icon' => 'chat-bubble-left-ellipsis', 'current' => request()->routeIs('feedback.*')],
];
Expand Down
33 changes: 33 additions & 0 deletions database/migrations/2024_02_13_024745_create_courses_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('courses', static function (Blueprint $table) {
$table->id();

$table->string('title');
$table->longText('description');
$table->integer('length_in_weeks');

$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('courses');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('course_prompts', static function (Blueprint $table) {
$table->id();

$table->foreignId('course_id')->constrained()->cascadeOnDelete();
$table->foreignId('prompt_id')->constrained()->cascadeOnDelete();

$table->integer('week_number');

$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('course_prompts');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('user_courses', static function (Blueprint $table) {
$table->id();

$table->foreignId('course_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();

$table->timestamp('started_at')->nullable();
$table->timestamp('completed_at')->nullable();

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user_courses');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('categories_grades', static function (Blueprint $table) {
$table->id();

$table->string('category');
$table->string('sub_category');
$table->integer('grade');

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('categories_grades');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('course_trivia', static function (Blueprint $table) {
$table->id();

$table->foreignId('course_id')->constrained()->cascadeOnDelete();

$table->string('title');
$table->integer('week');

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('course_trivia');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('course_trivia_questions', static function (Blueprint $table) {
$table->id();

$table->foreignId('course_trivia_id')->constrained('course_trivia')->cascadeOnDelete();

$table->string('question');

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('course_trivia_questions');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('course_trivia_question_answers', static function (Blueprint $table) {
$table->id();

$table->foreignId('course_trivia_id')->constrained('course_trivia')->cascadeOnDelete();

$table->string('answer');
$table->boolean('correct')->default(0);

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('course_trivia_question_answers');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users_course_trivia', function (Blueprint $table) {
$table->id();

$table->foreignId('course_trivia_id')->constrained('course_trivia')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();

$table->float('score');

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users_course_trivia');
}
};
Loading

0 comments on commit b830219

Please sign in to comment.