From 348dd6480ccf196b78c017ad7080b54df6d5ec2b Mon Sep 17 00:00:00 2001 From: Chamath Dilshan <150304779+ChamathDilshanC@users.noreply.github.com> Date: Sun, 16 Feb 2025 08:17:36 +0530 Subject: [PATCH 01/13] Create README.md --- README.md | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..edc96f7 --- /dev/null +++ b/README.md @@ -0,0 +1,196 @@ +# 🛍️ Spring Boot E-Commerce Core API + +A modern, scalable e-commerce backend API built with Spring Boot, featuring comprehensive order management, customer tracking, and inventory control. + +## ✨ Features + +- **Customer Management**: Track and manage customer profiles and preferences +- **Inventory Control**: Real-time stock management and updates +- **Order Processing**: Complete order lifecycle management with transaction support +- **RESTful API**: Modern API design following REST principles +- **Security**: Robust authentication and authorization (customizable) +- **Database**: JPA/Hibernate with transaction management +- **Documentation**: Swagger/OpenAPI integration + +## 🚀 Tech Stack + +- **Java 17** +- **Spring Boot 3.x** +- **Spring Data JPA** +- **MySQL Database** +- **Maven** +- **Hibernate** + +## 📋 Prerequisites + +- JDK 17 or later +- Maven 3.6+ +- MySQL 8.0+ +- Your favorite IDE (IntelliJ IDEA recommended) + +## 🛠️ Installation & Setup + +1. **Clone the repository** + ```bash + git clone https://github.com/yourusername/spring-boot-ecommerce.git + cd spring-boot-ecommerce + ``` + +2. **Configure MySQL** + ```properties + # Update application.properties + spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce_db + spring.datasource.username=your_username + spring.datasource.password=your_password + ``` + +3. **Build the project** + ```bash + mvn clean install + ``` + +4. **Run the application** + ```bash + mvn spring-boot:run + ``` + +## 🌐 API Endpoints + +### Customer Management +``` +GET /api/v1/customer - Get all customers +POST /api/v1/customer - Create new customer +PUT /api/v1/customer - Update customer +DELETE /api/v1/customer/{id} - Delete customer +``` + +### Inventory Management +``` +GET /api/v1/item - Get all items +POST /api/v1/item - Add new item +PUT /api/v1/item - Update item +DELETE /api/v1/item/{code} - Delete item +``` + +### Order Management +``` +POST /api/v1/order/save - Create new order +``` + +## 📦 Sample Request Objects + +### Create Order +```json +{ + "orderId": "ORD001", + "orderDate": "2024-02-15T14:30:00", + "customerId": "C001", + "orderDetails": [ + { + "itemCode": "ITM001", + "quantity": 2, + "unitPrice": 1500.00 + } + ], + "total": 3000.00 +} +``` + +## 🛡️ Security Configuration + +Basic configuration is included but should be customized for production: + +```java +@Configuration +@EnableWebSecurity +public class SecurityConfig { + // Add your security configuration here +} +``` + +## 📊 Database Schema + +### Core Tables +- `customer` - Customer information +- `item` - Product inventory +- `orders` - Order headers +- `order_detail` - Order line items + +## 🔧 Project Structure + +``` +src/ +├── main/ +│ ├── java/ +│ │ └── lk.ijse.spring_boot/ +│ │ ├── controller/ +│ │ ├── dto/ +│ │ ├── entity/ +│ │ ├── repo/ +│ │ ├── service/ +│ │ └── Application.java +│ └── resources/ +│ └── application.properties +└── test/ + └── java/ +``` + +## ⚙️ Configuration + +Key application properties: + +```properties +# Server Configuration +server.port=8080 +server.servlet.context-path=/api + +# Database Configuration +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true + +# Swagger/OpenAPI +springdoc.api-docs.path=/api-docs +``` + +## 🧪 Testing + +Run tests using Maven: + +```bash +mvn test +``` + +## 📈 Future Improvements + +- [ ] Add payment gateway integration +- [ ] Implement caching +- [ ] Add event-driven architecture +- [ ] Implement rate limiting +- [ ] Add metrics and monitoring +- [ ] Containerize with Docker + +## 🤝 Contributing + +1. Fork the project +2. Create your feature branch +3. Commit your changes +4. Push to the branch +5. Open a Pull Request + +## 📝 License + +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details. + +## 👥 Authors + +- **Chamath Dilshan** - *Initial work* - [My Github ❤️](https://github.com/ChamathDilshanC) + +## 🙏 Acknowledgments + +- Spring Boot team for the amazing framework +- The open-source community + +## 📧 Contact + +- Email: dilshancolonne123@gmail.com.com +- LinkedIn: [My Linkedin ❤️](https://www.linkedin.com/in/chamathdilsahnc/) From 475509dee5037fbb4def98d6c334ec0f3088ebcc Mon Sep 17 00:00:00 2001 From: Chamath Date: Sun, 16 Feb 2025 08:30:10 +0530 Subject: [PATCH 02/13] commit --- .idea/vcs.xml | 6 ++++++ .../main/java/lk/ijse/spring_boot/service/OrderService.java | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/13_Spring_Boot/src/main/java/lk/ijse/spring_boot/service/OrderService.java b/13_Spring_Boot/src/main/java/lk/ijse/spring_boot/service/OrderService.java index c369d38..35350a9 100644 --- a/13_Spring_Boot/src/main/java/lk/ijse/spring_boot/service/OrderService.java +++ b/13_Spring_Boot/src/main/java/lk/ijse/spring_boot/service/OrderService.java @@ -35,9 +35,12 @@ public boolean saveOrder(OrderDTO orderDTO) { return false; } + //Optional කියන්නේ Java 8 එක්ක හඳුන්වා දුන් object එකක්. මේක හදලා තියෙන්නේ null values හැසිරවීම වඩාත් ආරක්ෂිත විදිහට කරන්න. + // පාරිභෝගිකයා ඉන්නවද කියලා check කරනවා Optional customer = customerRepo.findById(orderDTO.getCustomerId()); if (customer.isEmpty()) { return false; + // පාරිභෝගිකයා නැත්නම් order එක save කරන්න බෑ } List orderDetails = new ArrayList<>(); @@ -47,6 +50,7 @@ public boolean saveOrder(OrderDTO orderDTO) { if (item.isEmpty()) { return false; + // Item එක නැත්නම් order එක save කරන්න බෑ } Item itemEntity = item.get(); From cb0f7b3ffc2fd4e738a1d05522b57868ff456053 Mon Sep 17 00:00:00 2001 From: Chamath Date: Thu, 20 Feb 2025 12:52:38 +0530 Subject: [PATCH 03/13] Updated Commit --- .idea/compiler.xml | 9 +- .idea/encodings.xml | 2 + .idea/misc.xml | 1 + 13_Spring_Boot.zip | Bin 27315 -> 51301 bytes 13_Spring_Boot/pom.xml | 5 + .../Controller/CustomerController.java | 33 +- .../Controller/ItemController.java | 31 +- .../Controller/OrderController.java | 17 +- .../ijse/spring_boot/Repo/CustomerRepo.java | 11 +- .../lk/ijse/spring_boot/Repo/OrderRepo.java | 3 +- .../advicer/AppWideExeptionHandler.java | 15 + .../ijse/spring_boot/config/WebAppConfig.java | 13 + .../spring_boot/service/CustomerService.java | 58 +- .../service/Impl/CustomerServiceImpl.java | 57 ++ .../service/Impl/ItemServiceImpl.java | 56 ++ .../service/Impl/OrderServiceImpl.java | 80 +++ .../ijse/spring_boot/service/ItemService.java | 35 +- .../spring_boot/service/OrderService.java | 82 +-- .../ijse/spring_boot/util/ResponseUtil.java | 53 ++ 14_Springboot_Frontend/pom.xml | 17 + .../src/main/java/lk/ijse/Item.html | 446 ++++++++++++++ .../src/main/java/lk/ijse/customer.html | 438 ++++++++++++++ .../src/main/java/lk/ijse/dashboard.html | 276 +++++++++ .../src/main/java/lk/ijse/js/customer.js | 240 ++++++++ .../src/main/java/lk/ijse/js/item.js | 260 ++++++++ .../main/java/lk/ijse/js/jquery-3.7.1.min.js | 2 + .../src/main/java/lk/ijse/js/order.js | 445 ++++++++++++++ .../src/main/java/lk/ijse/order.html | 556 ++++++++++++++++++ 28 files changed, 3039 insertions(+), 202 deletions(-) create mode 100644 13_Spring_Boot/src/main/java/lk/ijse/spring_boot/advicer/AppWideExeptionHandler.java create mode 100644 13_Spring_Boot/src/main/java/lk/ijse/spring_boot/config/WebAppConfig.java create mode 100644 13_Spring_Boot/src/main/java/lk/ijse/spring_boot/service/Impl/CustomerServiceImpl.java create mode 100644 13_Spring_Boot/src/main/java/lk/ijse/spring_boot/service/Impl/ItemServiceImpl.java create mode 100644 13_Spring_Boot/src/main/java/lk/ijse/spring_boot/service/Impl/OrderServiceImpl.java create mode 100644 13_Spring_Boot/src/main/java/lk/ijse/spring_boot/util/ResponseUtil.java create mode 100644 14_Springboot_Frontend/pom.xml create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/Item.html create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/customer.html create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/dashboard.html create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/js/customer.js create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/js/item.js create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/js/jquery-3.7.1.min.js create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/js/order.js create mode 100644 14_Springboot_Frontend/src/main/java/lk/ijse/order.html diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 13f3e99..a72619f 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -9,15 +9,16 @@ - + + + + + - - - diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 36f1451..e3a0c87 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -20,6 +20,8 @@ + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 04fe76a..51413d7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -20,6 +20,7 @@