/**
 * Created by Djidjelly Siclait on 11/26/2016.
 */
package com.evapps.Controller;

import com.evapps.Service.CRUD.CreateDataService;
import com.evapps.Service.CRUD.DeleteDataService;
import com.evapps.Service.CRUD.ReadDataService;
import com.evapps.Service.CRUD.UpdateDataService;
import com.evapps.Tools.Enums.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class AdminController {
    // Services
    @Autowired
    private CreateDataService CDS;
    @Autowired
    private ReadDataService RDS;
    @Autowired
    private UpdateDataService UDS;
    @Autowired
    private DeleteDataService DDS;

    // Gets

    // Gets
    @GetMapping("/admin")
    public ModelAndView index(Model model){
        if (!RDS.isUserLoggedIn())
            return new ModelAndView("redirect:/login");
        model.addAttribute("userRole",RDS.getCurrentLoggedUser().getRole());
        model.addAttribute("user",RDS.getSessionAttr("user"));
        if (RDS.getCurrentLoggedUser().getRole() != Permission.ADMIN)
            model.addAttribute("isAdmin", false);
        else
            model.addAttribute("isAdmin", true);

        return new ModelAndView("/Backend/homepage/index");
    }

    @GetMapping("/admin/inventory")
    public ModelAndView viewInventory(Model model){

        model.addAttribute("selection", RDS.findAllRegisteredProducts());

        return new ModelAndView("");
    }

    @GetMapping("/admin/users")
    public ModelAndView viewUsers(Model model){
        if (!RDS.isUserLoggedIn())
            return new ModelAndView("redirect:/login");

        System.out.println("EL MALDITO SWAG");
        model.addAttribute("userList", RDS.findAllRegisteredAccounts());

        return new ModelAndView("Backend/users/allUsers");
    }



    @GetMapping("/admin/transactions")
    public ModelAndView viewTransactions(Model model){

        model.addAttribute("transactions", RDS.findAllRegisteredTransactions());

        return new ModelAndView("");
    }

    // Posts
    // TODO: registerNewProduct
    // TODO: editProduct
    // TODO: deleteProduct
    // TODO: restockProduct
    // TODO: uploadProductImage
    // TODO: emailUser
    // TODO: suspendUserAccount
    // TODO: makeAdmin
    // TODO: printTransaction
    // TODO: downloadReport
}

@@ -845,21 +845,8 @@
 S;%0A%0A
-    // Gets%0A%0A
     
@@ -915,32 +915,33 @@
 x(Model model)%7B%0A
+%0A
         if (!RDS
@@ -1011,24 +1011,25 @@
 t:/login%22);%0A
+%0A
         mode
@@ -1152,24 +1152,25 @@
 r(%22user%22));%0A
+%0A
         if (
@@ -1488,32 +1488,123 @@
 (Model model)%7B%0A%0A
+        if(!RDS.isUserLoggedIn())%0A            return new ModelAndView(%22redirect:/login%22);%0A%0A
         model.ad
@@ -1786,16 +1786,17 @@
 model)%7B%0A
+%0A
         
@@ -1883,55 +1883,8 @@
 );%0A%0A
-        System.out.println(%22EL MALDITO SWAG%22);%0A
     
@@ -2019,18 +2019,16 @@
 %0A    %7D%0A%0A
-%0A%0A
     @Get
@@ -2106,32 +2106,131 @@
 (Model model)%7B%0A%0A
+        if(!RDS.isUserLoggedIn())%0A            return new ModelAndView(%22redirect:/login%22);%0A        %0A
         model.ad

Add GET force log in protocol in AdminController