REFACTOR: Optimized Catagory IDs INput Validation
This commit is contained in:
@@ -35,6 +35,7 @@ type Video struct {
|
||||
type DBClient interface {
|
||||
CreateVideo(ctx context.Context, v Video) (Video, error)
|
||||
ListCategories(ctx context.Context) ([]Category, error)
|
||||
ListCategoriesIDs(ctx context.Context) ([]int16, error)
|
||||
}
|
||||
|
||||
type DBConcrete struct {
|
||||
@@ -102,6 +103,24 @@ func (svc DBConcrete) ListCategories(ctx context.Context) ([]Category, error) {
|
||||
return categories, rows.Err()
|
||||
}
|
||||
|
||||
func (svc DBConcrete) ListCategoriesIDs(ctx context.Context) ([]int16, error) {
|
||||
rows, err := svc.SQLDB.QueryContext(ctx, `SELECT id FROM categories`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var categories []int16
|
||||
for rows.Next() {
|
||||
var category int16
|
||||
if err := rows.Scan(&category); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
categories = append(categories, category)
|
||||
}
|
||||
return categories, rows.Err()
|
||||
}
|
||||
|
||||
func (svc DBConcrete) Migrate() {
|
||||
if err := db.Migrate(svc.SQLDB); err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user