2020-12-21 07:09:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-12-27 00:34:07 +00:00
|
|
|
use App\Models\Book;
|
|
|
|
use App\Services\BookInformation\BookLookupService;
|
2020-12-21 07:09:34 +00:00
|
|
|
use Cache;
|
|
|
|
|
|
|
|
class LookupController {
|
2020-12-27 00:34:07 +00:00
|
|
|
public function lookup(BookLookupService $service, $isbn) {
|
|
|
|
$result = $service->lookup($isbn);
|
|
|
|
|
|
|
|
$arr = [
|
|
|
|
'success' => false
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$arr = array_merge($arr, [
|
|
|
|
'success' => true,
|
|
|
|
'data' => $result
|
|
|
|
]);
|
2020-12-21 07:09:34 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 00:34:07 +00:00
|
|
|
$book = Book::where('barcode', $isbn)->first();
|
|
|
|
|
|
|
|
if ($book) {
|
|
|
|
$arr['warning'] = 'Item already exists.<br />Location: ' . $book->location->name;
|
|
|
|
}
|
2020-12-21 07:09:34 +00:00
|
|
|
|
2020-12-27 00:34:07 +00:00
|
|
|
return response()->json($arr);
|
2020-12-21 07:09:34 +00:00
|
|
|
}
|
|
|
|
}
|