Update book table to cintain extra info
This commit is contained in:
parent
428213d49f
commit
58e27a38ad
|
@ -7,6 +7,7 @@ use App\Models\Book;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Services\BookInformation\BookLookupService;
|
use App\Services\BookInformation\BookLookupService;
|
||||||
use App\Services\BookInformation\GoogleBooks;
|
use App\Services\BookInformation\GoogleBooks;
|
||||||
|
use Carbon\Carbon;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
@ -74,13 +75,25 @@ class MainController extends Controller {
|
||||||
$res = $service->lookup($item['barcode']);
|
$res = $service->lookup($item['barcode']);
|
||||||
|
|
||||||
if (!empty($res)) {
|
if (!empty($res)) {
|
||||||
if ($thumbnail = data_get('images.thumbnail', $res)) {
|
if ($thumbnail = data_get($res, 'images.thumbnail')) {
|
||||||
$file = $this->downloadFile($thumbnail);
|
$file = $this->downloadFile($thumbnail);
|
||||||
|
|
||||||
$book->attach('thumbnail', $file);
|
$attachment = $book->attach($file, [
|
||||||
|
'key' => 'thumbnail'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$attachment->filename = 'thumbnail.jpg';
|
||||||
|
$attachment->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$book->description = $res->description;
|
||||||
|
$book->published_date = Carbon::parse($res->published_date);
|
||||||
|
$book->pages = $res->pages;
|
||||||
|
$book->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return redirect()->route('locations.show', $location->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,10 @@ class Book extends Model {
|
||||||
'location_id', 'barcode', 'name',
|
'location_id', 'barcode', 'name',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'published_date' => 'datetime:Y-m-d'
|
||||||
|
];
|
||||||
|
|
||||||
public function authors() {
|
public function authors() {
|
||||||
return $this->belongsToMany(Author::class, 'book_authors');
|
return $this->belongsToMany(Author::class, 'book_authors');
|
||||||
}
|
}
|
||||||
|
@ -34,13 +38,24 @@ class Book extends Model {
|
||||||
'properties' => [
|
'properties' => [
|
||||||
'name' => [
|
'name' => [
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
// Also you can configure multi-fields, more details you can find here https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html
|
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'raw' => [
|
'raw' => [
|
||||||
'type' => 'keyword',
|
'type' => 'keyword',
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'description' => [
|
||||||
|
'type' => 'text',
|
||||||
|
'fields' => [
|
||||||
|
'raw' => [
|
||||||
|
'type' => 'keyword',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'published_date' => [
|
||||||
|
'type' => 'date',
|
||||||
|
'format' => 'yyyy-MM-dd'
|
||||||
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ class GoogleBooks implements BookLookupService {
|
||||||
'title' => $volume->getTitle(),
|
'title' => $volume->getTitle(),
|
||||||
'authors' => $volume->getAuthors(),
|
'authors' => $volume->getAuthors(),
|
||||||
'images' => $volume->getImageLinks(),
|
'images' => $volume->getImageLinks(),
|
||||||
|
'description' => $volume->getDescription(),
|
||||||
|
'published_date' => $volume->getPublishedDate(),
|
||||||
|
'pages' => $volume->getPageCount()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class BookExtraInformation extends Migration {
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up() {
|
||||||
|
Schema::table('books', function(Blueprint $table) {
|
||||||
|
$table->text('description')->nullable();
|
||||||
|
$table->date('published_date')->nullable();
|
||||||
|
$table->integer('pages')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down() {
|
||||||
|
Schema::table('books', function(Blueprint $table) {
|
||||||
|
$table->dropColumn([ 'description', 'published_date', 'pages' ]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -6,6 +6,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Authors</th>
|
<th>Authors</th>
|
||||||
|
<th>Actions</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($rows as $row)
|
@foreach ($rows as $row)
|
||||||
|
|
Loading…
Reference in New Issue