videoshop.controller.BossController.java Source code

Java tutorial

Introduction

Here is the source code for videoshop.controller.BossController.java

Source

/*
 * Copyright 2013-2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package videoshop.controller;

import org.salespointframework.inventory.Inventory;
import org.salespointframework.inventory.InventoryItem;
import org.salespointframework.order.Order;
import org.salespointframework.order.OrderManager;
import org.salespointframework.order.OrderStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import videoshop.model.CustomerRepository;

// ()
// Straight forward?

@Controller
@PreAuthorize("hasRole('ROLE_BOSS')")
class BossController {

    private final OrderManager<Order> orderManager;
    private final Inventory<InventoryItem> inventory;
    private final CustomerRepository customerRepository;

    @Autowired
    public BossController(OrderManager<Order> orderManager, Inventory<InventoryItem> inventory,
            CustomerRepository customerRepository) {

        this.orderManager = orderManager;
        this.inventory = inventory;
        this.customerRepository = customerRepository;
    }

    @RequestMapping("/customers")
    public String customers(ModelMap modelMap) {

        modelMap.addAttribute("customerList", customerRepository.findAll());

        return "customers";
    }

    @RequestMapping("/orders")
    public String orders(ModelMap modelMap) {

        modelMap.addAttribute("ordersCompleted", orderManager.find(OrderStatus.COMPLETED));

        return "orders";
    }

    @RequestMapping("/stock")
    public String stock(ModelMap modelMap) {

        modelMap.addAttribute("stock", inventory.findAll());

        return "stock";
    }
}