Changeset f7b963f
- Timestamp:
- 01/08/23 23:00:21 (23 months ago)
- Branches:
- main
- Children:
- 5168b2e
- Parents:
- 7225443
- Location:
- FullyStocked/src/main
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/ArticlesRepository.java
r7225443 rf7b963f 11 11 List<Articles> findAllByArticlenameContainingIgnoreCase(String name); 12 12 List<Articles> findAllByCategoryListContaining(Categories category); 13 List<Articles> findAllBy(); 13 14 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/CategoriesRepository.java
r7225443 rf7b963f 9 9 public interface CategoriesRepository extends JpaRepository<Categories, Integer> { 10 10 List<Categories> findAllByCategorynameContainsIgnoreCase(String name); 11 List<Categories> findAll(); 11 12 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/ArticlesService.java
r7225443 rf7b963f 15 15 Optional<Articles> addToCategory(Integer articleId, Integer categoryId); 16 16 List<Categories> findAllCategoriesByArticle(Integer articleId); 17 List<Articles> findAll(); 17 18 18 19 List<SupplierSuppliesArticleReport> findAllBySupplier(Integer id); -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/ArticlesServiceImpl.java
r7225443 rf7b963f 56 56 Categories category=categoriesRepository.findById(categoryId).orElseThrow(InvalidArgumentsException::new); 57 57 Articles articles=articlesRepository.findById(articleId).orElseThrow(InvalidArgumentsException::new); 58 if(articles.getCategoryList().contains(category)) 59 { 60 return Optional.of(articles); 61 } 58 62 articles.getCategoryList().add(category); 59 63 articlesRepository.save(articles); … … 68 72 69 73 @Override 74 public List<Articles> findAll() { 75 return articlesRepository.findAll(); 76 } 77 78 @Override 70 79 public List<SupplierSuppliesArticleReport> findAllBySupplier(Integer supplierId) { 71 80 return supplierSuppliesArticleRepository.findAllById_Userid(supplierId); -
FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/ArticleController.java
r7225443 rf7b963f 1 1 package com.bazi.fullystocked.Web.Controller; 2 2 3 import com.bazi.fullystocked.Models.Articles; 4 import com.bazi.fullystocked.Models.Categories; 3 5 import com.bazi.fullystocked.Models.Exceptions.InvalidArgumentsException; 4 6 import com.bazi.fullystocked.Services.ArticlesService; 7 import com.bazi.fullystocked.Services.CategoriesService; 5 8 import org.springframework.stereotype.Controller; 6 9 import org.springframework.ui.Model; … … 11 14 12 15 import javax.servlet.http.HttpServletRequest; 16 import java.util.List; 13 17 14 18 @Controller … … 16 20 public class ArticleController { 17 21 private final ArticlesService articlesService; 22 private final CategoriesService categoriesService; 18 23 19 public ArticleController(ArticlesService articlesService ) {24 public ArticleController(ArticlesService articlesService, CategoriesService categoriesService) { 20 25 this.articlesService = articlesService; 26 this.categoriesService = categoriesService; 21 27 } 22 28 … … 27 33 } 28 34 @PostMapping("/create") 29 public String create Invoice(@RequestParam String aname,35 public String createArticle(@RequestParam String aname, 30 36 @RequestParam String opis, 31 37 @RequestParam(required = false) String slika, … … 44 50 45 51 } 46 return "redirect:/homeManager"; 52 return "redirect:/manager"; 53 } 54 @GetMapping("/category/add") 55 private String categoryArticle(Model m) 56 { 57 List<Articles> articlesList=articlesService.findAll(); 58 List<Categories> categories=categoriesService.findAll(); 59 m.addAttribute("articles",articlesList); 60 m.addAttribute("categories",categories); 61 62 63 return "addArticleCategory"; 64 } 65 @PostMapping("/category/add") 66 private String categoryArticle(@RequestParam Integer article, 67 @RequestParam Integer category) 68 { 69 try{ 70 articlesService.addToCategory(article,category); 71 } 72 catch (InvalidArgumentsException e) 73 { 74 return "redirect:/articles/category/add?error="+e.getMessage(); 75 } 76 77 78 return "redirect:/manager"; 47 79 } 48 80 }
Note:
See TracChangeset
for help on using the changeset viewer.