Skip to content

tripplen23/synchronize-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Fullstack Project of Binh Nguyen - Ecommerce inspiration

PostgreSQL PgAdmin 4 .NET Core EF Core XUnit Moq TypeScript React Redux toolkit TailwindCSS

Project Description

The project was done as a final project at Integrify bootcamp. It will offer core functionality concepts for a typical Ecommerce Website.

Project overview

This repository contains the backend server for an E-Commerce Platform. The project implements RESTful API endpoints for managing users, products, orders, carts, categories, and reviews.

NOTE: The frontend repository can be found here

Link to deployed Frontend Web UI: Frontend

Link to deployed Backend Server: Backend

Table of Contents

Technologies

  • Frontend: TailwindCSS, TypeScript, React, Redux Toolkit
  • Backend: ASP.NET Core, Entity Framework Core, PostgreSQL
  • Testing: Jest for frontend and XUnit, Moq for backend
  • Deployment: Vercel for Frontend, Azure for Backend and Neon.tech for Database

Getting start

  1. Open your terminal and clone the front-end repository with the following command:
git clone https://github.com/tripplen23/fs17-Frontend-project.git
  1. Next, clone the back-end repository:
git clone https://github.com/tripplen23/fs17_CSharp_FullStack.git
  1. Navigate the Web API layer in the back-end directory.
  cd Backend_Ecommerce
  cd Backend_Ecommerce/Ecommerce.WebAPI
  1. Set up your database connection in appsettings.json file with these values, replace them with your own database info and:
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "Localhost": "Host=localhost;Username=<your db username>;Database=<your db name>;Password=<your password>" // Password is optional depend if the user setup the password for admin or not
  },
  "Secrets": {
    "JwtKey": "[Your JWT Key]",
    "Issuer": "[Your Custom Name]"
  }
  1. change database connection configuration in the Program.cs to Local host (replace the following line of code to the line 59 in Program.cs) var dataSourceBuilder = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("Remote"));
  2. Try to build the application
dotnet build
  1. If build successfully, run this command to create a new Migrations folder, which stores the snapshot of all the database context changes: If there is already a folder Migrations in the Web API layer, delete it.
dotnet ef database drop
dotnet ef migrations add Create
  1. Apply all the changes to the database
dotnet ef database update
  1. Then run the backend
dotnet watch
  1. Then navigate to the Frontend Project, install all the necessary dependencies
npm install
  1. Navigate to the path inside frontend project /src/redux/newAxiosConfig.ts, then change the baseURL: "https://sync-ecommerce.azurewebsites.net/api/v1/" to baseURL: "http://localhost:5227/api/v1/"
  2. Then run the frontend
npm start

Folder structure

.
├── Backend_Ecommerce
│   ├── Backend_Ecommerce.sln
│   ├── Ecommerce.Controller
│   │   ├── Ecommerce.Controller.csproj
│   │   └── src
│   │       └── Controller
│   │           ├── AuthController.cs
│   │           ├── CartController.cs
│   │           ├── CategoryController.cs
│   │           ├── OrderController.cs
│   │           ├── ProductController.cs
│   │           ├── ReviewController.cs
│   │           └── UserController.cs
│   ├── Ecommerce.Core
│   │   ├── Ecommerce.Core.csproj
│   │   └── src
│   │       ├── Common
│   │       │   ├── AppException.cs
│   │       │   ├── BaseQueryOptions.cs
│   │       │   ├── ProductQueryOptions.cs
│   │       │   ├── UserCredential.cs
│   │       │   └── UserQueryOptions.cs
│   │       ├── Entity
│   │       │   ├── CartAggregate
│   │       │   |	  ├── Cart.cs
│   │       │   |	  └── CartItem.cs
│   │       │   ├── OrderAggregate
│   │       │   |	  ├── Order.cs
│   │       │   |	  └── OrderProduct.cs
│   │       │   ├── BaseEntity.cs
│   │       │   ├── Category.cs
│   │       │   ├── Product.cs
│   │       │   ├── ProductImage.cs
│   │       │   ├── Review.cs
│   │       │   ├── ShippingInfo.cs
│   │       │   ├── TimeStamp.cs
│   │       │   └── User.cs
│   │       ├── RepoAbstract
│   │       │   ├── ICartItemRepo.cs
│   │       │   ├── ICartRepo.cs
│   │       │   ├── ICategoryRepo.cs
│   │       │   ├── IOrderRepo.cs
│   │       │   ├── IProductImageRepo.cs
│   │       │   ├── IProductRepo.cs
│   │       │   ├── IReviewRepo.cs
│   │       │   └── IUserRepo.cs
│   │       └── ValueObject
│   │           ├── OrderStatus.cs
│   │           └── UserRole.cs
│   ├── Ecommerce.Service
│   │   ├── Ecommerce.Service.csproj
│   │   └── src
│   │       ├── DTO
│   │       │   ├── CartDto.cs
│   │       │   ├── CartItemDto.cs
│   │       │   ├── CategoryDto.cs
│   │       │   ├── OrderDto.cs
│   │       │   ├── OrderProductDto.cs
│   │       │   ├── ProductImageDto.cs
│   │       │   ├── ProductDto.cs
│   │       │   ├── ReviewDto.cs
│   │       │   ├── ShippingInfoDto.cs
│   │       │   └── UserDto.cs
│   │       ├── Service
│   │       │   ├── AuthService.cs
│   │       │   ├── CartItemService.cs
│   │       │   ├── CartService.cs
│   │       │   ├── CategoryService.cs
│   │       │   ├── OrderService.cs
│   │       │   ├── ProductService.cs
│   │       │   ├── ReviewService.cs
│   │       │   └── UserService.cs
│   │       ├── ServiceAbstract
│   │       │   ├── IAuthService.cs
│   │       │   ├── ICartItemService.cs
│   │       │   ├── ICartService.cs
│   │       │   ├── ICategoryService.cs
│   │       │   ├── IOrderService.cs
│   │       │   ├── IPasswordService.cs
│   │       │   ├── IProductImageService.cs
│   │       │   ├── IProductService.cs
│   │       │   ├── IReviewService.cs
│   │       │   ├── ITokenService.cs
│   │       │   └── IUserService.cs
│   │       └── Shared
│   │           └── MapperProfile.cs
│   ├── Ecommerce.Test
│   │   ├── Ecommerce.Test.csproj
│   │   └── src
│   │       ├── Core
│   │       │   └── removeme.txt
│   │       └── Service
│   │           ├── CategoryServiceTest.cs
│   │           ├── OrderServiceTest.cs
│   │           ├── ProductServiceTests.cs
│   │           ├── ReviewServiceTest.cs
│   │           └── UserServiceTest.cs
│   ├── Ecommerce.WebAPI
│   │   ├── Ecommerce.WebAPI.csproj
│   │   ├── Ecommerce.WebAPI.http
│   │   ├── Properties
│   │   │   └── launchSettings.json
│   │   ├── appsettings.Development.json
│   │   ├── appsettings.json
│   │   └── src
│   │       ├── AuthorizationPolicy
│   │       |   ├── AdminOrOwnerAccountRequirement.cs
│   │       │   ├── AdminOrOwnerCartRequirement.cs
│   │       │   ├── AdminOrOwnerOrderRequirement.cs
│   │       │   └── AdminOrOwnerReviewRequirement.cs
│   │       ├── Database
│   │       |   ├── AppDbContext.cs
│   │       │   ├── SeedingData.cs
│   │       │   └── TimeStampInterceptor.cs
│   │       ├── ExternalService
│   │       │   ├── PasswordService.cs
│   │       │   └── TokenService.cs
│   │       ├── Middleware
│   │       │   └── ExceptionHandlerMiddleware.cs
│   │       ├── Program.cs
│   │       └── Repo
│   │           ├── CategoryRepo.cs
│   │           ├── OrderRepo.cs
│   │           ├── ProductRepo.cs
│   │           ├── ReviewRepo.cs
│   │           └── UserRepo.cs
├── image
├──.gitignore
└── README.md

Relational database design

erd Click to see clearer

Functionalities

  1. Allow Anonymous:
  • Login -> POST http://localhost:5227/api/v1/auth/login
  • Get All Categories -> GET http://localhost:5227/api/v1/categories
  • Get Category By ID -> GET http://localhost:5227/api/v1/categories/:category_id
  • Get Order By User ID -> GET http://localhost:5227/api/v1/orders/user/:userId (Should be changed into Admin and Owner later!)
  • Get Order by ID -> GET http://localhost:5227/api/v1/orders/:orderId (Should be changed into Admin and Owner later!)
  • Get All Products -> GET http://localhost:5227/api/v1/products
  • Get Products By Category -> GET http://localhost:5227/api/v1/products/category/:categoryId
  • Get Product By Id -> GET http://localhost:5227/api/v1/products/:productId
  • Get All Reviews -> GET http://localhost:5227/api/v1/reviews
  • Get All Reviews Of A Product -> GET http://localhost:5227/api/v1/reviews/product/:productId
  • Get Review By ID -> GET http://localhost:5227/api/v1/reviews/:reviewId
  • Create An User (Register) -> POST http://localhost:5227/api/v1/users
  1. Owner only (Logged-in Users):
  • Logout -> POST http://localhost:5227/api/v1/auth/logout
  • Create An Order -> POST http://localhost:5227/api/v1/orders
  • Get Review By ID -> GET http://localhost:5227/api/v1/reviews/:reviewId
  • Create A Review -> POST http://localhost:5227/api/v1/reviews
  • Update An User Profile -> PUT http://localhost:5227/api/v1/users/:userId
  1. Admin and Owner:
  • Get Current User Profile -> GET http://localhost:5227/api/v1/auth/profile
  • Get Cart By ID -> GET http://localhost:5227/api/v1/carts/:cartId
  • Delete Cart By ID -> DELETE http://localhost:5227/api/v1/carts/:cartId
  • Update Cart Item's Quantity -> PATCH http://localhost:5227/api/v1/carts/:cartId
  • Update A Review By ID -> PATCH http://localhost:5227/api/v1/reviews/:reviewId
  • Delete A Review By ID -> DELETE http://localhost:5227/api/v1/reviews/:reviewId
  1. Admin Only:
  • Get All Carts -> GET http://localhost:5227/api/v1/carts
  • Create A New Category -> POST http://localhost:5227/api/v1/categories
  • Update A Category By ID -> PATCH http://localhost:5227/api/v1/categories/:category_id
  • Delele A Category By ID -> DELETE http://localhost:5227/api/v1/categories/:category_id
  • Get All Orders -> GET http://localhost:5227/api/v1/orders
  • Update Order Status or Shipping Information -> PATCH http://localhost:5227/api/v1/orders/:orderId
  • Delete An Order -> DELETE http://localhost:5227/api/v1/orders/:orderId
  • Create A Product -> POST http://localhost:5227/api/v1/products
  • Update A Product -> PATCH http://localhost:5227/api/v1/products/:productId
  • Delete A Product -> DELETE http://localhost:5227/api/v1/products/:productId
  • Get All Users -> GET http://localhost:5227/api/v1/users
  • Get User By ID -> GET http://localhost:5227/api/v1/users/{userId} (Should be changed into Admin and Owner later!)
  • Delete An User By ID -> DELETE http://localhost:5227/api/v1/users/{userId} (Should be changed into Admin and Owner later!)

RESTful API design

Check /Endpoints folder for all api endpoints and the usage, or click the links below to check descriptions and example request & response for each endpoint.

swaggerUI

CLEAN Architecture

image

This project follows the principles of Clean Architecture, emphasizing separation of concerns and modularity. It is organized into several layers, each with distinct responsibilities.

  1. Core Domain Layer (Ecommerce.Core)
  • Centralizes core domain logic and entities.
  • Includes common functionalities, repository abstractions, and value objects.
  1. Application Service Layer (Ecommerce.Service)
  • Implements business logic and orchestrates interactions between controllers and the core domain.
  • Services handle DTO transformations and business operations related to each resource.
  1. Controller Layer (Ecommerce.Controller)
  • Contains controllers responsible for handling HTTP requests and responses.
  • Controllers are organised by resource types (e.g., Auth, Category, Order, Product, Review, User).
  1. Infrastructure Layer (Ecommerce.WebAPI)
  • Manages infrastructure tasks and interaction with external systems.
  • Contains database context, repositories, and middleware for error handling.
  1. Testing Layer (Ecommerce.Test)
  • Holds unit tests for core domain and application services.
  • Ensures the reliability and correctness of the implemented functionalities.

Data flow:

image

Testing

Run tests:

  • Navigate to root folder of backend module, then run the test
dotnet test

test result

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages