diff --git a/src/Controllers/DormController.php b/src/Controllers/DormController.php index 86dcbd81da8587eb9b45e3933c52eec692ca40e0..f6ee0d2e33559de3daa5d6bb604a4468f7ec78f5 100644 --- a/src/Controllers/DormController.php +++ b/src/Controllers/DormController.php @@ -175,7 +175,7 @@ class DormController extends Controller public function delete($params) { $dormId = $params["dormId"]; - $dorm = Dorm::deleteById($dormId); + Dorm::deleteById($dormId); Response::redirect("/"); } diff --git a/src/Controllers/ReviewController.php b/src/Controllers/ReviewController.php index dde38bbe933b399f356a9bf00f8b0eeff7023bff..0233f994eee86dad1a1bc8b8ab5887ccf56626ca 100644 --- a/src/Controllers/ReviewController.php +++ b/src/Controllers/ReviewController.php @@ -108,7 +108,7 @@ class ReviewController extends Controller ]); } - public function delete($params) + public function deleteById($params) { $dormId = $params["dormId"]; diff --git a/src/Controllers/WishlistController.php b/src/Controllers/WishlistController.php index fda919cefa9e6d19f91de8255ac3a2fa31bf24d5..b057f9b3e8ac161e6c18a73338bcadee4ae0493a 100644 --- a/src/Controllers/WishlistController.php +++ b/src/Controllers/WishlistController.php @@ -67,16 +67,13 @@ class WishlistController extends Controller public function add($params) { $userId = Request::getUser()->user_id; - // $form = new Validation([ - // [new Field('dorm_id'), [new Number()]], - // ]); $dormId = $params["dormId"]; if (Request::getMethod() === "GET") { - $wishlist = Wishlists::toModel(["dorm_id" => $dormId, "user_id" => $userId]); - // $wishlist->user_id = $userId; - // var_dump($wishlist); - $wishlist->save(); + if (empty(Wishlists::where(["dorm_id"=>$dormId, "user_id"=>$userId]))) { + $wishlist = Wishlists::toModel(["dorm_id" => $dormId, "user_id" => $userId]); + $wishlist->save(); + } Toast::success("Kos berhasil ditambahkan ke wishlist", true); Response::redirect("/dorms/{$dormId}"); } diff --git a/src/Core/Application.php b/src/Core/Application.php index e643dc4495b795721616e486726281f5888d94b3..463ff2d6ef9f1cc11ebb9851ba956601158d426d 100644 --- a/src/Core/Application.php +++ b/src/Core/Application.php @@ -59,7 +59,7 @@ class Application $this->router->methods(["GET", "POST"], "/account/editPassword", [AuthRequired::class], UserController::class, 'editPassword'); $this->router->methods(["GET", "POST"], "/reviews/{reviewId}", [AuthRequired::class], ReviewController::class, 'edit'); - $this->router->delete("/dorms/{dormId}", [AuthRequired::class], ReviewController::class, 'delete'); + $this->router->delete("/dorms/{dormId}/delete-review", [AuthRequired::class], ReviewController::class, 'deleteById'); $this->router->methods(["GET"], "/wishlist", [AuthRequired::class], WishlistController::class, 'index'); $this->router->methods(["GET"], "/dorms/{dormId}/add-to-wishlist", [AuthRequired::class], WishlistController::class, 'add'); diff --git a/src/Models/Dorm.php b/src/Models/Dorm.php index 6e846df64fa29ce5a163dbe3e17f3a906f7fd395..509ebfcfb7483f57f09dfbe8db78262add352d99 100644 --- a/src/Models/Dorm.php +++ b/src/Models/Dorm.php @@ -78,6 +78,11 @@ class Dorm extends BaseModel public static function getInIds(array $ids) { + if (count($ids) == 0) { + $dorms = array(); + $medias = array(); + return ["dorms" => $dorms, "medias" => $medias]; + } $in = str_repeat('?,', count($ids) - 1) . '?'; $stmt = self::$db->prepare("SELECT * FROM dorms WHERE dorm_id IN ($in)"); $stmt->execute($ids); diff --git a/src/Views/dorm/view.php b/src/Views/dorm/view.php index a5f60b6a4d3b9c42d4687476aaa33c90c4a26d6f..6d12e5dfe972a38518a00d63b8fd75fd43741897 100644 --- a/src/Views/dorm/view.php +++ b/src/Views/dorm/view.php @@ -79,7 +79,7 @@ use app\Models\User; <a href="/dorms/<?= $dorm->dorm_id ?>/edit" class="btn btn-primary btn-edit-kos">Edit Kos</a> </div> <form method="POST"> - <button type="button" class="btn btn-danger dialog-btn action-btn" + <button type="button" class="btn btn-danger dialog-btn action-btn delete-dorm" data-dialog="delete-<?= $dorm->dorm_id ?>"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" width="14" height="14"> <path stroke-linecap="round" stroke-linejoin="round" @@ -91,7 +91,7 @@ use app\Models\User; <input type="hidden" name="_method" value="DELETE" /> <div class="dialog-wrapper delete-<?= $dorm->dorm_id ?>"> <div class="dialog-content"> - <h4 class="confirm-title">Apakah Anda yakin ingin menghapus dorm?</h4> + <h4 class="confirm-title">Apakah Anda yakin ingin menghapus kos?</h4> <div class="confirm-action"> <button type="button" class="btn btn-outlined dialog-btn" data-dialog="delete-<?= $dorm->dorm_id ?>">Batal</button> @@ -142,7 +142,7 @@ use app\Models\User; </svg> </a> <? endif ?> - <form method="POST"> + <form method="POST" action="/dorms/<?= $dorm->dorm_id ?>/delete-review"> <button type="button" class="btn btn-danger dialog-btn action-btn" data-dialog="delete-<?= $review->review_id ?>"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" width="20" height="20"> diff --git a/src/public/static/styles/dorm-view.css b/src/public/static/styles/dorm-view.css index 170a54de79bbcdd5da05b0528f3ba8069ed49ebc..744bec591a2eb01e1c102fc38b67758c15683e0c 100644 --- a/src/public/static/styles/dorm-view.css +++ b/src/public/static/styles/dorm-view.css @@ -79,7 +79,8 @@ } .add-review, -.edit-admin { +.edit-admin, +.delete-dorm { margin-top: 20px; margin-bottom: 20px; }