Add attachments, more pages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -2,20 +2,31 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Book;
|
||||
use App\Services\BookInformation\BookLookupService;
|
||||
use Cache;
|
||||
use App\Services\BookInformation\GoogleBooks;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class LookupController {
|
||||
public function lookup($isbn) {
|
||||
if (!preg_match('/^(\d+)$/', $isbn)) {
|
||||
throw new HttpException(400);
|
||||
public function lookup(BookLookupService $service, $isbn) {
|
||||
$result = $service->lookup($isbn);
|
||||
|
||||
$arr = [
|
||||
'success' => false
|
||||
];
|
||||
|
||||
if ($result) {
|
||||
$arr = array_merge($arr, [
|
||||
'success' => true,
|
||||
'data' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
return Cache::remember('isbn_' . $isbn, 86400, function() use ($isbn) {
|
||||
$google_books = new GoogleBooks();
|
||||
$book = Book::where('barcode', $isbn)->first();
|
||||
|
||||
return $google_books->lookup($isbn);
|
||||
});
|
||||
if ($book) {
|
||||
$arr['warning'] = 'Item already exists.<br />Location: ' . $book->location->name;
|
||||
}
|
||||
|
||||
return response()->json($arr);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user