Skip to content

Commit 74220f1

Browse files
committed
Allow overriding the file path for the books JSON file locally. Resolve a nullable chain code smell in the UI.
1 parent d8adf73 commit 74220f1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

api/Services/BookService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public ICollection<Book> GetBooks()
3636
private ICollection<Book> LoadBooks()
3737
{
3838
// try and load from the book JSON data source (it will be readonly until we have a database backing the service).
39-
var path = Environment.GetEnvironmentVariable("HOME") + @"\site\wwwroot\books.json";
39+
// locally, we can force the location of the file path using `ForceBooksFilePath` in `local.settings.json`.
40+
// when running in a Function app, use the recommended path.
41+
var path = Environment.GetEnvironmentVariable("ForceBooksFilePath") ??
42+
Environment.GetEnvironmentVariable("HOME") + @"\site\wwwroot\books.json";
4043
var books = JsonSerializer
4144
.Deserialize<ICollection<Book>>(File.ReadAllText(path)) ?? new List<Book>();
4245

ui/src/app/pages/landing-page/landing-page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<p-table
33
#libraryTable
44
[globalFilterFields]="['title', 'author', 'shelfLocation']"
5-
[value]="library().books ?? []"
5+
[value]="library().books"
66
class="w-full"
77
dataKey="title">
88
<ng-template #caption>

0 commit comments

Comments
 (0)