From f307c0933a1a4557716c349df701303f6aa9f6b9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Sat, 26 Apr 2025 09:16:38 -0600 Subject: [PATCH] add delete endpoint --- Controllers/APIController.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Controllers/APIController.cs b/Controllers/APIController.cs index 6ba0072..f56c841 100644 --- a/Controllers/APIController.cs +++ b/Controllers/APIController.cs @@ -1681,6 +1681,29 @@ namespace CarCareTracker.Controllers return Json(OperationResponse.Failed(ex.Message)); } } + [HttpDelete] + [Route("/api/vehicle/reminders/delete")] + public IActionResult DeleteReminderRecord(int id) + { + var existingRecord = _reminderRecordDataAccess.GetReminderRecordById(id); + if (existingRecord == null || existingRecord.Id == default) + { + Response.StatusCode = 400; + return Json(OperationResponse.Failed("Invalid Record Id")); + } + //security check. + if (!_userLogic.UserCanEditVehicle(GetUserID(), existingRecord.VehicleId)) + { + Response.StatusCode = 401; + return Json(OperationResponse.Failed("Access Denied, you don't have access to this vehicle.")); + } + var result = _reminderRecordDataAccess.DeleteReminderRecordById(existingRecord.Id); + if (result) + { + StaticHelper.NotifyAsync(_config.GetWebHookUrl(), WebHookPayload.FromReminderRecord(existingRecord, "reminderrecord.delete.api", User.Identity.Name)); + } + return Json(OperationResponse.Conditional(result, "Reminder Record Deleted")); + } [HttpGet] [Route("/api/calendar")] public IActionResult Calendar()