Giter Site home page Giter Site logo

bangazon-server's Introduction

Bangazon

Bangazon E-commerce Platform aims to provide a comprehensive online shopping experience for customers. Customers can view products, add them to their cart, place orders, manage their profiles, and much more.

About the User

  • The ideal user for this application is either a customer or seller.
  • Ideal for people who want to shop and purchase products.
  • Ideal for sellers who want to sell products.

Features

Our backend API for Bangazon has many features where:

  • Users can register or sign in.
  • Customers can shop for products/view product details, add items to their cart, check out, view order history, search items and sellers, view seller's stores.
  • Sellers can view orders with their products on them, view their seller dashboard, past sales, search products and sellers.

Data Design

306937666-3504e7cd-2dc9-42ca-a31a-eb73ca32c44b

Contributors

bangazon-server's People

Contributors

dylankmoore avatar

Watchers

 avatar

bangazon-server's Issues

Read/Get Categories

As backend developers, we need to create endpoints that GET all categories.

User Story

As a user, I want to be able to see the different categories for the available products.

Acceptance Criteria

Given a user is viewing any page on the Bangazon site
When the user clicks on the Product Categories hyperlink
Then the user will see a view containing a list of all product categories

Dependencies

#2 #3 #4

Dev Notes

We need to create an endpoint for GETTING categories.
app.MapGet("/api/categories"...

a reference from Creek River:
app.MapGet("/api/campsites", (CreekRiverDbContext db) => { return db.Campsites.ToList(); });

Get Users

As backend developers, we need to create an endpoint to GET all users.

Acceptance Criteria

We need to be able to query all of our users to verify if they are a registered user or not.

Dependencies

#2 #3 #4

Dev Notes

We need to create a GET request to get all users -
app.MapGet("/api/users..."

And a request to GET users by their IDS -
app.MapGet("/api/users/{id}"

Read/Get Orders

Customers should be able to view their order history, which will require a GET request that fetches all of our orders associated with that user/customerId.

A seller should also see orders that include products that align with their sellerId.

User Story

As a customer, I want to be able to view my orders & their details in the order history page.
I also want to see the seller's info for each product in an order.

As a seller, I want to see the orders that include products that I am selling.

Acceptance Criteria

When a user navigates to the order history page
Then order details should be displayed
And a user should be able to see the seller's info for a given order

Given a seller has sold items
When a seller navigates to the order history page
Then there should be a section dedicated to orders with their products
And they should be able to see the customers that placed each order

Dependencies

#2 #3 #4

Dev Notes

API calls that will involve the fetching of our orders:

app.MapGet("api/orders") will return the orders for a logged in user
app.MapGet("api/orders/sellers") will return the orders as well as the seller's info for each product on an order
app.MapGet("api/order/history/seller") should return the orders where the logged-in user has a product on the order
app.MapGet("/api/orders/{id}" will allow us to get orders by their ID

Create data & database

As backend web developers, we must create our DbContext class, seed our database with data, and create our database.

Acceptance Criteria

Once we create our models, DbContext class, data, and create our database - this database should be ready to query in pgAdmin.

Dependencies

#2 #3 We need to have our project setup & our Models created so that we can create data that references them.

Dev Notes

  • First, we must create a file in the main directory of the project called BangazonDbContext.cs and paste the following code in it (must be edited to reflect our Bangazon database entities):
using Microsoft.EntityFrameworkCore;
using CreekRiver.Models;

public class CreekRiverDbContext : DbContext
{

    public DbSet<Reservation> Reservations { get; set; }
    public DbSet<UserProfile> UserProfiles { get; set; }
    public DbSet<Campsite> Campsites { get; set; }
    public DbSet<CampsiteType> CampsiteTypes { get; set; }

    public CreekRiverDbContext(DbContextOptions<CreekRiverDbContext> context) : base(context)
    {

    }
}
  • Inside of the BangazonDbContext class, we will add the appropriate methods for all of our data entities. As an example from Creek River -
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    // seed data with campsite types
    modelBuilder.Entity<CampsiteType>().HasData(new CampsiteType[]
    {
        new CampsiteType {Id = 1, CampsiteTypeName = "Tent", FeePerNight = 15.99M, MaxReservationDays = 7},
        new CampsiteType {Id = 2, CampsiteTypeName = "RV", FeePerNight = 26.50M, MaxReservationDays = 14},
        new CampsiteType {Id = 3, CampsiteTypeName = "Primitive", FeePerNight = 10.00M, MaxReservationDays = 3},
        new CampsiteType {Id = 4, CampsiteTypeName = "Hammock", FeePerNight = 12M, MaxReservationDays = 7}
    });
}

After data has been made for all of our entities -

  • Create our Database:
  1. Run the following in the main project directory:
    dotnet ef migrations add InitialCreate

  2. This command will create a Migrations folder with a number of C# files in it in the project directory. When it finishes, run this:
    dotnet ef database update

  3. If everything goes well, you should now have a database ready to query! Open pgAdmin, and take a look at the database that EF Core created.

Create Users

As backend developers, we want to create a POST endpoint that allow for the creation of new users on our site.

User Story

As a new user to Bangaon, I want to be able to register an account so that I can be able to buy or sell products.

Acceptance Criteria

Given that a user wants to buy or sell products and does not already have an account
When they navigate to the app
Then they are given the option to register a new user

Dependencies

#2 #3 #4

Dev Notes

We will need to create a POST endpoint to CREATE new users -
app.MapPost("/api/users"...

an example of a POST endpoint from Creek River:
app.MapPost("/api/campsites", (CreekRiverDbContext db, Campsite campsite) => { db.Campsites.Add(campsite); db.SaveChanges(); return Results.Created($"/api/campsites/{campsite.Id}", campsite); });

Update Products

As backend developers, we should create an endpoint so that a seller can update a product if need be.

User Story

As a seller, I want to update information related to one of my products.

Acceptance Criteria

When I click on "update product"
Then I will be able to edit information on the product
And click "submit"
Then I will see my updated product information

Dependencies

#2 #3 #4

Dev Notes

We need to create a PUT endpoint so that we can update a product.
app.MapPut("/api/products/{id}"...

A put endpoint reference from Creek River:

app.MapPut("/api/campsites/{id}", (CreekRiverDbContext db, int id, Campsite campsite) =>
{
    Campsite campsiteToUpdate = db.Campsites.SingleOrDefault(campsite => campsite.Id == id);
    if (campsiteToUpdate == null)
    {
        return Results.NotFound();
    }
    campsiteToUpdate.Nickname = campsite.Nickname;
    campsiteToUpdate.CampsiteTypeId = campsite.CampsiteTypeId;
    campsiteToUpdate.ImageUrl = campsite.ImageUrl;

    db.SaveChanges();
    return Results.NoContent();
});

Updating Order

As backend developers, we need to create a POST endpoint for a user to be able to add products to their order.

User Story

As a user, I want to be able to add a product to my cart/order.

Acceptance Criteria

Given the customer is on a product detail page
When clicking on an add to cart button
Then the product should be added to their cart

Dependencies

#2 #3 #4

Dev Notes

We need to create the POST endpoint so that a user can ADD a product to an order -
app.MapPost("/api/orders/{id}/products...

It won't look quite like this but as a reference to post requests in the Creek River -

app.MapPost("/api/reservations", (CreekRiverDbContext db, Reservation newRes) =>
{
    try
    {
        db.Reservations.Add(newRes);
        db.SaveChanges();
        return Results.Created($"/api/reservations/{newRes.Id}", newRes);
    }
    catch (DbUpdateException)
    {
        return Results.BadRequest("Invalid data submitted");
    }
});

Create firebase

As backend developers, we should set up our firebase project so that the front end client ensures users will be able to log in as authenticated users.

User Story

As a user, I should be able to log in to the app and be recognized as a unique user.

Acceptance Criteria

When the front end is running, users will be able to successfully log in and be recognized as an authenticated user.

Dev Notes

We need to create a project in firebase and make sure we enable authentication for the client side portion of Bangazon. There are video references in our google classroom for us to use while setting up the firebase project.

Project Setup

Acceptance Criteria

After creating our web api with the proper dependencies, initalizing secrets, & establishing connection string we should add the code provided in our dev notes to our Program.cs file & remove the weather related code. These are the necessary first steps to setting our project up for coding.

Dependencies/Dev Notes

-dependencies:
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL --version 6.0
dotnet add package Microsoft.EntityFrameworkCore.Design --version 6.0

-initalize secrets:
dotnet user-secrets init

-establish connection string:
dotnet user-secrets set "BangazonDbConnectionString" "Host=localhost;Port=<port>;Username=postgres;Password=<your_postgresql_password>;Database=Bangazon"

We must configure our web API to use EF Core:

-add to the TOP of Program.cs:
using Bangazon.Models; using Microsoft.EntityFrameworkCore; using System.Text.Json.Serialization; using Microsoft.AspNetCore.Http.Json;

-add the following above the var app = builder.Build(); in Program.cs:

// allows passing datetimes without time zone data 
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

// allows our api endpoints to access the database through Entity Framework Core
builder.Services.AddNpgsql<BangazonDbContext>(builder.Configuration["BangazonDbConnectionString"]);

// Set the JSON serializer options
builder.Services.Configure<JsonOptions>(options =>
{
    options.SerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});

-remove the weather related code from the Program.cs

Create classes

As backend developers, we must create our classes within our Models folder

Acceptance Criteria

  • Create a Models folder in the project folder
  • Create individual files for each of our data objects
    (Orders.cs, Products.cs, Categories.cs, OrderProducts.cs, PaymentType.cs, Users.cs)
  • These files will contain the classes and properties for each object, which will be referenced from our ERD

Dependencies

#2 Our project should ideally be set up properly before we begin adding in our classes

Dev Notes

ERD:
bangazonERD

Our class structure will resemble examples from our CreekRiver project -

using System.ComponentModel.DataAnnotations;

namespace CreekRiver.Models;

public class Campsite
{
    public int Id { get; set; }
    [Required]
    public string Nickname { get; set; }
    public string ImageUrl { get; set; }
    public int CampsiteTypeId { get; set; }
    public CampsiteType CampsiteType { get; set; }
    public List<Reservation> Reservations { get; set; }
} 

However, we will use the ICollection method instead of the List method when we need to get the data from another object to establish our many to many relationships in entity framework.

Delete Orders

As backend developers, we need to create an endpoint that allows users to delete items from their carts/orders.

User Story

As a user, I want to be able to delete an item/order from my cart.

Acceptance Criteria

Given that a customer has an item in their cart
When they click the Delete button
Then the product is removed from their cart

Dependencies

#2 #3 #4

Dev Notes

We will need to create a DELETE request for this.
app.MapDelete("/api/orders/{id}"...

We can reference our delete endpoints in Creek River as we think of how to create this one -
instead of reservations/{id} it will be orders/{id} etc:

app.MapDelete("/api/reservations/{id}", (CreekRiverDbContext db, int id) =>
    {
        Reservation reservation = db.Reservations.SingleOrDefault(r => r.Id == id);
        if (reservation == null) { return Results.NotFound();
        }
        db.Reservations.Remove(reservation);
        db.SaveChanges();

        return Results.Ok("Reservation has been deleted!");
}); 

Delete Products

As backend developers, we need to create logic that allows users who are sellers the ability to delete products.

User Story

As a seller, I want to be able to delete products from my inventory.

Acceptance Criteria

When I no longer want to have a product listed,
Then I will be able to click the Delete button
And have it be removed from the inventory

Dependencies

#2 #3 #4

Dev Notes

We need to create a DELETE request that will start off like...
app.MapDelete("/api/products/{id}" ...

and as a reference from deleting in Creek River -

app.MapDelete("/api/reservations/{id}", (CreekRiverDbContext db, int id) =>
    {
        Reservation reservation = db.Reservations.SingleOrDefault(r => r.Id == id);
        if (reservation == null) { return Results.NotFound();
        }
        db.Reservations.Remove(reservation);
        db.SaveChanges();

        return Results.Ok("Reservation has been deleted!");
}); 

Read/Get Products

We need to be able to implement endpoints that enable a user to fetch all products from all sellers.

User Story

As a user, I want to be able to see a list of all available products to purchase.

Acceptance Criteria

Given that a seller has a store with products available
When a customer is viewing a seller's store
Then they will see all the products that the seller has available

Dependencies

#2 #3 #4

Dev Notes

We will need a GET request that gets all products -
app.MapPost("/api/products..."

and a GET request that gets all products by ID -
app.MapGet("/api/products/{id}"

Create Products

As backend developers, we need to have an endpoint that allows a user who is a seller the ability to create a product/add a product to the inventory.

User Story

As a seller, I want to be able to add new products to my inventory to sell.

Acceptance Criteria

When I want to add a new product,
Then I will click "Add Product"
And upload the product, which will
Then add the product to the inventory.

Dependencies

#2 #3 #4

Dev Notes

We will need a POST request that allows creation of new products.
app.MapPost("/api/products" ...

A reference from Creek River:
app.MapPost("/api/campsites", (CreekRiverDbContext db, Campsite campsite) => { db.Campsites.Add(campsite); db.SaveChanges(); return Results.Created($"/api/campsites/{campsite.Id}", campsite); });

Project Guidelines

For reference, this is the full outline of what our user's experience should look like. This is what we should be basing our backend endpoints off of. I'm adding this so that I can check these all off as I go over my work.

Acceptance Criteria

  • Title: Customer should be able to view products that a seller is selling
    Given that a seller has a store with products available
    When a customer is viewing a seller's store
    Then they will see all the products that the seller has available
    Potential Implementation Ideas
    Potentially create a new endpoint that includes product information with the seller
    Potentially refactor the existing seller endpoint to include product information
    Potentially create a query string parameter ?include=products to optionally include product information with the seller

  • Title: Allow a user to register for Bangazon
    Given that a user wants to buy or sell products and does not already have an account
    When they navigate to the app
    Then they are given the option to register a new user

  • Title: Customers can view shopping cart
    Given a user has products in their shopping cart
    When viewing their cart
    Then they should see the product name and price of each product they are ordering
    And they should be able to see the total amount of their order

  • Title: Allow sellers to see orders with their products on them
    Given a seller has sold items
    When a seller navigates to the order history page
    Then there should be a section dedicated to orders with their products
    And they should be able to see the customers that placed each order
    API Routes
    api/order/history/seller should return the orders where the logged-in user has a product on the order

  • Title: User Can View Product Detail
    Given the user is viewing any page that contains a hyperlink for a product
    When the user clicks on the product hyperlink
    Then the user will be shown the product detail page containing the title, description, quantity available, price per unit, and a button labeled Add to Cart

  • Title: Customer should be able to view product information when viewing order details
    Given a customer has purchased items
    When the customer views their order history
    Then product details should be viewable with each order

  • Title: Customer should be able to view their completed orders
    Given a customer has purchased items
    When the customer navigates to the Orders view
    Then they should see a list of their completed orders
    Potential Implementation Ideas:
    Potentially create a new endpoint that includes only completed Orders
    Potentially create a query string parameter ?completed=true to optionally include completed orders

  • Title: Customer can search for products
    Given sellers have items to purchase
    When the user clicks on the search input field in the navigation bar
    And the user types the name of a product
    When the enter key is pressed
    Then products matching the keyword will be shown on the page

  • Title: Customer should be able to view order history
    When a user navigates to the order history page
    Then order details should be displayed
    And a user should be able to see the seller's info for a given order
    Order API Routes:
    api/orders should return the orders for the logged-in user
    api/orders/sellers should return the orders for the logged-in user, along with the seller's info for each product on each order

  • Title: Seller should have a dashboard
    Given a seller has sold items
    When they navigate to the seller area
    Then they should arrive at a dashboard
    Dashboard data to display:
    Total Sales
    Total this month
    Average per item
    Total Inventory by Category
    Orders that require shipping

  • Title: Customer can view latest products on home page
    Given a user visits the home page of Bangazon
    When the page renders
    Then the last 20 products that have been added to the system will be displayed as hyperlinks to their respective detail pages

  • Title: Allow a user to place an order
    Given the user is authenticated
    And the user is viewing their cart
    When the user clicks the Order button
    Then the user should be presented with a view that allows them to select a payment type for the order

Given the user selects a payment option
When the user clicks the Done button
Then the payment type must be added to the order
And the user will be presented with a confirmation/thank you screen

  • Title: Customer can click on a seller's name on a product page to view all products sold by that seller
    Given a customer is on a product detail page
    When clicking on a seller's name
    Then they should be taken to a Seller's store

  • Title: Search for Seller by text
    Given A user is logged in
    Then they should be able to search for a seller

If the query string parameter of q is provided when querying the list of customers, then any customer that has a property value that matches the pattern should be returned.

If /customers?q=mic is requested, then any customer whose first name is Michelle, or Michael, or Domicio should be returned. Any customer whose last name is Michaelangelo, Omici, or Dibromic should be returned. Every property of the customer object should be checked for a match.

  • Title: Customer can add products to a cart
    Given the customer is on a product detail page
    When clicking on an add to cart button
    Then the product should be added to their cart

  • Title: Seller should be able to view their past sales
    Given a seller has sold items
    When the seller navigates to the Orders view
    Then they should see a list of their completed orders

  • Title: Customer can view their profile information
    Given a customer has registered an account
    When they click on their username
    Then they can view their profile information.

  • Title: Customer can delete an item from their cart
    Given that a customer has an item in their cart
    When they click the Delete button
    Then the product is removed from their cart

  • Title: User Can View All Product Categories
    Given a user is viewing any page on the Bangazon site
    When the user clicks on the Product Categories hyperlink
    Then the user will see a view containing a list of all product categories
    And next to the category name, the number of products in that category will be displayed
    And the first three products in the category will be displayed beneath each category, which are hyperlinks to the product detail

Sample:
Electronics (15)
Dryer
HD Television
Sony Walkman

Sporting Goods (7)
Football
Ice skates
Basketball hoop

  • Title:Customers can choose one of their payment types when purchasing their shopping cart
    Given a customer with a shopping cart with products in it
    When placing their order
    Then they should be asked for a payment type
    And they should select a payment type that they have defined

Given a customer with a shopping cart with products in it
And the customer does not have a payment method defined
When placing their order
Then they should be asked to define a payment method

Update Users

As backend developers, we should create a PUT request in case a user wants to update any information about themselves.

User Story

As a user, I need to make updates to my account information.

Acceptance Criteria

When I click "edit profile"
Then I will be taken to a form with all of my information
And be able to make needed changes
Then I will click "submit" to save these updates

Dependencies

#2 #3 #4

Dev Notes

We will want to create a PUT request if we want to update a user -
app.MapPut("/api/users/{id}",

an example of implementing this in Creek River:

app.MapPut("/api/campsites/{id}", (CreekRiverDbContext db, int id, Campsite campsite) =>
{
    Campsite campsiteToUpdate = db.Campsites.SingleOrDefault(campsite => campsite.Id == id);
    if (campsiteToUpdate == null)
    {
        return Results.NotFound();
    }
    campsiteToUpdate.Nickname = campsite.Nickname;
    campsiteToUpdate.CampsiteTypeId = campsite.CampsiteTypeId;
    campsiteToUpdate.ImageUrl = campsite.ImageUrl;

    db.SaveChanges();
    return Results.NoContent();
});

Create Orders

A customer should be able to place/CREATE an order which will require a POST request.

User Story

As a customer, I want to be able to create my order by placing items in my cart and checking out.

Acceptance Criteria

Given the user is authenticated
And the user is viewing their cart
When the user clicks the Order button
Then the user should be presented with a view that allows them to select a payment type for the order
Given the user selects a payment option
When the user clicks the Done button
Then the payment type must be added to the order
And the user will be presented with a confirmation/thank you screen

Dependencies

#2 #3 #4

Dev Notes

In order to allow creation of orders, we will need a POST request.
app.MapPost("/api/orders"...

We will need to edit this to fit the needs of this project, but this is a request from Creek River we can reference:

app.MapPost("/api/campsites", (CreekRiverDbContext db, Campsite campsite) =>
{
    db.Campsites.Add(campsite);
    db.SaveChanges();
    return Results.Created($"/api/campsites/{campsite.Id}", campsite);
});

Read/Get Payment Types

As backend developers, we need to create the endpoints for GETTING payment types.

User Story

As a user, I want to be able to select which payment type I would like to choose when checking out.

Acceptance Criteria

Given a customer with a shopping cart with products in it
When placing their order
Then they should be asked for a payment type
And they should select a payment type that they have defined

Dependencies

#2 #3 #4

Dev Notes

We will need to create an endpoint for GETTING payment types -
app.MapGet("/api/paymentTypes"...

a reference in making this call from Creek River:
app.MapGet("/api/campsites", (CreekRiverDbContext db) => { return db.Campsites.ToList(); });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.