diff --git a/src/Controllers/WishlistController.php b/src/Controllers/WishlistController.php index e5bc4b9a09253422315d4814751ea976b8735ec2..fda919cefa9e6d19f91de8255ac3a2fa31bf24d5 100644 --- a/src/Controllers/WishlistController.php +++ b/src/Controllers/WishlistController.php @@ -45,7 +45,6 @@ class WishlistController extends Controller $userId = Request::getUser()->user_id; $wishlists = Wishlists::where(["user_id" => $userId]); - print_r($wishlists); $dormIds = array_reduce( $wishlists, function ($carry, $wishlist) { diff --git a/src/Core/Application.php b/src/Core/Application.php index f969a3003c61fdbebaf5d3196f2c79317978b083..2d721263b462cfbc38671d5043bd21b9c2b4caaa 100644 --- a/src/Core/Application.php +++ b/src/Core/Application.php @@ -48,6 +48,7 @@ class Application $this->router->methods(["GET", "POST"], "/dorms/create", [AdminOnly::class], DormController::class, 'create'); $this->router->methods(["GET", "POST"], "/dorms/{dormId}", [AuthRequired::class], DormController::class, 'view'); + $this->router->delete("/dorms/{dormId}", [AuthRequired::class], DormController::class, 'delete'); $this->router->methods(["GET", "POST"], "/dorms/{dormId}/media", [AdminOnly::class], DormController::class, 'media'); $this->router->methods(["GET", "POST"], "/dorms/{dormId}/edit", [AdminOnly::class], DormController::class, 'edit'); $this->router->methods(["GET", "POST"], "/dorms/{dormId}/reviews", [AuthRequired::class], ReviewController::class, 'getAllByDormId'); diff --git a/src/Models/Wishlists.php b/src/Models/Wishlists.php index 76c90da82d5fc5a34837075f526ec7b76745c276..655e2cb03b40b18bb3ea9994acfc0b2cfad445ad 100644 --- a/src/Models/Wishlists.php +++ b/src/Models/Wishlists.php @@ -9,4 +9,16 @@ class Wishlists extends BaseModel public string $created_at; protected static string $table = 'wishlists'; protected static $primaryKey = ['user_id', 'dorm_id']; + + public function delete() + { + $sql = "DELETE FROM " . static::$table . " WHERE user_id = :user_id AND dorm_id = :dorm_id"; + + $stmt = self::$db->prepare($sql); + + $stmt->bindValue(":user_id", $this->user_id); + $stmt->bindValue(":dorm_id", $this->dorm_id); + + $stmt->execute(); + } }