File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments