|
|
@@ -5,15 +5,17 @@ import (
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"os"
|
|
|
- "saura/src/server/db/repo"
|
|
|
+ repoClient "saura/src/server/db/repo/client"
|
|
|
+ repoUser "saura/src/server/db/repo/user"
|
|
|
"sync"
|
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
)
|
|
|
|
|
|
type DB struct {
|
|
|
- db *sql.DB
|
|
|
- clientsRepo *repo.ClientRepo
|
|
|
+ db *sql.DB
|
|
|
+ clientRepo *repoClient.ClientRepo
|
|
|
+ userRepo *repoUser.UserRepo
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
@@ -39,7 +41,8 @@ func (ctx *DB) Init() error {
|
|
|
return fmt.Errorf("failed to connect to database: %w", err)
|
|
|
}
|
|
|
|
|
|
- ctx.clientsRepo = repo.NewClientRepo(ctx.db, dbURL)
|
|
|
+ ctx.clientRepo = repoClient.NewClientRepo(ctx.db, dbURL)
|
|
|
+ ctx.userRepo = repoUser.NewUserRepo(ctx.db, dbURL)
|
|
|
|
|
|
log.Println("Database initialized successfully")
|
|
|
return nil
|
|
|
@@ -52,68 +55,10 @@ func (ctx *DB) Close() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (ctx *DB) GetClientRepo() *repo.ClientRepo {
|
|
|
- return ctx.clientsRepo
|
|
|
+func (ctx *DB) GetClientRepo() *repoClient.ClientRepo {
|
|
|
+ return ctx.clientRepo
|
|
|
}
|
|
|
|
|
|
-func (ctx *DB) FetchMarks() ([]string, error) {
|
|
|
- query := `
|
|
|
- SELECT id, name
|
|
|
- FROM marks
|
|
|
- `
|
|
|
- rows, err := ctx.db.Query(query)
|
|
|
- if err != nil {
|
|
|
- return nil, fmt.Errorf("failed to execute query: %w", err)
|
|
|
- }
|
|
|
- defer rows.Close()
|
|
|
-
|
|
|
- var marks []string
|
|
|
-
|
|
|
- for rows.Next() {
|
|
|
- var id string
|
|
|
- var name string
|
|
|
-
|
|
|
- if err := rows.Scan(&id, &name); err != nil {
|
|
|
- return nil, fmt.Errorf("failed to scan row: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
- marks = append(marks, name)
|
|
|
- }
|
|
|
-
|
|
|
- if err := rows.Err(); err != nil {
|
|
|
- return nil, fmt.Errorf("error during iteration: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
- return marks, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (ctx *DB) FetchAdChannels() ([]string, error) {
|
|
|
- query := `
|
|
|
- SELECT id, name
|
|
|
- FROM ad_channels
|
|
|
- `
|
|
|
- rows, err := ctx.db.Query(query)
|
|
|
- if err != nil {
|
|
|
- return nil, fmt.Errorf("failed to execute query: %w", err)
|
|
|
- }
|
|
|
- defer rows.Close()
|
|
|
-
|
|
|
- var ad_channels []string
|
|
|
-
|
|
|
- for rows.Next() {
|
|
|
- var id string
|
|
|
- var name string
|
|
|
-
|
|
|
- if err := rows.Scan(&id, &name); err != nil {
|
|
|
- return nil, fmt.Errorf("failed to scan row: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
- ad_channels = append(ad_channels, name)
|
|
|
- }
|
|
|
-
|
|
|
- if err := rows.Err(); err != nil {
|
|
|
- return nil, fmt.Errorf("error during iteration: %w", err)
|
|
|
- }
|
|
|
-
|
|
|
- return ad_channels, nil
|
|
|
+func (ctx *DB) GetUserRepo() *repoUser.UserRepo {
|
|
|
+ return ctx.userRepo
|
|
|
}
|