Changeset 3179a2c


Ignore:
Timestamp:
01/10/23 19:27:00 (23 months ago)
Author:
DarkoSasanski <darko.sasanski@…>
Branches:
main
Children:
e341a60
Parents:
aad0fb3
Message:

Minor changes

Location:
FullyStocked/src/main
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • FullyStocked/src/main/java/com/bazi/fullystocked/Models/Exceptions/InvalidArgumentsException.java

    raad0fb3 r3179a2c  
    44
    55    public InvalidArgumentsException() {
    6         super("Invalid arguments exception");
     6        super("Invalid arguments");
    77    }
    88}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Models/Exceptions/InvalidUserCredentialsException.java

    raad0fb3 r3179a2c  
    44
    55    public InvalidUserCredentialsException() {
    6         super("Invalid user credentials exception");
     6        super("Invalid user credentials");
    77    }
    88}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Models/Suppliers.java

    raad0fb3 r3179a2c  
    3535    @NotEmpty(message = "Supplier must have street city")
    3636    private String city;
    37     @ManyToMany(fetch = FetchType.EAGER)
     37    @ManyToMany()
    3838    @JoinTable(name = "supplier_supplies_category",
    3939            joinColumns = @JoinColumn(name = "userid"),
  • FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/SuppliersServiceImpl.java

    raad0fb3 r3179a2c  
    11package com.bazi.fullystocked.Services.Implementations;
    22
     3import com.bazi.fullystocked.Models.Categories;
     4import com.bazi.fullystocked.Models.Exceptions.InvalidArgumentsException;
    35import com.bazi.fullystocked.Models.SqlViews.SuppliersReport;
    46import com.bazi.fullystocked.Models.Suppliers;
     7import com.bazi.fullystocked.Repositories.CategoriesRepository;
    58import com.bazi.fullystocked.Repositories.SuppliersReportRepository;
    69import com.bazi.fullystocked.Repositories.SuppliersRepository;
     
    811import org.springframework.stereotype.Service;
    912
     13import javax.transaction.Transactional;
    1014import java.util.List;
    1115import java.util.Optional;
     
    4044        return suppliersRepository.findById(id);
    4145    }
     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    }
    4253}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Services/SuppliersService.java

    raad0fb3 r3179a2c  
    11package com.bazi.fullystocked.Services;
    22
     3import com.bazi.fullystocked.Models.Categories;
    34import com.bazi.fullystocked.Models.SqlViews.SuppliersReport;
    45import com.bazi.fullystocked.Models.Suppliers;
     
    1112    List<SuppliersReport> findAllSuppliersReport();
    1213    Optional<Suppliers> findById(Integer id);
     14    List<Categories> findCategoriesBySupplier(Integer id);
    1315}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/LoginController.java

    raad0fb3 r3179a2c  
    1313import org.springframework.web.bind.annotation.PostMapping;
    1414import org.springframework.web.bind.annotation.RequestMapping;
     15import org.springframework.web.bind.annotation.RequestParam;
    1516
    1617import javax.servlet.http.HttpServletRequest;
     
    2829
    2930    @GetMapping
    30     public String getLoginPage(Model m) {
     31    public String getLoginPage(Model m, @RequestParam(required = false) String error) {
    3132        m.addAttribute("bodycontent","login");
    32 
     33        m.addAttribute("error", error);
    3334        return "/login";
    3435    }
     
    6162            return "redirect:/home";
    6263        }
    63         catch (InvalidUserCredentialsException exception) {
    64             model.addAttribute("hasError", true);
    65             model.addAttribute("error", exception.getMessage());
     64        catch (Exception exception) {
    6665
    67             return "redirect:/login";
     66            return "redirect:/login?error="+exception.getMessage();
    6867        }
    6968    }
  • FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/RegisterController.java

    raad0fb3 r3179a2c  
    2525    public String getRegisterPage(@RequestParam(required = false) String error, Model model)
    2626    {
     27        model.addAttribute("error", error);
    2728        return "register";
    2829    }
     
    4647            return "redirect:/login";
    4748        }
    48         catch (UsernameAlreadyExistsException | InvalidArgumentsException exception)
     49        catch (Exception exception)
    4950        {
    5051            return "redirect:/register?error="+exception.getMessage();
     
    6970            return "redirect:/login";
    7071        }
    71         catch (UsernameAlreadyExistsException | InvalidArgumentsException exception)
     72        catch (Exception exception)
    7273        {
     74            request.getSession().invalidate();
    7375            return "redirect:/register?error="+exception.getMessage();
    7476        }
  • FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/SupplierController.java

    raad0fb3 r3179a2c  
    11package com.bazi.fullystocked.Web.Controller;
    22
    3 import com.bazi.fullystocked.Models.Categories;
    43import com.bazi.fullystocked.Models.Suppliers;
     4import com.bazi.fullystocked.Services.SuppliersService;
    55import org.springframework.stereotype.Controller;
    66import org.springframework.ui.Model;
     
    99
    1010import javax.servlet.http.HttpServletRequest;
    11 import java.util.List;
    1211
    1312@Controller
    1413@RequestMapping(value ="/supplier")
    1514public class SupplierController {
     15    private final SuppliersService suppliersService;
     16
     17    public SupplierController(SuppliersService suppliersService) {
     18        this.suppliersService = suppliersService;
     19    }
     20
    1621    @GetMapping
    1722    public String getSupplierPage()
     
    2429    {
    2530        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()));
    2832        return "supplierCategories";
    2933    }
  • FullyStocked/src/main/resources/templates/login.html

    raad0fb3 r3179a2c  
    2525                    <button type="submit" class="btn btn-primary btn-lg btn-block">Најави се</button>
    2626
     27                    <div class="form-outline mt-3 text-danger" th:if="${error!=null}">
     28                        <th:block th:text="${error}"></th:block>
     29                    </div>
    2730
    2831
  • FullyStocked/src/main/resources/templates/register.html

    raad0fb3 r3179a2c  
    1414
    1515                <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>
    1620
    1721                <form class="mx-1 mx-md-4" method="POST" action="/register">
     
    7074                  </div>
    7175
     76
    7277                </form>
    7378                <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.