Skip to content

Varunkamban/taxibhai_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Carpooling GraphQL Application

A .NET Core GraphQL application built with HotChocolate for a carpooling service.

Features

  • GraphQL API with HotChocolate
  • Entity Framework Core with SQL Server
  • Real-time subscriptions for live updates
  • Comprehensive data model for carpooling services
  • Filtering, sorting, and projections support

Prerequisites

  • .NET 8.0 SDK
  • SQL Server (LocalDB or full instance)
  • Visual Studio 2022 or VS Code

Database Setup

  1. Create the database using the provided SQL script:

    • Open SQL/CarpoolingSchema.txt
    • Execute the script in SQL Server Management Studio or Azure Data Studio
    • Or use the Entity Framework migrations (see below)
  2. Update connection string in appsettings.json if needed:

    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=(LocalDB)\\MSSQLLocalDB;Database=CarpoolingDB;Trusted_Connection=True;MultipleActiveResultSets=true;"
      }
    }

Entity Framework Migrations

If you want to use EF migrations instead of the SQL script:

# Add initial migration
dotnet ef migrations add InitialCreate

# Update database
dotnet ef database update

Running the Application

  1. Restore packages:

    dotnet restore
  2. Run the application:

    dotnet run
  3. Access the application:

    • GraphQL endpoint: https://localhost:7000/graphql
    • GraphQL Playground: https://localhost:7000/graphql-voyager
    • Swagger UI: https://localhost:7000/swagger

GraphQL Schema

Queries

  • users - Get all users
  • user(userId: Int!) - Get user by ID
  • drivers - Get all drivers
  • driver(driverId: Int!) - Get driver by ID
  • riders - Get all riders
  • rider(riderId: Int!) - Get rider by ID
  • bookings - Get all bookings
  • booking(bookingId: UUID!) - Get booking by ID
  • packages - Get all packages
  • package(packageId: Int!) - Get package by ID
  • packageCategories - Get all package categories
  • payments - Get all payments
  • transactions - Get all transactions

Mutations

  • createUser(input: CreateUserInput!) - Create a new user
  • createDriver(input: CreateDriverInput!) - Create a new driver
  • createRider(input: CreateRiderInput!) - Create a new rider
  • createBooking(input: CreateBookingInput!) - Create a new booking
  • createPackage(input: CreatePackageInput!) - Create a new package
  • createPayment(input: CreatePaymentInput!) - Create a new payment
  • updateBookingStatus(bookingId: UUID!, status: String!) - Update booking status

Subscriptions

  • onBookingStatusChanged - Subscribe to booking status changes
  • onDriverLocationUpdated - Subscribe to driver location updates
  • onPaymentReceived - Subscribe to payment notifications
  • onRideCompleted - Subscribe to ride completion events

Example GraphQL Queries

Get all users with their roles

query {
  users {
    userId
    firstName
    lastName
    email
    role {
      roleName
    }
  }
}

Create a new user

mutation {
  createUser(input: {
    firstName: "John"
    lastName: "Doe"
    email: "john.doe@example.com"
    passwordHash: "hashedpassword"
    phoneNumber: "+1234567890"
    roleId: 1
  }) {
    userId
    firstName
    lastName
    email
  }
}

Get booking with related data

query {
  booking(bookingId: "123e4567-e89b-12d3-a456-426614174000") {
    bookingId
    pickupLocation
    dropoffLocation
    bookingStatus
    requestedTime
    rider {
      user {
        firstName
        lastName
      }
    }
    driver {
      user {
        firstName
        lastName
      }
      vehicleType
      vehiclePlateNumber
    }
    package {
      packageName
      price
    }
  }
}

Project Structure

CarpoolingGraphQL/
├── Models/                 # Entity models
├── Data/                   # DbContext and data access
├── GraphQL/                # GraphQL types (Query, Mutation, Subscription)
├── SQL/                    # Database schema script
├── appsettings.json        # Configuration
├── Program.cs              # Application entry point
└── README.md               # This file

Technologies Used

  • .NET 8.0 - Framework
  • HotChocolate 13.7.0 - GraphQL server
  • Entity Framework Core 8.0 - ORM
  • SQL Server - Database
  • ASP.NET Core - Web framework

Development

Adding New GraphQL Types

  1. Create new model in Models/ folder
  2. Add DbSet to CarpoolingDbContext
  3. Add queries/mutations in GraphQL/Query.cs or GraphQL/Mutation.cs
  4. Configure relationships in OnModelCreating method

Database Changes

  1. Modify entity models
  2. Create new migration: dotnet ef migrations add MigrationName
  3. Update database: dotnet ef database update

Troubleshooting

Common Issues

  1. Database connection failed

    • Verify SQL Server is running
    • Check connection string in appsettings.json
    • Ensure database exists
  2. GraphQL schema errors

    • Check for missing using statements
    • Verify entity relationships are properly configured
    • Ensure all required packages are installed
  3. Migration errors

    • Delete existing migrations folder
    • Drop and recreate database
    • Run dotnet ef database update again

License

This project is for educational and development purposes.

About

taxibhai_backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors