An ASP.NET Core 8 Web API for managing a theater: halls, spectacles, tickets, users, and admin operations. Built with Entity Framework Core (PostgreSQL), secured with JWT, and documented via Swagger.
- Authentication & Authorization 🔐: JWT-based auth with role-based endpoints (admin/user)
- Entity Framework Core 🐘: PostgreSQL provider, code-first migrations
- Swagger/OpenAPI 📚: Interactive docs at
/swagger - Background Jobs ⏱️: Cleanup and unblock workers (
ReservationCleanupWorker,SpectacleCleanupWorker,UserUnblockWorker) - Auditing 🧾: Action history tracking for key operations
Controllers/
AdminController.cs # Admin operations
AuthController.cs # Login / token
HallsController.cs # Halls CRUD
SpectaclesController.cs # Spectacles CRUD & stats
TicketsController.cs # Ticketing & reservations
UserController.cs # User profile & management
UserVisitsController.cs # Visit logging
Data/
AppDbContext.cs
Migrations/ # EF Core migrations
Models/ # Entities & DTOs
Services/ # Business logic & background workers
Program.cs # Host & middleware setup
- Prerequisites
- .NET SDK 8.x
- PostgreSQL 14+ (or compatible)
- Clone & Configure
git clone https://github.com/VolleyLord/theater-api-dotnet.git
cd theater-api-dotnet
Create appsettings.json (or appsettings.Development.json) using the template below. These files are intentionally git-ignored.
{
"ConnectionStrings": {
"Default": "Host=localhost;Port=5432;Database=theaterdb;Username=user;Password=yourpassword"
},
"Jwt": {
"Issuer": "TheaterAPI",
"Audience": "TheaterAPI.Clients",
"Key": "replace-with-a-long-random-secret-key",
"TokenLifetimeMinutes": 120
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}- Restore, Migrate, Run
dotnet restore
dotnet ef database update
dotnet run
The API will start (by default on http://localhost:5197 or similar). Visit http://localhost:<port>/swagger for interactive docs.
- Obtain a JWT via
AuthController(e.g.,/api/auth/login). - Send the token in authorization window.
- Admin-only endpoints are guarded by role checks.
Use TheaterAPI.http (VS Code/Visual Studio REST client) to quickly test endpoints locally.
- Create a new migration:
dotnet ef migrations add <MigrationName>
- Apply migrations:
dotnet ef database update
Ensure your ConnectionStrings:Default is valid before applying migrations.
AuthController— login, token issuanceAdminController— administrative actions (e.g., blocking/unblocking users, audits)HallsController— CRUD for hallsSpectaclesController— CRUD, scheduling, and statisticsTicketsController— ticket reservation, purchase, cleanupUserController— user management, password updatesUserVisitsController— logging and viewing user visits
See Swagger for full request/response schemas.
appsettings.jsonandappsettings.*.jsonare ignored by git.- Important keys:
ConnectionStrings:DefaultJwt:Issuer,Jwt:Audience,Jwt:Key,Jwt:TokenLifetimeMinutes