REFACTOR: Optimized Catagory IDs INput Validation
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 2m47s
Deploy Infrastructure / pulumi-up (push) Failing after 26s

This commit is contained in:
FahdShalhoub
2026-08-17 01:17:08 +03:00
parent 56a2992206
commit b77afbfed6
4 changed files with 82 additions and 41 deletions
+19
View File
@@ -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)