Skip to content

Commit 4377c5f

Browse files
committed
feat: add comment in module product
1 parent 38a4c42 commit 4377c5f

File tree

16 files changed

+69
-11
lines changed

16 files changed

+69
-11
lines changed

backend/src/main/java/com/smalltrend/controller/products/ProductController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
@RequiredArgsConstructor
3434
public class ProductController {
3535

36+
// REVIEW FLOW: Controller nhận request -> phân quyền @PreAuthorize -> chuyển cho service xử lý nghiệp vụ -> trả response cho frontend.
3637
private final ProductService productService;
3738
private final ProductVariantService productVariantService;
3839
private final UnitConversionService unitConversionService;
@@ -187,6 +188,7 @@ public ResponseEntity<String> deleteUnit(@PathVariable("id") Integer id) {
187188
}
188189

189190
// ─── Variant Prices ──────────────────────────────────────────────────────
191+
// REVIEW FLOW (PRICE): tạo/lấy/cập nhật giá theo variant -> service tự quản lý active/inactive + lịch sử hiệu lực giá.
190192
// Tạo giá mới cho variant (giá cũ chuyển INACTIVE)
191193
@PostMapping("/variants/{variantId}/prices")
192194
@PreAuthorize("hasAnyAuthority('MANAGER','ROLE_MANAGER')")
@@ -271,6 +273,7 @@ public ResponseEntity<java.util.Map<String, Object>> sendPriceExpiryAlertsNow()
271273
));
272274
}
273275

276+
// REVIEW FLOW (PRODUCT CRUD): tạo/cập nhật/toggle/xoá product sẽ gọi ProductService, nơi enforce rule validate + propagate trạng thái xuống variants.
274277
@PostMapping
275278
@PreAuthorize("hasAnyAuthority('MANAGER','ROLE_MANAGER')")
276279
public ResponseEntity<ProductResponse> create(@RequestBody CreateProductRequest request) {

backend/src/main/java/com/smalltrend/service/products/ProductComboServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@RequiredArgsConstructor
3232
public class ProductComboServiceImpl implements ProductComboService {
3333

34+
// REVIEW FLOW: validate combo + items -> chuẩn hoá giá -> kiểm tra giá so với tổng cost -> lưu combo -> lưu danh sách item.
3435
private static final BigDecimal PRICE_ROUND_STEP = BigDecimal.valueOf(100);
3536

3637
private final ProductComboRepository productComboRepository;

backend/src/main/java/com/smalltrend/service/products/ProductServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@RequiredArgsConstructor
2020
public class ProductServiceImpl implements ProductService {
2121

22+
// REVIEW FLOW: validate dữ liệu product -> map request vào entity -> lưu DB -> map response trả về.
2223
private final ProductRepository productRepository;
2324
private final ProductValidator productValidator;
2425

@@ -77,6 +78,7 @@ public ProductResponse create(CreateProductRequest request) {
7778

7879
// Sửa thông tin Sản phẩm đã tồn tại. Nếu cập nhật trạng thái (Active)
7980
// thì thay đổi sẽ áp dụng lan truyền xuống các Biến thể (Variants) con
81+
// REVIEW FLOW (UPDATE): lấy product cũ -> validate tên mới -> apply request -> nếu đổi trạng thái thì propagate xuống variant -> save.
8082
@Override
8183
@Transactional
8284
public ProductResponse update(Integer id, CreateProductRequest request) {

backend/src/main/java/com/smalltrend/service/products/ProductVariantService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
@RequiredArgsConstructor
4040
public class ProductVariantService {
4141

42+
// REVIEW FLOW: validate product/unit/SKU/barcode -> tạo/cập nhật variant -> đồng bộ batch, conversion, stock và dữ liệu giá liên quan.
4243
private final ProductVariantRepository productVariantRepository;
4344
private final UnitRepository unitRepository;
4445
private final InventoryStockRepository inventoryStockRepository;
@@ -87,6 +88,7 @@ public List<ProductVariantRespone> getVariantsByProductId(Integer productId) {
8788
* Tạo mới một variant cho product. Thực hiện đầy đủ validate nghiệp vụ
8889
* trước khi lưu.
8990
*/
91+
// REVIEW FLOW (CREATE): validate product/unit + rule SKU/Barcode/PLU -> dựng entity variant -> lưu variant -> (nếu có) tạo batch giá vốn ban đầu.
9092
public ProductVariantRespone createVariant(Integer productId, CreateVariantRequest request) {
9193
Product product = productVariantValidator.requireExistingProduct(productId);
9294
Unit unit = productVariantValidator.requireExistingUnit(request.getUnitId());
@@ -132,6 +134,7 @@ public ProductVariantRespone createVariant(Integer productId, CreateVariantReque
132134
* Cập nhật thông tin variant hiện có. Nếu có costPrice thì cập nhật batch
133135
* mới nhất hoặc tạo batch mới khi chưa có dữ liệu batch.
134136
*/
137+
// REVIEW FLOW (UPDATE): tìm variant hiện tại -> validate unique/format -> cập nhật trường thay đổi -> đồng bộ costPrice vào batch gần nhất.
135138
public ProductVariantRespone updateVariant(Integer variantId, CreateVariantRequest request) {
136139
ProductVariant variant = productVariantValidator.requireExistingVariant(variantId);
137140
Unit unit = productVariantValidator.requireExistingUnit(request.getUnitId());

backend/src/main/java/com/smalltrend/validation/product/ProductComboValidator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@Component
1717
public class ProductComboValidator {
1818

19+
// REVIEW FLOW: validate tên/giá/items combo -> chặn trùng variant trong cùng combo -> kiểm tra unique tên và mã combo trước khi lưu.
1920
private final ProductComboRepository productComboRepository;
2021
private final ProductVariantRepository productVariantRepository;
2122

backend/src/main/java/com/smalltrend/validation/product/ProductValidator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@RequiredArgsConstructor
1919
public class ProductValidator {
2020

21+
// REVIEW FLOW: đảm bảo tồn tại dữ liệu liên quan (product/category/brand/tax) và chặn vi phạm rule tên trùng hoặc xoá quá 2 phút.
2122
private final ProductRepository productRepository;
2223
private final BrandRepository brandRepository;
2324
private final CategoryRepository categoryRepository;

backend/src/main/java/com/smalltrend/validation/product/ProductVariantValidator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@RequiredArgsConstructor
1717
public class ProductVariantValidator {
1818

19+
// REVIEW FLOW: kiểm tra tồn tại product/unit/variant -> validate format + unique SKU/Barcode/PLU -> chặn activate sai trạng thái product cha.
1920
private final ProductVariantRepository productVariantRepository;
2021
private final ProductRepository productRepository;
2122
private final UnitRepository unitRepository;

frontend/src/pages/Products/ProductManager/AddNewProduct.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ const AddNewProduct = () => {
177177
};
178178

179179
// --- HANDLER SUBMIT TỔNG CHÍNH ---
180+
// REVIEW FLOW: validate form -> upload ảnh (nếu có) -> gọi API tạo product -> điều hướng về list.
180181
const handleSubmit = async (e) => {
181182
e.preventDefault();
182183

frontend/src/pages/Products/ProductManager/AddNewProductVariant.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import api from "../../../config/axiosConfig";
1616
* Hỗ trợ sinh SKU/Barcode tự động, khai báo thuộc tính và cấu hình quy đổi đơn vị.
1717
*/
1818
const AddNewProductVariant = () => {
19+
// REVIEW FLOW: nhập mã/đơn vị/thuộc tính -> (tuỳ chọn) upload ảnh + khai báo quy đổi -> tạo variant -> tạo conversion -> quay về màn detail.
1920
const navigate = useNavigate();
2021
const location = useLocation();
2122
const product = location.state?.product;
@@ -283,6 +284,7 @@ const AddNewProductVariant = () => {
283284
};
284285

285286
// Hàm Submit: Tiến hành Upload image (nếu có) trước rồi lấy URL đính vào payload Variant để Post tạo mới
287+
// REVIEW FLOW (SUBMIT): validate -> upload ảnh -> tạo variant -> nếu có thì tạo conversion -> quay về detail.
286288
const handleSubmit = async (e) => {
287289
e.preventDefault();
288290
setErrorMsg("");

frontend/src/pages/Products/ProductManager/CategoryAndBrand.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useAuth } from "../../../context/AuthContext";
1414
import { canManageProducts } from "../../../utils/roleUtils";
1515

1616
const Category_Brand = () => {
17+
// REVIEW FLOW: chọn tab Category/Brand -> lọc/sắp xếp dữ liệu -> add/edit/delete qua modal -> refresh và hiển thị toast phản hồi.
1718
const { user } = useAuth();
1819
const canEditProducts = canManageProducts(user);
1920
// Trạng thái quản lý điều hướng và modal
@@ -204,7 +205,7 @@ const Category_Brand = () => {
204205
return [...new Set(countries)].sort();
205206
}, [brands, activeTab]);
206207

207-
// Bộ tổng hợp Filter: Chỉ hiện các từ khoá trùng, quốc gia khớp và sắp xếp theo ngày sinh
208+
// REVIEW FLOW (LIST): lấy data theo tab hiện tại -> lọc theo search/country -> sort theo ngày tạo để render bảng.
208209
const filteredData = useMemo(() => {
209210
let filtered = data.filter(item =>
210211
item.name?.toLowerCase()?.includes(searchQuery.toLowerCase())

0 commit comments

Comments
 (0)