Get All Books API #13

Merged
a258wang merged 10 commits from feat/api-all-books into main 2022-02-23 00:17:03 -05:00
Owner

Closes #2

This PR implements the getAllBooks function that can be used to get summary information about all the books, in order to display them on the main page.

I'm not sure why I waited so long to create this PR, but I suspect that we were blocked by #11 (which has now been merged).

Closes #2 This PR implements the getAllBooks function that can be used to get summary information about all the books, in order to display them on the main page. I'm not sure why I waited so long to create this PR, but I suspect that we were blocked by #11 (which has now been merged).
a258wang added 8 commits 2022-02-15 17:39:28 -05:00
a258wang requested review from j285he 2022-02-15 17:39:54 -05:00
a258wang requested review from n3parikh 2022-02-15 17:40:00 -05:00
j285he reviewed 2022-02-15 22:45:44 -05:00
lib/books.ts Outdated
@ -0,0 +23,4 @@
}
export interface SimpleBook {
authors: string;
Member

There are data rows where authors is NULL, isbn is NULL, and title is NULL. How are we going to handle this?

There are data rows where authors is NULL, isbn is NULL, and title is NULL. How are we going to handle this?
Author
Owner

Good catch! I can think of a couple of ways to handle this:

  1. When dealing with the result from the database query, replace null values with empty strings.
  2. Update the interface to allow these fields to be string | null, and then accomodate for null values appropriately on the "frontend".

I don't really like option 1 because:
a) I feel like the getAllBooks() function should only be responsible for getting the information from the database, and not for performing additional logic on it.
b) Although replacing with an empty string might work for null strings, what would we do for fields that are supposed to be numbers or booleans or another data type?

So I have implemented option 2.

Good catch! I can think of a couple of ways to handle this: 1. When dealing with the result from the database query, replace `null` values with empty strings. 2. Update the interface to allow these fields to be `string | null`, and then accomodate for `null` values appropriately on the "frontend". I don't really like option 1 because: a) I feel like the `getAllBooks()` function should only be responsible for getting the information from the database, and not for performing additional logic on it. b) Although replacing with an empty string might work for null strings, what would we do for fields that are supposed to be numbers or booleans or another data type? So I have implemented option 2.
Member

Agreed, I also used this solution

Agreed, I also used this solution
lib/books.ts Outdated
@ -0,0 +24,4 @@
export interface SimpleBook {
authors: string;
isbn: string;
Member

id is the primary key in the database, do we want that in the interface as well?

`id` is the primary key in the database, do we want that in the interface as well?
Owner

Ya, I think id is worth adding since the permalink for the one book page will probably be based on the ID.

Ya, I think `id` is worth adding since the permalink for the one book page will probably be based on the ID.
a258wang added 1 commit 2022-02-22 22:08:13 -05:00
a258wang added 1 commit 2022-02-22 22:12:40 -05:00
j285he approved these changes 2022-02-22 23:09:09 -05:00
a258wang merged commit 2a308e1f37 into main 2022-02-23 00:17:03 -05:00
a258wang referenced this issue from a commit 2022-02-23 00:17:03 -05:00
a258wang deleted branch feat/api-all-books 2022-02-23 00:17:04 -05:00
Sign in to join this conversation.
No reviewers
No Label
Backend
Frontend
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: www/library#13
No description provided.