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 @@ +
ID | +Name | +Postal Code | +Latitude | +Longitude | + +
---|---|---|---|---|
getId(); ?> | +name; ?> | +postal_code; ?> | +point()->latitude; ?> | +point()->longitude; ?> | +