Skip to content

muhammadabdelgawad/Talabat-API-Project

Repository files navigation

Talabat API Project

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.

Features and Functionality

  • 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.

Technology Stack

  • .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.

Prerequisites

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.

Installation Instructions

  1. Clone the repository:

    git clone https://github.com/muhammadabdelgawad/Talabat-API-Project.git
    cd Talabat-API-Project
  2. Configure the database:

    • Update the connection strings in Talabat.PL/appsettings.json for both Default (StoreContext) and AppIdentityConnection (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"
      }
  3. 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
  4. Seed the database:

    • Run the application. This will trigger the DataStoreSeed.SeedAsync method in Talabat.PL/Program.cs to seed the product, brand, and type data. Also, AppIdentityDbContextSeed.SeedUserAsync will create an initial user.
  5. Configure Stripe API Keys:

    • Update the appsettings.json file in the Talabat.PL project with your Stripe secret key.
      "StripeKeys": {
          "Secretkey": "<Your_Stripe_Secret_Key>"
      }

Usage Guide

  1. Run the API:

    • Open a terminal in the Talabat.PL directory and run:
    dotnet run
  2. Access the API:

    • The API will be accessible at https://localhost:<port>, where <port> is the port number specified in launchSettings.json (typically 5001 or 5002).
  3. 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

API Documentation

  • Base URL: https://localhost:<port>/api

Endpoints:

  • Products:

    • GET /Products: Get all products (supports filtering, sorting, and pagination using query parameters like sort, name, typeId, brandId, pageSize, and index).
    • 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 a CustomerBasketDto in the request body).
    • DELETE /Baskets: Delete a customer basket by ID.
  • Accounts:

    • POST /Accounts/Register: Register a new user (requires a RegisterDto in the request body).
    • POST /Accounts/Login: Login an existing user (requires a LoginDto 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 an AddressDto 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 an OrderDto 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.

Data Transfer Objects (DTOs):

  • 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"
        }
    }

Contributing Guidelines

Contributions are welcome! To contribute to this project:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with descriptive messages.
  4. Submit a pull request to the master branch.

License Information

This project does not currently have a specified license. All rights are reserved by the owner of the repository.

Contact/Support Information

For questions or support, please contact muhammadabdelgawad through GitHub.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages