feat: add handlers - WIP

This commit is contained in:
Elton Minetto
2020-06-25 18:03:58 -03:00
parent b9205999f1
commit adc2331b89
13 changed files with 763 additions and 362 deletions
+21 -1
View File
@@ -84,7 +84,27 @@ func (r *MySQLRepo) Search(query string) ([]*Book, error) {
//List users
func (r *MySQLRepo) List() ([]*Book, error) {
return nil, nil
stmt, err := r.db.Prepare(`select id, title, author, pages, quantity, created_at from book`)
if err != nil {
return nil, err
}
var books []*Book
rows, err := stmt.Query()
if err != nil {
return nil, err
}
for rows.Next() {
var b Book
err = rows.Scan(&b.ID, &b.Title, &b.Author, &b.Pages, &b.Quantity, &b.CreatedAt)
if err != nil {
return nil, err
}
books = append(books, &b)
}
if len(books) == 0 {
return nil, domain.ErrNotFound
}
return books, nil
}
//Delete an user