Compare commits

...

2 Commits

Author SHA1 Message Date
ea3afa2507 Updated: README.md added diagrams
All checks were successful
Build and Deploy Zola Website / build_and_deploy (push) Successful in 13s
2025-01-26 23:16:00 +01:00
a5f99788fc Added: Delete vehicle 2025-01-26 23:01:35 +01:00
9 changed files with 76 additions and 5 deletions

BIN
.screenshots/class.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
.screenshots/dlm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

BIN
.screenshots/usecase.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -53,5 +53,13 @@ php -S localhost:8000 -t ./public
4. Track your fuel consumption and spending through the dashboard. 4. Track your fuel consumption and spending through the dashboard.
5. View detailed stats and graphs to analyze your driving habits. 5. View detailed stats and graphs to analyze your driving habits.
## Use case diagram
![](.screenshots/usecase.png)
## Data logical model
![](.screenshots/dlm.png)
## Class diagram
![](.screenshots/class.png)
## License ## License
This project is licensed under GPL3.0 and later. More information is available in the `LICENSE` file. This project is licensed under GPL3.0 and later. More information is available in the `LICENSE` file.

23
TODO.md
View File

@ -12,7 +12,7 @@
- [ ] remove/edit fuel record - [ ] remove/edit fuel record
## Until release ## Until release
- [ ] Sync offline data from locale storage - [x] Sync offline data from locale storage
- [ ] Include kilometer state of an car - [ ] Include kilometer state of an car
- [ ] More charts - [ ] More charts
- [ ] Average fuel conusption - [ ] Average fuel conusption
@ -21,3 +21,24 @@
- [ ] Average fuel conusption in last 30 days - [ ] Average fuel conusption in last 30 days
- [ ] Kilometer state in last 30 days` - [ ] Kilometer state in last 30 days`
- [ ] Offline navigation between dashboard and offline form - [ ] Offline navigation between dashboard and offline form
## What has to be done
- [x] Vehicle delete
- [ ] intro tutorial when no car exist or just dont show anything
- [ ] change/set default car
- [ ] hide errors
## Nice to have
- [ ] specific car view - charts, fuel records
- [ ] remove/edit fuel record
- [ ] Include kilometer state of an car
- [ ] More charts
- [ ] Average fuel conusption
- [ ] Kilometer state
- [ ] More cards
- [ ] Average fuel conusption in last 30 days
- [ ] Kilometer state in last 30 days`
- [ ] Offline navigation between dashboard and offline form
- [ ] Fix vehicle deletion - wrong redirect

View File

@ -56,7 +56,23 @@ class VehicleController extends Controller {
} }
public function delete() { public function delete() {
// TODO: Delete vehicle (to be implemented later) if(!$_SERVER['REQUEST_METHOD'] === 'POST') {
echo "Wrong method";
return;
}
// TODO: Validate the request
$vehicle_id = $_POST['vehicle_id'];
$vehicle = new Vehicle();
$result = $vehicle->delete($vehicle_id, $_SESSION['user']['id']);
if($result != true) {
echo "Something went wrong";
return;
}
$this->view('vehicles/index', ['title' => 'Vehicles', 'vehicles' => $vehicles]);
} }
public function api_get() { public function api_get() {

View File

@ -60,4 +60,28 @@ class Vehicle {
return $result->fetch_assoc(); return $result->fetch_assoc();
} }
public function delete($vehicle_id, $user_id) {
try {
$stmt = $this->db->prepare("SELECT id FROM vehicles WHERE id = ? AND user_id = ?");
$stmt->bind_param("ii", $vehicle_id, $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
return "Error: Unauthorized action or vehicle not found.";
}
$stmt = $this->db->prepare("DELETE FROM vehicles WHERE id = ?");
$stmt->bind_param("i", $vehicle_id);
if ($stmt->execute()) {
return true;
} else {
return "Error: " . $stmt->error;
}
} catch (mysqli_sql_exception $e) {
return $e->getMessage();
}
}
} }

View File

@ -14,8 +14,10 @@
<p><?= htmlspecialchars($vehicle['fuel_type']) ?></p> <p><?= htmlspecialchars($vehicle['fuel_type']) ?></p>
<p><?= htmlspecialchars($vehicle['note'] ?? "") ?></p> <p><?= htmlspecialchars($vehicle['note'] ?? "") ?></p>
<div class="actions"> <div class="actions">
<a href="/vehicles/edit?id=<?= $vehicle['id'] ?>">Edit</a> <form method="POST" action="/vehicles/delete">
<a href="/vehicles/delete?id=<?= $vehicle['id'] ?>" onclick="return confirm('Are you sure you want to delete this habit?')">Delete</a> <input type="number" name="vehicle_id" value="<?= $vehicle['id'] ?>" style="display: none">
<input type="submit" value="Delete vehicle" class="btn-danger">
</form>
</div> </div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>

View File

@ -46,7 +46,7 @@ $router->group('/vehicles', ['RequireAuth'], function ($router) {
$router->add('', 'VehicleController@index'); $router->add('', 'VehicleController@index');
$router->add('/create', 'VehicleController@create'); $router->add('/create', 'VehicleController@create');
$router->add('/edit/{id}', 'VehicleController@edit'); $router->add('/edit/{id}', 'VehicleController@edit');
$router->add('/delete/{id}', 'VehicleController@delete'); $router->add('/delete', 'VehicleController@delete');
}); });
$router->group('/refuel', ['RequireAuth'], function ($router) { $router->group('/refuel', ['RequireAuth'], function ($router) {