Changeset f08836b
- Timestamp:
- 01/06/23 15:24:07 (2 years ago)
- Branches:
- main
- Children:
- 5f69a70
- Parents:
- e440971
- Location:
- FullyStocked/src/main/java/com/bazi/fullystocked
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/InvoicedArticlesRepository.java
re440971 rf08836b 12 12 List<InvoicedArticles> findAllByArticle(Articles article); 13 13 List<InvoicedArticles> findAllByInvoice(Invoices invoice); 14 List<InvoicedArticles> findAllByInvoiceAndArticle(Invoices invoice, Articles article);14 Optional<InvoicedArticles> findByInvoiceAndArticle(Invoices invoice, Articles article); 15 15 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/OrderedArticlesRepository.java
re440971 rf08836b 14 14 List<OrderedArticles> findAllByArticle(Articles article); 15 15 List<OrderedArticles> findAllByLocation(Locations location); 16 List<OrderedArticles> findAllByLocationAndArticleAndArticlestatus(Locations location, Articles article, ArticleStatus status); 16 17 List<OrderedArticles> findAllByOrder(Orders order); 17 List<OrderedArticles> findAllByOrderAndArticle(Orders order, Articles article);18 Optional<OrderedArticles> findByOrderAndArticle(Orders order, Articles article); 18 19 List<OrderedArticles> findAllByArticlestatus(ArticleStatus status); 19 20 List<OrderedArticles> findAllByLocationAndArticlestatus(Locations location, ArticleStatus status); -
FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/StoredArticlesRepository.java
re440971 rf08836b 11 11 List<StoredArticles> findAllByLocations(Locations location); 12 12 List<StoredArticles> findAllByArticle(Articles article); 13 List<StoredArticles> findAllByArticleAndLocations(Articles article, Locations location);13 Optional<StoredArticles> findByArticleAndLocations(Articles article, Locations location); 14 14 List<StoredArticles> findAllByLocationsAndQuantityIsLessThanEqual(Locations location, int quantity); 15 15 List<StoredArticles> findAllByLocationsAndQuantity(Locations location, int quantity); -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/InvoicesServiceImpl.java
re440971 rf08836b 1 1 package com.bazi.fullystocked.Services.Implementations; 2 2 3 import com.bazi.fullystocked.Models.Articles; 3 import com.bazi.fullystocked.Models.*; 4 import com.bazi.fullystocked.Models.Exceptions.ArticleAlreadyInInvoiceException; 5 import com.bazi.fullystocked.Models.Exceptions.ArticleNotAvailableException; 4 6 import com.bazi.fullystocked.Models.Exceptions.InvalidArgumentsException; 5 import com.bazi.fullystocked.Models.InvoicedArticles; 6 import com.bazi.fullystocked.Models.Invoices; 7 import com.bazi.fullystocked.Models.Workers; 8 import com.bazi.fullystocked.Repositories.ArticlesRepository; 9 import com.bazi.fullystocked.Repositories.InvoicedArticlesRepository; 10 import com.bazi.fullystocked.Repositories.InvoicesRepository; 11 import com.bazi.fullystocked.Repositories.WorkersRepository; 7 import com.bazi.fullystocked.Repositories.*; 12 8 import com.bazi.fullystocked.Services.InvoicesService; 13 9 import org.springframework.stereotype.Service; … … 22 18 private final WorkersRepository workersRepository; 23 19 private final ArticlesRepository articlesRepository; 20 private final StoredArticlesRepository storedArticlesRepository; 24 21 25 public InvoicesServiceImpl(InvoicedArticlesRepository invoicedArticlesRepository, InvoicesRepository invoicesRepository, WorkersRepository workersRepository, ArticlesRepository articlesRepository ) {22 public InvoicesServiceImpl(InvoicedArticlesRepository invoicedArticlesRepository, InvoicesRepository invoicesRepository, WorkersRepository workersRepository, ArticlesRepository articlesRepository, StoredArticlesRepository storedArticlesRepository) { 26 23 this.invoicedArticlesRepository = invoicedArticlesRepository; 27 24 this.invoicesRepository = invoicesRepository; 28 25 this.workersRepository = workersRepository; 29 26 this.articlesRepository = articlesRepository; 27 this.storedArticlesRepository = storedArticlesRepository; 30 28 } 31 29 … … 47 45 Invoices invoice = invoicesRepository.findById(invoiceId).orElseThrow(InvalidArgumentsException::new); 48 46 Articles article = articlesRepository.findById(articleId).orElseThrow(InvalidArgumentsException::new); 47 if(invoicedArticlesRepository.findByInvoiceAndArticle(invoice, article).isPresent()) 48 { 49 throw new ArticleAlreadyInInvoiceException(); 50 } 49 51 if(price<=0 || quantity<=0) 50 52 { 51 53 throw new InvalidArgumentsException(); 54 } 55 StoredArticles storedArticle=storedArticlesRepository.findByArticleAndLocations(article, invoice.getWorker().getLocation()).orElseThrow(InvalidArgumentsException::new); 56 if(quantity>storedArticle.getQuantity()) 57 { 58 throw new ArticleNotAvailableException(); 52 59 } 53 60 InvoicedArticles invoicedArticles=new InvoicedArticles(price, quantity, invoice, article); -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/OrdersServiceImpl.java
re440971 rf08836b 5 5 import com.bazi.fullystocked.Models.Enumerations.OrderPriority; 6 6 import com.bazi.fullystocked.Models.Enumerations.OrderStatus; 7 import com.bazi.fullystocked.Models.Exceptions.ArticleAlreadyInOrderException; 8 import com.bazi.fullystocked.Models.Exceptions.ArticleMaxQuantityException; 7 9 import com.bazi.fullystocked.Models.Exceptions.InvalidArgumentsException; 8 10 import com.bazi.fullystocked.Repositories.*; … … 55 57 @Transactional 56 58 public Optional<Orders> addArticleToOrder(int quantity, Integer locationId, Integer articleId, Integer orderId) { 59 Locations location=locationsRepository.findById(locationId).orElseThrow(InvalidArgumentsException::new); 60 Articles article=articlesRepository.findById(articleId).orElseThrow(InvalidArgumentsException::new); 61 Orders order=ordersRepository.findById(orderId).orElseThrow(InvalidArgumentsException::new); 62 if(orderedArticlesRepository.findByOrderAndArticle(order, article).isPresent()) 63 { 64 throw new ArticleAlreadyInOrderException(); 65 } 57 66 if(quantity<=0) 58 67 { 59 68 throw new InvalidArgumentsException(); 60 69 } 61 Locations location=locationsRepository.findById(locationId).orElseThrow(InvalidArgumentsException::new); 62 Articles article=articlesRepository.findById(articleId).orElseThrow(InvalidArgumentsException::new); 63 Orders order=ordersRepository.findById(orderId).orElseThrow(InvalidArgumentsException::new); 70 int quantityAlreadyOrdered=orderedArticlesRepository.findAllByLocationAndArticleAndArticlestatus(location, article, ArticleStatus.ORDERED). 71 stream().mapToInt(OrderedArticles::getQuantity).sum()+ 72 orderedArticlesRepository.findAllByLocationAndArticleAndArticlestatus(location, article, ArticleStatus.DELIVERED). 73 stream().mapToInt(OrderedArticles::getQuantity).sum(); 74 if(article.getMaxquantityperlocation()<quantityAlreadyOrdered+quantity) 75 { 76 throw new ArticleMaxQuantityException(); 77 } 64 78 OrderedArticles orderedArticles=orderedArticlesRepository.save(new OrderedArticles(quantity, order, location, article)); 65 79 order.getArticlesList().add(orderedArticles); -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/StoredArticlesServiceImpl.java
re440971 rf08836b 49 49 throw new InvalidArgumentsException(); 50 50 } 51 StoredArticles storedArticle=storedArticlesRepository.find AllByArticleAndLocations(orderedArticle.getArticle(), orderedArticle.getLocation()).get(0);51 StoredArticles storedArticle=storedArticlesRepository.findByArticleAndLocations(orderedArticle.getArticle(), orderedArticle.getLocation()).orElseThrow(InvalidArgumentsException::new); 52 52 storedArticle.setQuantity(storedArticle.getQuantity()+ orderedArticle.getQuantity()); 53 53 orderedArticle.setArticlestatus(ArticleStatus.PROCESSED);
Note:
See TracChangeset
for help on using the changeset viewer.