From 589a4d1d0633469f5004ff87f66f0542406f1f9f Mon Sep 17 00:00:00 2001 From: 0x1026 <69076992+0x1026@users.noreply.github.com> Date: Sat, 16 Nov 2024 22:08:54 +0100 Subject: [PATCH] feat(zone): add Zone MVC --- docker/database/start-scripts/0-init.sql | 10 +++---- docker/database/start-scripts/1-seed.sql | 6 +++++ src/app/Controllers/ZoneController.php | 25 ++++++++++++++++++ src/app/Models/Zone.php | 33 ++++++++++++++++++++++++ src/app/Views/Zone.php | 25 ++++++++++++++++++ 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 src/app/Controllers/ZoneController.php create mode 100644 src/app/Models/Zone.php create mode 100644 src/app/Views/Zone.php diff --git a/docker/database/start-scripts/0-init.sql b/docker/database/start-scripts/0-init.sql index 760c20e1..9265fc48 100644 --- a/docker/database/start-scripts/0-init.sql +++ b/docker/database/start-scripts/0-init.sql @@ -7,11 +7,11 @@ create table points ( create table zones ( id int auto_increment primary key, - name varchar(255), - quantity int, - postal_code int, - point_id int, - foreign key (point_id) references points(id) + name varchar(255) not null, + postal_code int not null, + point_id int not null unique, + foreign key (point_id) references points(id), + constraint UC_Zone unique (name, postal_code) ); create table tree_types ( diff --git a/docker/database/start-scripts/1-seed.sql b/docker/database/start-scripts/1-seed.sql index 6d903f67..ac8a4070 100644 --- a/docker/database/start-scripts/1-seed.sql +++ b/docker/database/start-scripts/1-seed.sql @@ -39,3 +39,9 @@ INSERT INTO points (latitude, longitude) VALUES (40.416775, -3.703790), (40.416776, -3.703795), (40.416777, -3.703800); + +-- Insert sample zones +INSERT INTO zones (name, postal_code, point_id) VALUES +('Zona 1', '46001', 1), +('Zona 2', '46002', 2), +('Zona 3', '46003', 3); diff --git a/src/app/Controllers/ZoneController.php b/src/app/Controllers/ZoneController.php new file mode 100644 index 00000000..e21c831a --- /dev/null +++ b/src/app/Controllers/ZoneController.php @@ -0,0 +1,25 @@ + "Zone", + "title" => "Zones", + "layout" => "MainLayout", + "data" => ["zones" => $zones] + ]); + } + + public function post() {} + public function put() {} + public function delete() {} +} diff --git a/src/app/Models/Zone.php b/src/app/Models/Zone.php new file mode 100644 index 00000000..eee08bcc --- /dev/null +++ b/src/app/Models/Zone.php @@ -0,0 +1,33 @@ +id = $data['id']; + $zone->name = $data['name']; + $zone->postal_code = $data['postal_code']; + $zone->point_id = $data['point_id']; + return $zone; + } + + // Fetch the zone's point + public function point() + { + return $this->belongsTo(Point::class, 'point_id', 'id'); + } +} diff --git a/src/app/Views/Zone.php b/src/app/Views/Zone.php new file mode 100644 index 00000000..fbc4e8f7 --- /dev/null +++ b/src/app/Views/Zone.php @@ -0,0 +1,25 @@ +
+ + + + + + + + + + + + + + + + + + + + + + +
IDNamePostal CodeLatitudeLongitude
getId(); ?>name; ?>postal_code; ?>point()->latitude; ?>point()->longitude; ?>
+
\ No newline at end of file