Skip to content

Commit 9e1c6a8

Browse files
committed
Find All Data Updating
1 parent da72a29 commit 9e1c6a8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

book/response.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package book
2+
3+
type BookResponse struct {
4+
ID int `json:"id"`
5+
Title string `json:"title"`
6+
Description string `json:"description"`
7+
Price int `json:"price"`
8+
Rating int `json:"rating"`
9+
Discount int `json:"discount"`
10+
}

handler/book.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,23 @@ func (h *bookHandler) GetBooks(c *gin.Context) {
2626
})
2727
}
2828

29+
var booksResponse []book.BookResponse
30+
31+
for _, b := range books {
32+
bookResponse := book.BookResponse{
33+
ID: b.ID,
34+
Title: b.Title,
35+
Price: b.Price,
36+
Description: b.Description,
37+
Rating: b.Rating,
38+
Discount: b.Discount,
39+
}
40+
41+
booksResponse = append(booksResponse, bookResponse)
42+
}
43+
2944
c.JSON(http.StatusOK, gin.H{
30-
"data": books,
45+
"data": booksResponse,
3146
})
3247
}
3348

0 commit comments

Comments
 (0)