Đã hoàn thiện kết nối Frontend React với Backend Spring Boot, thay thế toàn bộ mock data bằng API thật từ database.
- ✅ Thêm query parameters:
searchvàbarcode - ✅ Endpoint:
GET /api/pos/product?search=coca&barcode=123456
- ✅ Thêm logic tìm kiếm sản phẩm theo tên, SKU, barcode
- ✅ Tích hợp với InventoryStock để lấy số lượng tồn kho
- ✅ Lấy thông tin Category và Brand
- Integer id
- String name
- String sku
- String barcode
- BigDecimal sellPrice
- Integer stockQuantity
- String categoryName
- String brandName- ✅ Thêm query parameter:
phone - ✅ Cho phép CASHIER role truy cập
- ✅ Endpoint:
GET /api/crm/customers?phone=0912345678
- ✅ Thêm logic tìm kiếm khách hàng theo số điện thoại
- ✅ Thêm method:
findByProductVariantId(Integer productVariantId)
// Services for POS operations
- getAllProducts()
- searchProducts(searchTerm)
- getProductByBarcode(barcode)// Services for customer operations
- getAllCustomers()
- searchByPhone(phone)- ✅ Xóa mock data
- ✅ Fetch products từ backend khi component mount
- ✅ Transform data từ backend sang format frontend
- ✅ Tích hợp QR Scanner với API
- ✅ Thêm loading state
Key Changes:
// Before: Mock data
const mockProducts = [...]
// After: Real API
useEffect(() => {
loadProducts();
}, []);
const loadProducts = async () => {
const data = await posService.getAllProducts();
setProducts(transformedData);
};- ✅ Tích hợp customerService
- ✅ Tìm kiếm khách hàng thật từ database
- ✅ Xử lý khách hàng mới vs khách hàng cũ
- ✅ Thêm loading state khi search
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/pos/product |
Lấy tất cả sản phẩm | ADMIN, MANAGER, CASHIER |
| GET | /api/pos/product?search=coca |
Tìm sản phẩm theo tên/SKU | ADMIN, MANAGER, CASHIER |
| GET | /api/pos/product?barcode=123456 |
Tìm sản phẩm theo barcode | ADMIN, MANAGER, CASHIER |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/crm/customers |
Lấy tất cả khách hàng | ADMIN, MANAGER, CASHIER |
| GET | /api/crm/customers?phone=0912 |
Tìm khách hàng theo SĐT | ADMIN, MANAGER, CASHIER |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/login |
Đăng nhập |
| POST | /api/auth/logout |
Đăng xuất |
| GET | /api/auth/validate |
Validate token |
| GET | /api/auth/me |
Lấy thông tin user hiện tại |
Frontend (pos.jsx)
→ posService.getAllProducts()
→ axios GET /api/pos/product
→ ProductVariantController
→ ProductVariantService
→ ProductVariantRepository + InventoryStockRepository
→ Database (product_variants, products, inventory_stocks)
→ Response: List<ProductVariantResponse>
→ Frontend transforms & displays
Frontend (Cart.jsx)
→ customerService.searchByPhone(phone)
→ axios GET /api/crm/customers?phone=xxx
→ CustomerController
→ CustomerService
→ CustomerRepository
→ Database (customers)
→ Response: List<CustomerResponse>
→ Frontend displays customer info
Frontend (QRScanner)
→ Scan barcode
→ posService.getProductByBarcode(barcode)
→ axios GET /api/pos/product?barcode=xxx
→ Backend filters by barcode
→ Response: Product data
→ Add to cart
- Start backend:
cd backend && .\mvnw spring-boot:run - Check health: http://localhost:8081/actuator/health
- Test product API: http://localhost:8081/api/pos/product (with JWT token)
- Test customer API: http://localhost:8081/api/crm/customers (with JWT token)
- Start frontend:
cd frontend && npm run dev - Login with valid credentials
- Check if products load from database
- Test search functionality
- Test customer phone search
- Test QR scanner with barcode
- Test add to cart
- Test checkout flow
cd backend
.\mvnw spring-boot:runBackend runs at: http://localhost:8081
cd frontend
npm install # First time only
npm run devFrontend runs at: http://localhost:5173
- URL: http://localhost:5173/login
- Use credentials from database (users table)
- Default: Check migration files for seed data
- User logs in → POST
/api/auth/login - Backend returns JWT token
- Frontend stores token in localStorage
- All subsequent API calls include:
Authorization: Bearer {token} - Backend validates token via JwtAuthenticationFilter
- If token invalid/expired → 401 → Redirect to login
- CORS: Backend đã config cho phép
localhost:5173,5174,3000 - JWT Token: Tự động thêm vào header bởi axios interceptor
- Error Handling: 401 errors tự động redirect về login
- Data Transform: Backend trả BigDecimal, frontend convert sang Number
- Stock Quantity: Tính tổng từ tất cả locations trong inventory_stocks
- Chưa có API tạo đơn hàng (SalesOrder) - cần implement
- Chưa có API cập nhật điểm khách hàng - cần implement
- Chưa có API trừ tồn kho khi bán - cần implement
- Payment processing vẫn dùng localStorage - cần API
- Implement SalesOrder API (POST /api/pos/orders)
- Implement inventory deduction on sale
- Implement loyalty points update
- Add transaction history API
- Add real-time stock validation
Solution:
- Check backend is running on port 8081
- Check JWT token is valid
- Check database has product data
- Check browser console for errors
Solution:
- Login again to get fresh token
- Check token in localStorage
- Check backend JWT secret matches
Solution:
- Check backend CORS config includes your frontend URL
- Clear browser cache
- Restart backend
Solution:
- Check database has data in
product_variantstable - Run migration scripts if needed
- Check backend logs for SQL errors
controller/pos/ProductVariantController.javaservice/ProductVariantService.javadto/pos/ProductVariantResponse.javacontroller/CustomerController.javaservice/CustomerService.javarepository/InventoryStockRepository.java
services/posService.jsservices/customerService.jspages/Pos/pos.jsxpages/Pos/Cart.jsxconfig/axiosConfig.js
Status: ✅ COMPLETED - Frontend now fully connected to Backend API Date: 2025-01-29 Version: 1.0