Skip to content

Commit

Permalink
feat(pruning-type): add PruningType (#66)
Browse files Browse the repository at this point in the history
Introduce a new PruningType MVC for managing pruning types. Create the
pruning_types table to meet the requirements, ensuring proper data
handling and integrity.
  • Loading branch information
0x1026 authored Nov 16, 2024
2 parents 732fee1 + edd91db commit 12463b2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docker/database/start-scripts/0-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ create table sensor_history (
created_at timestamp default current_timestamp,
foreign key (sensor_id) references sensors(id)
);

create table pruning_types (
id int auto_increment primary key,
name varchar(20) unique,
description varchar(255)
);

create table task_types (
id int auto_increment primary key,
name varchar(255)
)
name varchar(255) unique
);
6 changes: 6 additions & 0 deletions docker/database/start-scripts/1-seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ INSERT INTO task_types (name) VALUES
('Abono arbustos'),
('Podar setos'),
('Abono setos');

-- Insert sample pruning types
INSERT INTO pruning_types (name, description) VALUES
('A', 'Poda de mantenimiento en árbol tipo A, caduco, de p.c. entre 41/80 cm.'),
('B', 'Poda de mantenimiento en árbol tipo B, caduco, de p.c. mayor de 81 cm.'),
('C', 'Poda de mantenimiento en árbol tipo C, perenne, de p.c. entre 41/60 cm.');
25 changes: 25 additions & 0 deletions src/app/Controllers/PruningTypeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Controllers;

use App\Core\BaseController;
use App\Core\View;
use App\Models\PruningType;

class PruningTypeController implements BaseController
{
public function get()
{
$pruning_types = PruningType::findAll();
View::render([
"view" => "PruningType",
"title" => "Pruning Types",
"layout" => "MainLayout",
"data" => ["pruning_types" => $pruning_types]
]);
}

public function post() {}
public function put() {}
public function delete() {}
}
26 changes: 26 additions & 0 deletions src/app/Models/PruningType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Models;

use App\Core\BaseModel;
use App\Core\Database;

class PruningType extends BaseModel
{
public string $name;
public ?string $description;

protected static function getTableName()
{
return 'pruning_types';
}

protected static function mapDataToModel($data)
{
$pruning_type = new PruningType();
$pruning_type->id = $data['id'];
$pruning_type->name = $data['name'];
$pruning_type->description = $data['description'];
return $pruning_type;
}
}
21 changes: 21 additions & 0 deletions src/app/Views/PruningType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="overflow-x-auto">
<table class="min-w-full bg-white border border-gray-300 rounded-lg shadow-md">
<thead>
<tr class="bg-gray-100 text-left">
<th class="px-4 py-2 border-b">ID</th>
<th class="px-4 py-2 border-b">Name</th>
<th class="px-4 py-2 border-b">Description</th>

</tr>
</thead>
<tbody>
<?php foreach ($pruning_types as $pruning_type): ?>
<tr class="hover:bg-gray-50">
<td class="px-4 py-2 border-b"><?php echo $pruning_type->getId(); ?></td>
<td class="px-4 py-2 border-b"><?php echo $pruning_type->name; ?></td>
<td class="px-4 py-2 border-b"><?php echo $pruning_type->description; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

0 comments on commit 12463b2

Please sign in to comment.