package com.chantha.springdemo.controller;

import com.chantha.springdemo.model.Product;
import com.chantha.springdemo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class MainController {

    @Autowired
    private  final ProductService productService;

    public MainController(ProductService productService) {
        this.productService=productService;
    }
    @RequestMapping("/")
    public String indexPage(Model mod){
        mod.addAttribute("products",productService.findAllProduct());
        return "index";
    }

    @RequestMapping("/admin")
    public String adminPage(Model model){
       List<Product> products=productService.findAllProduct();
       model.addAttribute("products",products);
       return "admin/admin";
    }

    @RequestMapping("/dba")
    public String dbaPage(){
        return "dba/dba";
    }

    @RequestMapping("/user")
    public String userPage(){
        return "user/user";
    }
}
