Skip to content

jamesjiayu/ECom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ECom Application README

This project is a Spring Boot-based e-commerce application named ECom. It provides a backend API for managing users, products, orders, and user details. The application utilizes JPA for database interactions and Spring Security for authentication and authorization.

Project Structure

The project is structured as follows:

  • EComApplication.java:
    • The main Spring Boot application entry point.
  • beans:
    • Contains the Java classes representing the data models (entities) for the application.
    • Order.java: Represents an order placed by a user.
    • OrderProduct.java: Represents a product within an order.
    • Product.java: Represents a product available for purchase.
    • User.java: Represents a user of the application.
    • UserDetail.java: Represents detailed information about a user.
    • UserProfile.java: Represents user roles or profiles.
  • controllers:
    • Contains the REST controllers that handle incoming HTTP requests and define the API endpoints.
  • dao:
    • Contains the Data Access Objects (DAOs) or repositories for database interactions.
  • handler:
    • Contains classes for handling specific aspects of the application (e.g., custom exception handling).
  • http:
    • Contains classes related to HTTP request and response handling.
  • security:
    • Contains classes related to Spring Security configuration.
  • service:
    • Contains the business logic services that interact with the DAOs and perform operations.

Data Models (Beans)

Order.java

  • Represents an order with properties such as id, purchase_date, purchases (list of OrderProduct), and user.
  • Uses JPA annotations for entity mapping and relationships (e.g., @Entity, @Table, @Id, @GeneratedValue, @OneToMany, @ManyToOne).
  • @JsonFormat is used to format the purchase_date in "yyyy-MM-dd" format.

OrderProduct.java

  • Represents a product within an order with properties such as id, quantity, order, and product.
  • Uses JPA annotations for entity mapping and relationships (e.g., @Entity, @Table, @Id, @GeneratedValue, @ManyToOne).
  • @JsonIgnoreProperties is used to prevent infinite recursion during JSON serialization.

Product.java

  • Represents a product with properties such as id, name, brand, price, stock, and image.
  • Uses JPA annotations for entity mapping and validation constraints (e.g., @Entity, @Table, @Id, @GeneratedValue, @NotEmpty, @Positive, @PositiveOrZero).

User.java

  • Represents a user with properties such as id, username, password, profiles (list of UserProfile), and userDetail.
  • Implements UserDetails for Spring Security integration.
  • Uses JPA annotations for entity mapping and relationships (e.g., @Entity, @Table, @Id, @GeneratedValue, @ManyToMany, @OneToOne).
  • Includes methods for Spring Security authentication and authorization.

UserDetail.java

  • Represents detailed information about a user with properties such as id, name, phone, email, address1, address2, state, city, zipcode, and user.
  • Uses JPA annotations for entity mapping and relationships (e.g., @Entity, @Table, @Id, @GeneratedValue, @OneToOne).

UserProfile.java

  • Represents user roles or profiles with properties such as id and type.
  • Implements GrantedAuthority for Spring Security integration.
  • Uses JPA annotations for entity mapping (e.g., @Entity, @Table, @Id).

Key Concepts

  • JPA (Java Persistence API): Used for object-relational mapping, allowing Java objects to be persisted to a relational database.
  • Spring Security: Used for authentication and authorization, providing security features for the application.
  • REST Controllers: Handle HTTP requests and define the API endpoints for the application.
  • DAOs (Data Access Objects): Interact with the database to perform CRUD operations.
  • Services: Implement the business logic of the application.
  • Validation Constraints: Used to enforce data integrity and validation rules.
  • JSON Serialization/Deserialization: Used to convert Java objects to and from JSON format for HTTP requests and responses.

Notes

  • The Order class has a one-to-many relationship with OrderProduct, indicating that an order can have multiple products.
  • The User class has a one-to-one relationship with UserDetail, indicating that each user has one user detail.
  • The User class has a many-to-many relationship with UserProfile, indicating that a user can have multiple roles or profiles.
  • The @JsonIgnore and @JsonIgnoreProperties annotations are used to prevent infinite recursion during JSON serialization.
  • The allocationSize attribute in @SequenceGenerator is used to specify the increment size for sequence-based ID generation.

Future Enhancements

  • Implement more robust error handling and validation.
  • Add unit and integration tests.
  • Implement caching for improved performance.
  • Add support for different payment gateways.
  • Implement a frontend for the application.
  • Add more detailed documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages