Skip to content

Commit 6a0be91

Browse files
adding function to list product
1 parent da38319 commit 6a0be91

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ecomm-api/storer/storer_mysql.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ func (ms *MySQLStorer) GetProduct (ctx context.Context,id int64) (*Product,error
4242
return &p,nil
4343
}
4444

45+
func (ms *MYSQLStorer) ListProducts (ctx context.Context) ([] *Product,error) {
46+
var products []*Product
47+
err := ms.db.SelectContext(ctx, &products, "SELECT * FROM products")
48+
if err != nil {
49+
return nil, fmt.Errorf("error listing products:%w", err)
50+
}
51+
52+
return products, nil
53+
}
54+
4555

0 commit comments

Comments
 (0)