FEAT: Load Catagories from backend
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 2m11s
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 2m11s
This commit is contained in:
@@ -29,6 +29,7 @@ type Video struct {
|
||||
|
||||
type DBClient interface {
|
||||
CreateVideo(ctx context.Context, v Video) (Video, error)
|
||||
ListCategories(ctx context.Context) ([]string, error)
|
||||
}
|
||||
|
||||
type DBConcrete struct {
|
||||
@@ -81,6 +82,30 @@ func (svc DBConcrete) CreateVideo(ctx context.Context, v Video) (Video, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (svc DBConcrete) ListCategories(ctx context.Context) ([]string, error) {
|
||||
sqlDB, err := sql.Open("postgres", svc.ConnectionString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer sqlDB.Close()
|
||||
|
||||
rows, err := sqlDB.QueryContext(ctx, `SELECT name FROM categories ORDER BY name`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var categories []string
|
||||
for rows.Next() {
|
||||
var name string
|
||||
if err := rows.Scan(&name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
categories = append(categories, name)
|
||||
}
|
||||
return categories, rows.Err()
|
||||
}
|
||||
|
||||
func (svc DBConcrete) Migrate() {
|
||||
sqlDB, err := sql.Open("postgres", svc.ConnectionString)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user