RonAsis / Wsep202

Trading system Is a system that enables trading infrastructure between sellers and buyers.
1 stars 0 forks source link

fix addProduct(...) in TradingSystemFacade #241

Closed noyasi closed 4 years ago

noyasi commented 4 years ago

I added a check to make sure that amount and cost aren't negative:

public ProductDto addProduct(@NotBlank String ownerUsername, int storeId, @NotBlank String productName, @NotBlank String category, int amount, double cost, UUID uuid) { try { if (cost<0 || amount<0) { log.error("cost and amount can't be negative"); return null; } UserSystem user = tradingSystem.getUser(ownerUsername, uuid); //get registered user with ownerUsername Store ownerStore = user.getOwnerOrManagerWithPermission(storeId, StorePermission.EDIT_PRODUCT); //verify he owns store with storeId //convert to a category we can add to the product ProductCategory productCategory = ProductCategory.getProductCategory(category); Product product = factoryObjects.createProduct(productName, productCategory, amount, cost, storeId); Product productRes = tradingSystemDao.addProductToStore(ownerStore, user, product); return Objects.nonNull(productRes) ? modelMapper.map(productRes, ProductDto.class) : null; } catch (TradingSystemException e) { log.error("add product failed", e); return null; } }

MoranNeptune commented 4 years ago

fixed