add composer and scaffold out the braindump function

This commit is contained in:
Joren de Graaf
2026-08-13 14:19:26 +02:00
parent 39b3d91e5d
commit 5da8c9f57e
16 changed files with 433 additions and 21 deletions
Generated
+3 -3
View File
@@ -6260,7 +6260,7 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {},
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
@@ -6268,6 +6268,6 @@
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*" "ext-iconv": "*"
}, },
"platform-dev": [], "platform-dev": {},
"plugin-api-version": "2.6.0" "plugin-api-version": "2.9.0"
} }
Executable
BIN
View File
Binary file not shown.
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260812162507 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260812163058 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE exercise_session (id INT AUTO_INCREMENT NOT NULL, type VARCHAR(255) DEFAULT NULL, started_at DATETIME NOT NULL, ended_at DATETIME DEFAULT NULL, duration INT NOT NULL, distance NUMERIC(10, 0) NOT NULL, calories INT NOT NULL, notes LONGTEXT DEFAULT NULL, source VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci`');
$this->addSql('ALTER TABLE settings CHANGE latitude latitude VARCHAR(255) DEFAULT NULL, CHANGE longitude longitude VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE settings RENAME INDEX uniq_settings_user TO UNIQ_E545A0C5A76ED395');
$this->addSql('ALTER TABLE task CHANGE is_outdoor is_outdoor TINYINT NOT NULL, CHANGE weather_profile weather_profile VARCHAR(30) NOT NULL');
$this->addSql('ALTER TABLE weather_forecast RENAME INDEX idx_forecast_settings TO IDX_CB36DFBF59949888');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE exercise_session');
$this->addSql('ALTER TABLE settings CHANGE latitude latitude NUMERIC(10, 7) DEFAULT NULL, CHANGE longitude longitude NUMERIC(10, 7) DEFAULT NULL');
$this->addSql('ALTER TABLE settings RENAME INDEX uniq_e545a0c5a76ed395 TO UNIQ_SETTINGS_USER');
$this->addSql('ALTER TABLE task CHANGE is_outdoor is_outdoor TINYINT DEFAULT 0 NOT NULL, CHANGE weather_profile weather_profile VARCHAR(30) DEFAULT \'none\' NOT NULL');
$this->addSql('ALTER TABLE weather_forecast RENAME INDEX idx_cb36dfbf59949888 TO IDX_FORECAST_SETTINGS');
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class BraindumpController extends AbstractController
{
#[Route('/braindump', name: 'app_braindump')]
public function index(): Response
{
return $this->render('braindump/index.html.twig');
}
#[Route('/braindump/dump', name: 'app_braindump_dump', methods: ['POST'])]
public function dump(
Request $request,
HttpClientInterface $client
): Response {
if (!$this->isCsrfTokenValid(
'braindump_dump',
$request->getPayload()->getString('_token')
)) {
throw $this->createAccessDeniedException('Invalid CSRF token.');
}
$brainDump = $request->getPayload()->getString('brain_dump');
$response = $client->request('POST', 'http://192.168.1.238:11434/api/generate', [
'json' => [
'model' => 'qwen3:4b',
'prompt' => $brainDump,
'stream' => false,
],
]);
$data = $response->toArray();
return $this->render('braindump/_task_result.html.twig', [
'response' => $data['response'] ?? 'No response received.',
]);
}
}
@@ -1,18 +0,0 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class ExcerciseSessionController extends AbstractController
{
#[Route('/excercise', name: 'app_excercise_session')]
public function index(): Response
{
return $this->render('excercise_session/index.html.twig', [
'controller_name' => 'ExcerciseSessionController',
]);
}
}
@@ -0,0 +1,81 @@
<?php
namespace App\Controller;
use App\Entity\ExerciseSession;
use App\Form\ExerciseSessionType;
use App\Repository\ExerciseSessionRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/workout')]
final class ExerciseSessionController extends AbstractController
{
#[Route(name: 'app_exercise_session_index', methods: ['GET'])]
public function index(ExerciseSessionRepository $exerciseSessionRepository): Response
{
return $this->render('exercise_session/index.html.twig', [
'exercise_sessions' => $exerciseSessionRepository->findAll(),
]);
}
#[Route('/new', name: 'app_exercise_session_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$exerciseSession = new ExerciseSession();
$form = $this->createForm(ExerciseSessionType::class, $exerciseSession);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($exerciseSession);
$entityManager->flush();
return $this->redirectToRoute('app_exercise_session_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('exercise_session/new.html.twig', [
'exercise_session' => $exerciseSession,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_exercise_session_show', methods: ['GET'])]
public function show(ExerciseSession $exerciseSession): Response
{
return $this->render('exercise_session/show.html.twig', [
'exercise_session' => $exerciseSession,
]);
}
#[Route('/{id}/edit', name: 'app_exercise_session_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, ExerciseSession $exerciseSession, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(ExerciseSessionType::class, $exerciseSession);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_exercise_session_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('exercise_session/edit.html.twig', [
'exercise_session' => $exerciseSession,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_exercise_session_delete', methods: ['POST'])]
public function delete(Request $request, ExerciseSession $exerciseSession, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$exerciseSession->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($exerciseSession);
$entityManager->flush();
}
return $this->redirectToRoute('app_exercise_session_index', [], Response::HTTP_SEE_OTHER);
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Form;
use App\Entity\ExerciseSession;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ExerciseSessionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('type')
->add('startedAt', null, [
'widget' => 'single_text',
])
->add('endedAt', null, [
'widget' => 'single_text',
])
->add('duration')
->add('distance')
->add('calories')
->add('notes')
->add('source')
->add('createdAt', null, [
'widget' => 'single_text',
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => ExerciseSession::class,
]);
}
}
@@ -0,0 +1,5 @@
<div>
<h2>Ollama says:</h2>
<p>{{ response|nl2br }}</p>
</div>
+47
View File
@@ -0,0 +1,47 @@
{% extends 'base.html.twig' %}
{% block title %}Brain Dump{% endblock %}
{% block body %}
<h1>Brain Dump</h1>
<form
method="post"
action="{{ path('app_braindump_dump') }}"
hx-post="{{ path('app_braindump_dump') }}"
hx-target="#tasks-result"
hx-swap="innerHTML"
>
<input
type="hidden"
name="_token"
value="{{ csrf_token('braindump_dump') }}"
>
<div>
<label for="brain_dump">
What's on your mind?
</label>
<textarea
id="brain_dump"
name="brain_dump"
rows="8"
placeholder="Dump everything that's on your mind..."
required
></textarea>
</div>
<button type="submit">
✨ Suggest tasks
</button>
</form>
<div id="tasks-result">
{# HTMX will put the proposed tasks here #}
</div>
{% endblock %}
@@ -0,0 +1,4 @@
<form method="post" action="{{ path('app_exercise_session_delete', {'id': exercise_session.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ exercise_session.id) }}">
<button class="btn">Delete</button>
</form>
@@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}
+13
View File
@@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}Edit ExerciseSession{% endblock %}
{% block body %}
<h1>Edit ExerciseSession</h1>
{{ include('exercise_session/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('app_exercise_session_index') }}">back to list</a>
{{ include('exercise_session/_delete_form.html.twig') }}
{% endblock %}
@@ -0,0 +1,51 @@
{% extends 'base.html.twig' %}
{% block title %}ExerciseSession index{% endblock %}
{% block body %}
<h1>ExerciseSession index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Type</th>
<th>StartedAt</th>
<th>EndedAt</th>
<th>Duration</th>
<th>Distance</th>
<th>Calories</th>
<th>Notes</th>
<th>Source</th>
<th>CreatedAt</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for exercise_session in exercise_sessions %}
<tr>
<td>{{ exercise_session.id }}</td>
<td>{{ exercise_session.type }}</td>
<td>{{ exercise_session.startedAt ? exercise_session.startedAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ exercise_session.endedAt ? exercise_session.endedAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ exercise_session.duration }}</td>
<td>{{ exercise_session.distance }}</td>
<td>{{ exercise_session.calories }}</td>
<td>{{ exercise_session.notes }}</td>
<td>{{ exercise_session.source }}</td>
<td>{{ exercise_session.createdAt ? exercise_session.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td>
<a href="{{ path('app_exercise_session_show', {'id': exercise_session.id}) }}">show</a>
<a href="{{ path('app_exercise_session_edit', {'id': exercise_session.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="11">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('app_exercise_session_new') }}">Create new</a>
{% endblock %}
+11
View File
@@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New ExerciseSession{% endblock %}
{% block body %}
<h1>Create new ExerciseSession</h1>
{{ include('exercise_session/_form.html.twig') }}
<a href="{{ path('app_exercise_session_index') }}">back to list</a>
{% endblock %}
+58
View File
@@ -0,0 +1,58 @@
{% extends 'base.html.twig' %}
{% block title %}ExerciseSession{% endblock %}
{% block body %}
<h1>ExerciseSession</h1>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<td>{{ exercise_session.id }}</td>
</tr>
<tr>
<th>Type</th>
<td>{{ exercise_session.type }}</td>
</tr>
<tr>
<th>StartedAt</th>
<td>{{ exercise_session.startedAt ? exercise_session.startedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
<tr>
<th>EndedAt</th>
<td>{{ exercise_session.endedAt ? exercise_session.endedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
<tr>
<th>Duration</th>
<td>{{ exercise_session.duration }}</td>
</tr>
<tr>
<th>Distance</th>
<td>{{ exercise_session.distance }}</td>
</tr>
<tr>
<th>Calories</th>
<td>{{ exercise_session.calories }}</td>
</tr>
<tr>
<th>Notes</th>
<td>{{ exercise_session.notes }}</td>
</tr>
<tr>
<th>Source</th>
<td>{{ exercise_session.source }}</td>
</tr>
<tr>
<th>CreatedAt</th>
<td>{{ exercise_session.createdAt ? exercise_session.createdAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
</tbody>
</table>
<a href="{{ path('app_exercise_session_index') }}">back to list</a>
<a href="{{ path('app_exercise_session_edit', {'id': exercise_session.id}) }}">edit</a>
{{ include('exercise_session/_delete_form.html.twig') }}
{% endblock %}