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"
|
||||
)
|
||||
|
||||
type CatagoriesRepository interface {
|
||||
ListCategories(ctx context.Context) ([]models.Category, error)
|
||||
ListCategoriesIDs(ctx context.Context) ([]int16, error)
|
||||
type CatagoriesRepository struct {
|
||||
SQLDB *sql.DB
|
||||
}
|
||||
|
||||
var CatagoriesRepo CatagoriesRepository
|
||||
|
||||
type ConcreteCatagoriesRepository struct {
|
||||
SQLDB *sql.DB
|
||||
}
|
||||
|
||||
func (svc ConcreteCatagoriesRepository) ListCategories(ctx context.Context) ([]models.Category, error) {
|
||||
func (svc CatagoriesRepository) ListCategories(ctx context.Context) ([]models.Category, error) {
|
||||
rows, err := svc.SQLDB.QueryContext(ctx, `SELECT id, name FROM categories ORDER BY name`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -35,7 +30,7 @@ func (svc ConcreteCatagoriesRepository) ListCategories(ctx context.Context) ([]m
|
||||
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`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -8,17 +8,13 @@ import (
|
||||
"thamanyah/cms/v2/internal/models"
|
||||
)
|
||||
|
||||
type VideoRepository interface {
|
||||
CreateVideo(ctx context.Context, v models.Video) (models.Video, error)
|
||||
type VideoRepository struct {
|
||||
SQLDB *sql.DB
|
||||
}
|
||||
|
||||
var VideoRepo VideoRepository
|
||||
|
||||
type ConcreteVideoRepository struct {
|
||||
SQLDB *sql.DB
|
||||
}
|
||||
|
||||
func (svc ConcreteVideoRepository) CreateVideo(ctx context.Context, v models.Video) (models.Video, error) {
|
||||
func (svc VideoRepository) CreateVideo(ctx context.Context, v models.Video) (models.Video, error) {
|
||||
tx, err := svc.SQLDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return models.Video{}, err
|
||||
|
||||
+4
-2
@@ -84,10 +84,12 @@ func runServer() {
|
||||
concreteDBClient := db.CreateDBConnection(requireDBConnectionString())
|
||||
defer db.CloseConnection(concreteDBClient)
|
||||
db.AssertSuccessfulConnection(context.Background(), concreteDBClient)
|
||||
repositories.VideoRepo = &repositories.ConcreteVideoRepository{
|
||||
|
||||
repositories.VideoRepo = repositories.VideoRepository{
|
||||
SQLDB: concreteDBClient,
|
||||
}
|
||||
repositories.CatagoriesRepo = &repositories.ConcreteCatagoriesRepository{
|
||||
|
||||
repositories.CatagoriesRepo = repositories.CatagoriesRepository{
|
||||
SQLDB: concreteDBClient,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user