Welcome to the Talabat API! This repository contains the backend logic for an e-commerce platform, providing endpoints for user management, products, orders, payments, and more.
- Overview
- Authentication and Authorization
- Controllers
- Permissions
- Database Schema
- How to Run the Project
The Talabat API is a backend system built using ASP.NET Core to support the functionality of managing an e-commerce platform. It includes user management, product listings, order processing, and Stripe-based payment handling.
- User Authentication & Authorization
- Product Management
- Order Creation & Tracking
- Payment Integration via Stripe
- Role-based access control
This API uses JWT tokens for authentication and role-based authorization to ensure secure access to protected resources. Make sure to include a valid JWT token in your requests' Authorization header.
The AccountController handles user account-related operations such as fetching and updating user profile information and changing passwords.
GET /me: Fetch current user's profile information.PUT /me/info: Update current user's profile.PUT /me/change-password: Change the current user's password.
The AuthController is responsible for handling user authentication actions such as login, registration, and token management.
POST /auth: Log in with email and password.POST /auth/refresh: Refresh an expired JWT token.POST /auth/register: Register a new user.
The ProductsController manages operations related to listing, retrieving, adding, updating, and deleting products.
GET /api/products: Fetch all products.GET /api/products/{id}: Fetch product details by ID.POST /api/products: Create a new product.PUT /api/products/{id}: Update an existing product.DELETE /api/products/{id}: Delete a product.
The OrdersController handles order creation, tracking, and management.
GET /api/orders: Fetch all orders.GET /api/orders/{id}: Fetch order details by ID.POST /api/orders: Create a new order.PUT /api/orders/{id}: Update an existing order.DELETE /api/orders/{id}: Cancel an order.
The PaymentsController integrates Stripe to manage payments for orders.
POST /api/payments: Process a payment using Stripe.GET /api/payments/history: Get the payment history for a user.
The UsersController manages user-related tasks such as retrieving user information and updating user statuses.
GET /api/users: Fetch all users.GET /api/users/{id}: Get details of a specific user.POST /api/users: Create a new user.PUT /api/users/{id}: Update an existing user.PUT /api/users/{id}/toggle-status: Toggle the active status of a user.
Permissions are enforced at the controller and action level to restrict access based on the user's role and assigned permissions. These permissions are set in attributes such as [HasPermission(Permissions.AddProduct)].
The Talabat API database schema is designed around core entities such as Product, Order, Payment, and ApplicationUser. Below is a high-level overview of the tables and relationships.
-
ApplicationUser: Represents the system's users, extending ASP.NET Core Identity features. Each user can have many
OrdersandPayments.- One-to-Many:
ApplicationUser↔Order - One-to-Many:
ApplicationUser↔Payment
- One-to-Many:
-
Product: Contains product information such as name, price, and stock. A product can be associated with many
Orders.- One-to-Many:
Product↔Order
- One-to-Many:
-
Order: Represents customer purchases. Each order contains references to
Productsand is linked to anApplicationUser.- One-to-Many:
Order↔Product - Many-to-One:
Order↔ApplicationUser
- One-to-Many:
-
Payment: Represents a payment made for an order. Each payment is associated with an
Orderand anApplicationUser.- One-to-One:
Payment↔Order - Many-to-One:
Payment↔ApplicationUser
- One-to-One:
The schema can be visualized as follows:
ApplicationUser
↳ Order (1-N)
↳ Payment (1-N)
Product
↳ Order (1-N)
Order
↳ Product (1-N)
↳ Payment (1-1)
Each arrow (↳) represents a one-to-many (1-N) or one-to-one (1-1) relationship. For example, one Order can contain many Products, and one Payment is linked to one Order.
To run the project locally:
-
Clone the repository:
git clone https://github.com/your-repo/Talabat.Api.git
-
Just run the project
when you run the project everything will be set for you, including creating the database and seeding it with initial data