This commit is contained in:
2026-04-13 08:10:14 +03:00
commit a4455b1170
18 changed files with 1063 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
package repository
import "log/slog"
// NotificationDB — интерфейс базы данных, который нужен NotificationRepo.
type NotificationDB interface {
Query(query string) error
Exec(query string) error
BulkInsert(query string, args ...any) error
}
// NotificationRepo — интерфейс репозитория уведомлений.
type NotificationRepo interface{}
// notificationRepo — конкретная реализация, скрыта от внешних пакетов.
type notificationRepo struct {
db NotificationDB
}
// NewNotificationRepo создаёт репозиторий уведомлений.
func NewNotificationRepo(db NotificationDB) NotificationRepo {
slog.Info("репозиторий уведомлений создан")
return &notificationRepo{db: db}
}
+31
View File
@@ -0,0 +1,31 @@
package repository
import "log/slog"
// SessionDB — интерфейс базы данных, который нужен SessionRepo.
type SessionDB interface {
Query(query string) error
Exec(query string) error
BeginTx() error
}
// SessionCache — интерфейс кэша, который нужен SessionRepo.
type SessionCache interface {
Get(key string) (string, error)
Set(key, value string) error
}
// SessionRepo — интерфейс репозитория сессий.
type SessionRepo interface{}
// sessionRepo — конкретная реализация, скрыта от внешних пакетов.
type sessionRepo struct {
db SessionDB
cache SessionCache
}
// NewSessionRepo создаёт репозиторий сессий.
func NewSessionRepo(db SessionDB, cache SessionCache) SessionRepo {
slog.Info("репозиторий сессий создан")
return &sessionRepo{db: db, cache: cache}
}
+24
View File
@@ -0,0 +1,24 @@
package repository
import "log/slog"
// UserDB — интерфейс базы данных, который нужен UserRepo.
type UserDB interface {
Query(query string) error
QueryRow(query string) error
Exec(query string) error
}
// UserRepo — интерфейс репозитория пользователей.
type UserRepo interface{}
// userRepo — конкретная реализация, скрыта от внешних пакетов.
type userRepo struct {
db UserDB
}
// NewUserRepo создаёт репозиторий пользователей.
func NewUserRepo(db UserDB) UserRepo {
slog.Info("репозиторий пользователей создан")
return &userRepo{db: db}
}