Skip to content

Commit

Permalink
error response for get title
Browse files Browse the repository at this point in the history
  • Loading branch information
GarbhanK committed May 24, 2024
1 parent 036ae8c commit 2e5c0de
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions controllers/books.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ func CreateBook(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"data": book})
}

// GET /books/:title
// Find a book
// GET /books/title/
// Find a specific book
func FindBook(c *gin.Context) {

// parse out author name in query params
log.Printf("title query param %v", c.Query("title"))
title, err := c.GetQuery("title")
if err == false {
log.Printf("No title provided...")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "No title parameter provided"})
return
}

Expand All @@ -127,9 +127,9 @@ func FindBook(c *gin.Context) {
// array of books to return
var bookDocs []models.Book

// iterator over books collection in firestore
// iterate over books collection in firestore
iter := client.Collection("books").Where("Title", "==", title).Documents(ctx)
defer iter.Stop() // add to clean up resources
defer iter.Stop() // clean up resources

// loop until all documents matching title are added to books array
for {
Expand All @@ -154,18 +154,6 @@ func FindBook(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"data": bookDocs})
}

// // Validate Input
// var input models.UpdateBookInput
// if err := c.ShouldBindJSON(&input); err != nil {
// c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

// models.DB.Model(&book).Updates(input)

// c.JSON(http.StatusOK, gin.H{"data": book})
// }

func FindAuthor(c *gin.Context) {

// parse out author name in query params
Expand Down

0 comments on commit 2e5c0de

Please sign in to comment.