REFACTOR: Deleted Redundant Repo Interfaces
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 2m46s
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 2m46s
This commit is contained in:
@@ -6,18 +6,13 @@ import (
|
|||||||
"thamanyah/cms/v2/internal/models"
|
"thamanyah/cms/v2/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CatagoriesRepository interface {
|
type CatagoriesRepository struct {
|
||||||
ListCategories(ctx context.Context) ([]models.Category, error)
|
SQLDB *sql.DB
|
||||||
ListCategoriesIDs(ctx context.Context) ([]int16, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var CatagoriesRepo CatagoriesRepository
|
var CatagoriesRepo CatagoriesRepository
|
||||||
|
|
||||||
type ConcreteCatagoriesRepository struct {
|
func (svc CatagoriesRepository) ListCategories(ctx context.Context) ([]models.Category, error) {
|
||||||
SQLDB *sql.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc ConcreteCatagoriesRepository) ListCategories(ctx context.Context) ([]models.Category, error) {
|
|
||||||
rows, err := svc.SQLDB.QueryContext(ctx, `SELECT id, name FROM categories ORDER BY name`)
|
rows, err := svc.SQLDB.QueryContext(ctx, `SELECT id, name FROM categories ORDER BY name`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -35,7 +30,7 @@ func (svc ConcreteCatagoriesRepository) ListCategories(ctx context.Context) ([]m
|
|||||||
return categories, rows.Err()
|
return categories, rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc ConcreteCatagoriesRepository) ListCategoriesIDs(ctx context.Context) ([]int16, error) {
|
func (svc CatagoriesRepository) ListCategoriesIDs(ctx context.Context) ([]int16, error) {
|
||||||
rows, err := svc.SQLDB.QueryContext(ctx, `SELECT id FROM categories`)
|
rows, err := svc.SQLDB.QueryContext(ctx, `SELECT id FROM categories`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -8,17 +8,13 @@ import (
|
|||||||
"thamanyah/cms/v2/internal/models"
|
"thamanyah/cms/v2/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VideoRepository interface {
|
type VideoRepository struct {
|
||||||
CreateVideo(ctx context.Context, v models.Video) (models.Video, error)
|
SQLDB *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
var VideoRepo VideoRepository
|
var VideoRepo VideoRepository
|
||||||
|
|
||||||
type ConcreteVideoRepository struct {
|
func (svc VideoRepository) CreateVideo(ctx context.Context, v models.Video) (models.Video, error) {
|
||||||
SQLDB *sql.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc ConcreteVideoRepository) CreateVideo(ctx context.Context, v models.Video) (models.Video, error) {
|
|
||||||
tx, err := svc.SQLDB.BeginTx(ctx, nil)
|
tx, err := svc.SQLDB.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Video{}, err
|
return models.Video{}, err
|
||||||
|
|||||||
+4
-2
@@ -84,10 +84,12 @@ func runServer() {
|
|||||||
concreteDBClient := db.CreateDBConnection(requireDBConnectionString())
|
concreteDBClient := db.CreateDBConnection(requireDBConnectionString())
|
||||||
defer db.CloseConnection(concreteDBClient)
|
defer db.CloseConnection(concreteDBClient)
|
||||||
db.AssertSuccessfulConnection(context.Background(), concreteDBClient)
|
db.AssertSuccessfulConnection(context.Background(), concreteDBClient)
|
||||||
repositories.VideoRepo = &repositories.ConcreteVideoRepository{
|
|
||||||
|
repositories.VideoRepo = repositories.VideoRepository{
|
||||||
SQLDB: concreteDBClient,
|
SQLDB: concreteDBClient,
|
||||||
}
|
}
|
||||||
repositories.CatagoriesRepo = &repositories.ConcreteCatagoriesRepository{
|
|
||||||
|
repositories.CatagoriesRepo = repositories.CatagoriesRepository{
|
||||||
SQLDB: concreteDBClient,
|
SQLDB: concreteDBClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user