package com.utopiaindustries.restcontroller;

import com.utopiaindustries.model.uind.PurchaseOrder;
import com.utopiaindustries.service.PurchaseOrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping( "/rest/purchase-orders" )
public class PurchaseOrderRestController {

    private final PurchaseOrderService purchaseOrderService;

    public PurchaseOrderRestController(PurchaseOrderService purchaseOrderService) {
        this.purchaseOrderService = purchaseOrderService;
    }

    /*
    *  search by term
    * */
    @GetMapping( "/search" )
    public List<PurchaseOrder> findByTerm(@RequestParam("term") String term ) {
        return purchaseOrderService.findByTerm( term );
    }
}
