Get All Books API #13

Merged
a258wang merged 10 commits from feat/api-all-books into main 1 year ago
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 1 year ago
a258wang requested review from j285he 1 year ago
a258wang requested review from n3parikh 1 year ago
j285he reviewed 1 year ago
lib/books.ts Outdated
}
export interface SimpleBook {
authors: string;
Collaborator

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?
Poster
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.
Collaborator

Agreed, I also used this solution

Agreed, I also used this solution
lib/books.ts Outdated
export interface SimpleBook {
authors: string;
isbn: string;
Collaborator

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 1 year ago
a258wang added 1 commit 1 year ago
j285he approved these changes 1 year ago
a258wang merged commit 2a308e1f37 into main 1 year ago
a258wang referenced this issue from a commit 1 year ago
a258wang deleted branch feat/api-all-books 1 year ago

Reviewers

n3parikh was requested for review 1 year ago
j285he approved these changes 1 year ago
The pull request has been merged as 2a308e1f37.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: www/library#13
Loading…
There is no content yet.