Changeset 3179a2c
- Timestamp:
- 01/10/23 19:27:00 (2 years ago)
- Branches:
- main
- Children:
- e341a60
- Parents:
- aad0fb3
- Location:
- FullyStocked/src/main
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/src/main/java/com/bazi/fullystocked/Models/Exceptions/InvalidArgumentsException.java
raad0fb3 r3179a2c 4 4 5 5 public InvalidArgumentsException() { 6 super("Invalid arguments exception");6 super("Invalid arguments"); 7 7 } 8 8 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Models/Exceptions/InvalidUserCredentialsException.java
raad0fb3 r3179a2c 4 4 5 5 public InvalidUserCredentialsException() { 6 super("Invalid user credentials exception");6 super("Invalid user credentials"); 7 7 } 8 8 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Models/Suppliers.java
raad0fb3 r3179a2c 35 35 @NotEmpty(message = "Supplier must have street city") 36 36 private String city; 37 @ManyToMany( fetch = FetchType.EAGER)37 @ManyToMany() 38 38 @JoinTable(name = "supplier_supplies_category", 39 39 joinColumns = @JoinColumn(name = "userid"), -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/SuppliersServiceImpl.java
raad0fb3 r3179a2c 1 1 package com.bazi.fullystocked.Services.Implementations; 2 2 3 import com.bazi.fullystocked.Models.Categories; 4 import com.bazi.fullystocked.Models.Exceptions.InvalidArgumentsException; 3 5 import com.bazi.fullystocked.Models.SqlViews.SuppliersReport; 4 6 import com.bazi.fullystocked.Models.Suppliers; 7 import com.bazi.fullystocked.Repositories.CategoriesRepository; 5 8 import com.bazi.fullystocked.Repositories.SuppliersReportRepository; 6 9 import com.bazi.fullystocked.Repositories.SuppliersRepository; … … 8 11 import org.springframework.stereotype.Service; 9 12 13 import javax.transaction.Transactional; 10 14 import java.util.List; 11 15 import java.util.Optional; … … 40 44 return suppliersRepository.findById(id); 41 45 } 46 47 @Override 48 @Transactional 49 public List<Categories> findCategoriesBySupplier(Integer id) { 50 Suppliers supplier=suppliersRepository.findById(id).orElseThrow(InvalidArgumentsException::new); 51 return supplier.getCategoryList(); 52 } 42 53 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/SuppliersService.java
raad0fb3 r3179a2c 1 1 package com.bazi.fullystocked.Services; 2 2 3 import com.bazi.fullystocked.Models.Categories; 3 4 import com.bazi.fullystocked.Models.SqlViews.SuppliersReport; 4 5 import com.bazi.fullystocked.Models.Suppliers; … … 11 12 List<SuppliersReport> findAllSuppliersReport(); 12 13 Optional<Suppliers> findById(Integer id); 14 List<Categories> findCategoriesBySupplier(Integer id); 13 15 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/LoginController.java
raad0fb3 r3179a2c 13 13 import org.springframework.web.bind.annotation.PostMapping; 14 14 import org.springframework.web.bind.annotation.RequestMapping; 15 import org.springframework.web.bind.annotation.RequestParam; 15 16 16 17 import javax.servlet.http.HttpServletRequest; … … 28 29 29 30 @GetMapping 30 public String getLoginPage(Model m ) {31 public String getLoginPage(Model m, @RequestParam(required = false) String error) { 31 32 m.addAttribute("bodycontent","login"); 32 33 m.addAttribute("error", error); 33 34 return "/login"; 34 35 } … … 61 62 return "redirect:/home"; 62 63 } 63 catch (InvalidUserCredentialsException exception) { 64 model.addAttribute("hasError", true); 65 model.addAttribute("error", exception.getMessage()); 64 catch (Exception exception) { 66 65 67 return "redirect:/login ";66 return "redirect:/login?error="+exception.getMessage(); 68 67 } 69 68 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/RegisterController.java
raad0fb3 r3179a2c 25 25 public String getRegisterPage(@RequestParam(required = false) String error, Model model) 26 26 { 27 model.addAttribute("error", error); 27 28 return "register"; 28 29 } … … 46 47 return "redirect:/login"; 47 48 } 48 catch ( UsernameAlreadyExistsException | InvalidArgumentsException exception)49 catch (Exception exception) 49 50 { 50 51 return "redirect:/register?error="+exception.getMessage(); … … 69 70 return "redirect:/login"; 70 71 } 71 catch ( UsernameAlreadyExistsException | InvalidArgumentsException exception)72 catch (Exception exception) 72 73 { 74 request.getSession().invalidate(); 73 75 return "redirect:/register?error="+exception.getMessage(); 74 76 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/SupplierController.java
raad0fb3 r3179a2c 1 1 package com.bazi.fullystocked.Web.Controller; 2 2 3 import com.bazi.fullystocked.Models.Categories;4 3 import com.bazi.fullystocked.Models.Suppliers; 4 import com.bazi.fullystocked.Services.SuppliersService; 5 5 import org.springframework.stereotype.Controller; 6 6 import org.springframework.ui.Model; … … 9 9 10 10 import javax.servlet.http.HttpServletRequest; 11 import java.util.List;12 11 13 12 @Controller 14 13 @RequestMapping(value ="/supplier") 15 14 public class SupplierController { 15 private final SuppliersService suppliersService; 16 17 public SupplierController(SuppliersService suppliersService) { 18 this.suppliersService = suppliersService; 19 } 20 16 21 @GetMapping 17 22 public String getSupplierPage() … … 24 29 { 25 30 Suppliers s= (Suppliers) request.getSession().getAttribute("user"); 26 List<Categories> categoriesList=s.getCategoryList(); 27 m.addAttribute("categoires",categoriesList); 31 m.addAttribute("categoires",suppliersService.findCategoriesBySupplier(s.getUserid())); 28 32 return "supplierCategories"; 29 33 } -
FullyStocked/src/main/resources/templates/login.html
raad0fb3 r3179a2c 25 25 <button type="submit" class="btn btn-primary btn-lg btn-block">Најави се</button> 26 26 27 <div class="form-outline mt-3 text-danger" th:if="${error!=null}"> 28 <th:block th:text="${error}"></th:block> 29 </div> 27 30 28 31 -
FullyStocked/src/main/resources/templates/register.html
raad0fb3 r3179a2c 14 14 15 15 <p class="text-center h1 fw-bold mb-5 mx-1 mx-md-4 mt-4">Регистрација</p> 16 17 <div class="d-flex justify-content-center mx-4 mb-3 mb-lg-4 text-danger" th:if="${error!=null}"> 18 <th:block th:text="${error}"> 19 </div> 16 20 17 21 <form class="mx-1 mx-md-4" method="POST" action="/register"> … … 70 74 </div> 71 75 76 72 77 </form> 73 78 <p class="d-flex justify-content-center">Веќе имаш профил? <a href="/login" class="link-info"> Најави сe тука!</a></p>
Note:
See TracChangeset
for help on using the changeset viewer.