This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\WebService\Almoxarifado\ConectaSus;
|
||||
|
||||
use App\Exceptions\WebService\Almoxarifado\ConectaSus\FornecedorNotFoundException;
|
||||
use App\Models\Cadastro\Fornecedor\Fornecedor;
|
||||
use App\Services\Service;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FornecedorService extends Service
|
||||
{
|
||||
public static function index()
|
||||
{
|
||||
return DB::table('cadastro_fornecedor AS fornecedor')
|
||||
->select([
|
||||
'fornecedor.id',
|
||||
'fornecedor.nome_fantasia AS nome',
|
||||
'fornecedor.cnpj',
|
||||
])
|
||||
->orderBy('fornecedor.nome_fantasia')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function show($id)
|
||||
{
|
||||
$fornecedor = self::getFornecedorModel($id);
|
||||
|
||||
return (object) [
|
||||
'id' => $fornecedor->id,
|
||||
'nome' => $fornecedor->nome_fantasia,
|
||||
'cnpj' => $fornecedor->cnpj,
|
||||
];
|
||||
}
|
||||
|
||||
private static function getFornecedorModel($id)
|
||||
{
|
||||
$fornecedor = Fornecedor::find($id);
|
||||
|
||||
if (is_null($fornecedor)) {
|
||||
|
||||
throw new FornecedorNotFoundException();
|
||||
}
|
||||
|
||||
return $fornecedor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user