A .NET 8 RESTful Web API for managing a Book Library system, built using Repository Pattern and Unit of Work, with JWT Authentication for securing endpoints.
- 🏛️ Repository Pattern and Unit of Work for clean architecture
- 🔒 Authentication & Authorization using JWT Bearer Tokens
- 📚 Book Borrowing and Returning system
- 🛡️ Role-based access control (
Adminrole features) - 🧪 Built-in Swagger UI for testing APIs
- 🚀 Dockerized for easy deployment
/RepositoryPatternWithUOW.Api --> Main Web API project
├── /Controllers --> API Controllers (Auth, Books, Authors)
├── appsettings.json --> Application settings
├── Dockerfile --> Docker configuration
├── Program.cs --> Application entry point
/RepositoryPatternWithUOW.Core --> Core layer (business logic)
├── /Constants --> Static values/constants
├── /Interfaces --> Repository and Unit of Work interfaces
├── /Models --> Entity and business models
├── IUnitOfWork.cs --> Unit of Work interface
/RepositoryPatternWithUOW.EF --> Infrastructure layer (Entity Framework)
├── /Migrations --> EF Core Migrations
├── /Repositories --> Repository implementations
├── ApplicationDbContext.cs --> EF Core DbContext
├── UnitOfWork.cs --> Unit of Work implementation
- 🔒 JWT Bearer Authentication secures the API.
- 🛡️ Some endpoints require specific Roles (e.g.,
Admin) for sensitive actions.
| Method | Route | Description | Authorization Required |
|---|---|---|---|
| POST | /register |
Register a new user | ❌ |
| POST | /login |
Login and get JWT token | ❌ |
| POST | /addrole |
Add a role to a user | ✅ (Admin only) |
| Method | Route | Description | Authorization Required |
|---|---|---|---|
| GET | /GetAllAvailable |
Get all available (not borrowed) books | ❌ |
| GET | /GetAll |
Get all books | ✅ (Admin only) |
| POST | /AddBook |
Add a new book | ✅ (Admin only) |
| POST | /BorrowBook |
Borrow a book | ✅ |
| POST | /ReturnBook |
Return a borrowed book | ✅ |
| GET | /GetByName |
Get a book by Title ("NewBook") | ❌ |
| GET | /GetAllWithAuthors |
Get books with author information (Title contains "NewBook") | ❌ |
| GET | /GetOrdered |
Get books ordered by Id (Title contains "NewBook") | ❌ |
| Method | Route | Description | Authorization Required |
|---|---|---|---|
| GET | / |
Get author by static ID (id=1) | ✅ |
| GET | /GetbyIdAsync |
Get author asynchronously by ID (id=1) | ❌ |
| Technology | Purpose |
|---|---|
| .NET 8 | Backend Framework |
| Entity Framework Core | ORM |
| JWT Bearer Authentication | Authentication |
| Docker | Containerization |
| Swagger (Swashbuckle) | API Documentation |
- .NET 8 SDK
- Docker (optional)
git clone https://github.com/YOUR_GITHUB_USERNAME/RepositoryPatternWithUOW.git
cd RepositoryPatternWithUOWcd RepositoryPatternWithUOW.Api
dotnet restore
dotnet runSwagger UI will be available at:
➡️ https://localhost:5001/swagger (HTTPS)
➡️ http://localhost:5000/swagger (HTTP)
docker build -t booklibraryapi .
docker run -d -p 5000:80 booklibraryapiPOST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "YourSecurePassword123!"
}POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "YourSecurePassword123!"
}Use the received token in Authorization headers:
Authorization: Bearer YOUR_JWT_TOKEN
POST /api/books/BorrowBook?BookId=1&UserId=your_user_id
Authorization: Bearer YOUR_JWT_TOKENMade with ❤️ by Filo Salah
🔗 Docker Hub: filosalah
#️⃣ Feel free to fork, contribute, and star the project!