This repository contains the code for the Talabat API project, an e-commerce backend built with .NET. It provides functionalities for managing products, brands, types, customer baskets, orders, user accounts, and payments.
-
Product Management:
- Browse products with filtering, sorting, and pagination.
- Retrieve product details by ID.
- Fetch product brands and types.
-
Basket Management:
- Create, retrieve, update, and delete customer baskets.
- Manage basket items (add, update quantity, remove).
-
Order Management:
- Create orders.
- Retrieve orders for a specific user.
- Retrieve order details by ID for a user.
- Get a list of available delivery methods.
-
User Account Management:
- Register new users.
- Login existing users.
- Retrieve current user information.
- Get and update user addresses.
-
Payment Integration:
- Create or update payment intents for customer baskets using Stripe.
-
Caching: Implemented caching using Redis to improve API response times for Product listing.
- .NET: The project is built using the .NET framework.
- ASP.NET Core Web API: Provides the API endpoints.
- Entity Framework Core (EF Core): Used as the ORM for database interactions (SQL Server).
- Microsoft Identity: Used for authentication and authorization.
- StackExchange.Redis: Used for interacting with Redis Cache.
- Stripe: Used for payment processing.
- AutoMapper: Used for object-object mapping.
- SQL Server: Database used to store application data.
Before you begin, ensure you have the following installed:
- .NET SDK: Install the latest .NET SDK from https://dotnet.microsoft.com/download.
- SQL Server: Install SQL Server Express or a similar SQL Server instance.
- Redis Server: Install and run a Redis server instance.
- Stripe Account: Create a Stripe account at https://stripe.com to obtain API keys.
-
Clone the repository:
git clone https://github.com/muhammadabdelgawad/Talabat-API-Project.git cd Talabat-API-Project
-
Configure the database:
-
Update the connection strings in
Talabat.PL/appsettings.json
for bothDefault
(StoreContext) andAppIdentityConnection
(AppIdentityDbContext). Replace<Your_Database_Server>
with the correct server address,<Your_Database_Name>
with the preferred database name, and<Your_Database_User_Id>
&<Your_Database_Password>
with credentials that has access to the database. Example:"ConnectionStrings": { "Default": "Data Source=<Your_Database_Server>;Initial Catalog=<Your_Database_Name>;Integrated Security=True;User Id=<Your_Database_User_Id>;Password=<Your_Database_Password>;MultipleActiveResultSets=True", "AppIdentityConnection": "Data Source=<Your_Database_Server>;Initial Catalog=<Your_Database_Name>;Integrated Security=True;User Id=<Your_Database_User_Id>;Password=<Your_Database_Password>;MultipleActiveResultSets=True", "RidusConnection": "localhost" }
-
-
Apply EF Core Migrations:
- Open a terminal in the
Talabat.Repository
directory.
dotnet ef database update -s ../Talabat.PL -c StoreContext dotnet ef database update -s ../Talabat.PL -c AppIdentityDbContext
- Open a terminal in the
-
Seed the database:
- Run the application. This will trigger the
DataStoreSeed.SeedAsync
method inTalabat.PL/Program.cs
to seed the product, brand, and type data. Also,AppIdentityDbContextSeed.SeedUserAsync
will create an initial user.
- Run the application. This will trigger the
-
Configure Stripe API Keys:
- Update the
appsettings.json
file in theTalabat.PL
project with your Stripe secret key."StripeKeys": { "Secretkey": "<Your_Stripe_Secret_Key>" }
- Update the
-
Run the API:
- Open a terminal in the
Talabat.PL
directory and run:
dotnet run
- Open a terminal in the
-
Access the API:
- The API will be accessible at
https://localhost:<port>
, where<port>
is the port number specified inlaunchSettings.json
(typically 5001 or 5002).
- The API will be accessible at
-
Explore the API Endpoints:
-
Use tools like Postman, Swagger UI (if enabled), or
curl
to interact with the API endpoints. -
Example using
curl
to get all products:curl https://localhost:5001/api/Products
-
- Base URL:
https://localhost:<port>/api
-
Products:
GET /Products
: Get all products (supports filtering, sorting, and pagination using query parameters likesort
,name
,typeId
,brandId
,pageSize
, andindex
).GET /Products/{Id}
: Get a product by ID.GET /Products/Brands
: Get all product brands.GET /Products/Types
: Get all product types.
-
Baskets:
GET /Baskets/{id}
: Get or recreate a customer basket by ID.POST /Baskets
: Update or create a customer basket (requires aCustomerBasketDto
in the request body).DELETE /Baskets
: Delete a customer basket by ID.
-
Accounts:
POST /Accounts/Register
: Register a new user (requires aRegisterDto
in the request body).POST /Accounts/Login
: Login an existing user (requires aLoginDto
in the request body).GET /Accounts/GetCurrentUser
: Get the current user (requires authentication).GET /Accounts/Address
: Get the user's address (requires authentication).PUT /Accounts/UpdateUserAddress
: Update the user's address (requires authentication and anAddressDto
in the request body).GET /Accounts/IsUserExist?Email={Email}
: Check if the User is Exist by Email.
-
Order:
POST /Order
: Create a new order (requires authentication and anOrderDto
in the request body).GET /Order
: Get all orders for the current user (requires authentication).GET /Order/{id}
: Get an order by ID for the current user (requires authentication).GET /Order/DeliveryMethods
: Get all available delivery methods.
-
Payments:
POST /Payments
: Creates or update Payment Intent.
-
ProductToReturnDto:
{ "id": 1, "name": "Product Name", "description": "Product Description", "pictureUrl": "URL to the product image", "price": 19.99, "brandId": 1, "brand": "Brand Name", "typeId": 1, "type": "Type Name" }
-
CustomerBasketDto:
{ "id": "basketId", "items": [ { "id": 1, "productName": "Product Name", "pictureUrl": "URL to product image", "brand": "Brand Name", "type": "Type Name", "price": 24.99, "quantity": 2 } ], "paymentIntentId": "string", "clientSecret": "string", "deliveryMethodId": 1 }
-
RegisterDto:
{ "email": "user@example.com", "displayName": "John Doe", "phoneNumber": "123-456-7890", "password": "StrongPassword123!" }
-
LoginDto:
{ "email": "user@example.com", "password": "password" }
-
AddressDto:
{ "firstName": "John", "lastName": "Doe", "street": "123 Main St", "city": "Anytown", "country": "USA" }
-
OrderDto:
{ "basketId": "basketId", "deliveryMethodId": 1, "shippingAddress": { "firstName": "John", "lastName": "Doe", "street": "123 Main St", "city": "Anytown", "country": "USA" } }
Contributions are welcome! To contribute to this project:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with descriptive messages.
- Submit a pull request to the
master
branch.
This project does not currently have a specified license. All rights are reserved by the owner of the repository.
For questions or support, please contact muhammadabdelgawad through GitHub.