The E-Commerce REST API Service is a modular implementation of an e-commerce website's backend, with the aim of showcasing a well-structured modular architecture
- Product Service: Responsible for managing the products available on the website. This includes features like adding, updating, and deleting products, as well as managing product categories and attributes.
- Order Service: Responsible for creating and cancelling orders made by customers.
- Cart Service: Responsible for managing the shopping cart and adding products to it.
- Security Service: Responsible for customer login and authentication.
- Java 17
- Spring Boot 2.7.10
- Postgresql
- Maven
To get started with this project, follow these steps:
- Clone this repository to your local machine.
- Install PostgreSQL and create a database called ecommerce.
- Create these tables in ecommerce database with the following schemas:
CREATE TABLE IF NOT EXISTS public.product ( id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ), description character varying(255) COLLATE pg_catalog."default", name character varying(255) COLLATE pg_catalog."default", price numeric(19,2), quantity integer, CONSTRAINT product_pkey PRIMARY KEY (id) )
CREATE TABLE IF NOT EXISTS public.orders ( id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ), created_at timestamp without time zone, order_status character varying(255) COLLATE pg_catalog."default", total double precision, customer_id bigint, CONSTRAINT orders_pkey PRIMARY KEY (id) )
CREATE TABLE IF NOT EXISTS public.order_item ( id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ), price numeric(19,2), quantity integer, order_id bigint, product_id bigint, CONSTRAINT order_item_pkey PRIMARY KEY (id), CONSTRAINT fkt4dc2r9nbvbujrljv3e23iibt FOREIGN KEY (order_id) REFERENCES public.orders (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION )
CREATE TABLE IF NOT EXISTS public.customer ( id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ), address character varying(255) COLLATE pg_catalog."default", email character varying(255) COLLATE pg_catalog."default", name character varying(255) COLLATE pg_catalog."default", CONSTRAINT customer_pkey PRIMARY KEY (id) )
CREATE TABLE IF NOT EXISTS public.carts ( id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ), created_at timestamp without time zone, cart_status character varying(255) COLLATE pg_catalog."default", total double precision, customer_id bigint, CONSTRAINT carts_pkey PRIMARY KEY (id), CONSTRAINT fk7ltuqgyyak6nuuddwlsy93uje FOREIGN KEY (customer_id) REFERENCES public.customer (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION )
CREATE TABLE IF NOT EXISTS public.cart_items ( id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ), price numeric(19,2), quantity integer, cart_id bigint, product_id bigint, CONSTRAINT cart_items_pkey PRIMARY KEY (id), CONSTRAINT fkl7je3auqyq1raj52qmwrgih8x FOREIGN KEY (product_id) REFERENCES public.product (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT fkpcttvuq4mxppo8sxggjtn5i2c FOREIGN KEY (cart_id) REFERENCES public.carts (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION )
- Update the database configuration in Application properties to match your PostgreSQL database configuration.
- Build and run the project using Maven:
./mvn spring-boot:run
These are some examples of api endpoints
POST localhost:8080/api/order
{
"customerId": 1,
"orderItems": [
{
"productId": 2,
"price": 2000.0,
"quantity": 1
},
{
"productId": 3,
"price": 200.0,
"quantity": 1
}
],
"total": 7000.0
}
PUT localhost:8080/order/1/cancel