diff --git a/docker/database/start-scripts/0-init.sql b/docker/database/start-scripts/0-init.sql index e18c9fac..9265fc48 100644 --- a/docker/database/start-scripts/0-init.sql +++ b/docker/database/start-scripts/0-init.sql @@ -1,16 +1,17 @@ create table points ( id int auto_increment primary key, - latitude decimal, - longitude decimal + latitude decimal(10, 7) not null, + longitude decimal(10, 7) not null, + constraint UC_Point unique (latitude, longitude) ); 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 9c3ca232..ac8a4070 100644 --- a/docker/database/start-scripts/1-seed.sql +++ b/docker/database/start-scripts/1-seed.sql @@ -32,4 +32,16 @@ INSERT INTO task_types (name) VALUES 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.'); \ No newline at end of file +('C', 'Poda de mantenimiento en árbol tipo C, perenne, de p.c. entre 41/60 cm.'); + +-- Insert sample points +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/Point.php b/src/app/Models/Point.php new file mode 100644 index 00000000..a586a6e3 --- /dev/null +++ b/src/app/Models/Point.php @@ -0,0 +1,25 @@ +id = $data['id']; + $point->latitude = $data['latitude']; + $point->longitude = $data['longitude']; + return $point; + } +} 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