Skip to content

Commit 18c4bbd

Browse files
committed
fix: support using API's media type if present in batch scanner
1 parent 7e41d0b commit 18c4bbd

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

lib/fuzzy_catalog_web/controllers/book_controller.ex

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,14 @@ defmodule FuzzyCatalogWeb.BookController do
390390
case Catalog.find_book_by_title_and_author(title, author) do
391391
nil ->
392392
# Step 4: Book doesn't exist, create it
393-
# Determine media type from suggested types or use the provided one
393+
# Determine media type based on user selection
394394
determined_media_type =
395-
case determine_media_type(book_params) do
396-
"unspecified" -> media_type
397-
suggested_type -> suggested_type
395+
if media_type == "automatic" do
396+
# Use API-suggested media type, or "unspecified" if not available
397+
determine_media_type(book_params)
398+
else
399+
# Use the user's explicit selection
400+
media_type
398401
end
399402

400403
final_params =
@@ -411,7 +414,7 @@ defmodule FuzzyCatalogWeb.BookController do
411414
title: book.title,
412415
author: book.author,
413416
isbn: isbn,
414-
media_type: media_type
417+
media_type: determined_media_type
415418
}
416419
})
417420

lib/fuzzy_catalog_web/controllers/book_html/batch_scanner.html.heex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@
4545
<span class="label-text-alt text-xs">Applied to new books</span>
4646
</label>
4747
<select id="default-media-type" class="select select-bordered w-full">
48+
<option value="automatic" selected>Automatic (from API)</option>
4849
<option value="unspecified">Unspecified</option>
49-
<option value="hardcover" selected>Hardcover</option>
50+
<option value="hardcover">Hardcover</option>
5051
<option value="paperback">Paperback</option>
5152
<option value="audiobook">Audiobook</option>
5253
<option value="ebook">eBook</option>
5354
</select>
55+
<label class="label">
56+
<span class="label-text-alt text-xs text-base-content/60">
57+
"Automatic" uses API-detected format or "Unspecified" if not found
58+
</span>
59+
</label>
5460
</div>
5561

5662
<!-- Control Buttons -->

test/fuzzy_catalog/catalog/providers/hardcover_provider_test.exs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,23 @@ defmodule FuzzyCatalog.Catalog.Providers.HardcoverProviderTest do
203203
assert nil == HardcoverProvider.__format_series__([])
204204
end
205205

206-
test "extracts first series name from map" do
207-
series = [%{"name" => "The Stormlight Archive"}]
206+
test "extracts first series name from nested structure" do
207+
series = [%{"series" => %{"name" => "The Stormlight Archive"}}]
208208
assert "The Stormlight Archive" == HardcoverProvider.__format_series__(series)
209209
end
210210

211211
test "extracts first series name when multiple exist" do
212-
series = [%{"name" => "The Stormlight Archive"}, %{"name" => "Another Series"}]
212+
series = [
213+
%{"series" => %{"name" => "The Stormlight Archive"}},
214+
%{"series" => %{"name" => "Another Series"}}
215+
]
216+
213217
assert "The Stormlight Archive" == HardcoverProvider.__format_series__(series)
214218
end
215219

216-
test "extracts first series name from string list" do
217-
series = ["The Stormlight Archive", "Another Series"]
218-
assert "The Stormlight Archive" == HardcoverProvider.__format_series__(series)
220+
test "handles malformed series data gracefully" do
221+
series = [%{"name" => "The Stormlight Archive"}]
222+
assert nil == HardcoverProvider.__format_series__(series)
219223
end
220224

221225
test "returns nil for unexpected format" do

0 commit comments

Comments
 (0)