Add attachments, more pages
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tyler
2020-12-26 19:34:07 -05:00
parent d086b29bcc
commit a1ac81a73a
29 changed files with 2349 additions and 17899 deletions

View File

@ -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);
}
}