Skip to content

onsaurav/QuartzNET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuartzNET Notifications API

A robust ASP.NET Core Web API demonstrating how to integrate Quartz.NET for scheduling background jobs, alongside Entity Framework Core and a SQLite database to manage a notification system.

The application automatically generates a "Scheduled Job Fired" notification every minute in the background using Quartz, and provides a full RESTful API to retrieve, manage, and delete these notifications.

🚀 Key Features

  • Background Jobs with Quartz.NET: Implements a NotificationJob that runs on a Cron schedule (every 1 minute) to automatically generate notifications.
  • RESTful Notification API: Full CRUD operations for managing notifications (Create, Read, Update, Delete) with filtering and convenience endpoints (like Mark As Read).
  • Lightweight Database: Uses SQLite via Entity Framework Core, meaning no heavy database setup is required. The database (notifications.db) is automatically created and migrated on startup.
  • Modern API Documentation: Uses Scalar API Reference for clean, modern OpenAPI documentation.

🛠️ Technology Stack

  • Framework: .NET / ASP.NET Core
  • Job Scheduling: Quartz.NET
  • ORM: Entity Framework Core
  • Database: SQLite
  • API Documentation: Scalar (Scalar.AspNetCore)

📂 Project Structure

  • Controllers/ - Contains the NotificationsController exposing the REST API endpoints.
  • Models/ - Data models (e.g., Notification.cs) representing the database schema.
  • DTOs/ - Data Transfer Objects used for creating and updating notifications.
  • Jobs/ - Contains the Quartz.NET background jobs (e.g., NotificationJob.cs).
  • Data/ - Contains the Entity Framework AppDbContext.

⚙️ Getting Started

Prerequisites

  • .NET SDK (Version 8.0 or later recommended)

Running the Application

  1. Clone or download the repository.
  2. Navigate to the QuartzNET project directory.
  3. Run the application using the .NET CLI:
    dotnet run
  4. The application will automatically create the notifications.db SQLite database if it doesn't exist.
  5. Open your browser and navigate to the Scalar API documentation (usually at https://localhost:<port>/scalar/v1) to explore and test the endpoints.

📡 API Endpoints

The API provides the following endpoints under /api/notifications:

Method Endpoint Description
GET /api/notifications Get all notifications. Supports optional ?userId={id} and ?isRead={bool} filters.
GET /api/notifications/{id} Get a specific notification by ID.
POST /api/notifications Create a new notification manually.
PUT /api/notifications/{id} Update an existing notification.
PATCH /api/notifications/{id}/read Convenience endpoint to mark a specific notification as read.
DELETE /api/notifications/{id} Delete a specific notification by ID.
DELETE /api/notifications?userId={id} Delete all notifications for a specific user.

⏱️ Background Job Details

The NotificationJob is configured in Program.cs and uses a Cron schedule expression: 0 0/1 * * * ? (runs every 1 minute).

Each time the job executes, it writes a new notification to the database indicating that the scheduled job fired, including the exact UTC timestamp. This job uses the [DisallowConcurrentExecution] attribute to prevent multiple instances of the job running simultaneously if execution takes longer than the scheduled interval.

About

A robust ASP.NET Core REST API that uses Quartz.NET for scheduled background jobs and Entity Framework Core (SQLite) to automatically generate and manage system notifications.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors