This commit is contained in:
pasha1coil 2025-07-09 14:43:14 +03:00
parent ff8956355f
commit 2dd714b369
2 changed files with 4 additions and 24 deletions

@ -9,7 +9,6 @@ import (
"gitea.pena/SQuiz/common/dal" "gitea.pena/SQuiz/common/dal"
"gitea.pena/SQuiz/common/healthchecks" "gitea.pena/SQuiz/common/healthchecks"
"gitea.pena/SQuiz/common/middleware" "gitea.pena/SQuiz/common/middleware"
"gitea.pena/SQuiz/common/utils"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/skeris/appInit" "github.com/skeris/appInit"
"go.uber.org/zap" "go.uber.org/zap"
@ -47,9 +46,6 @@ type Options struct {
CrtFile string `env:"CRT" default:"server.crt"` CrtFile string `env:"CRT" default:"server.crt"`
KeyFile string `env:"KEY" default:"server.key"` KeyFile string `env:"KEY" default:"server.key"`
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"` PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
RedirectURL string `env:"REDIRECT_URL" default:"https://squiz.pena.digital"`
PubKey string `env:"PUBLIC_KEY"`
PrivKey string `env:"PRIVATE_KEY"`
} }
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) { func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
@ -90,13 +86,9 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
zapLogger.Info("config", zap.Any("options", options)) zapLogger.Info("config", zap.Any("options", options))
encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
svc, err := service.New(service.ServiceDeps{ svc, err := service.New(service.ServiceDeps{
Dal: pgdal, Dal: pgdal,
Encrypt: encrypt, AiClient: clients.NewAiClient("https://alvatar.com/api/engine/send_answer"),
RedirectURl: options.RedirectURL,
AiClient: clients.NewAiClient("https://alvatar.com/api/engine/send_answer"),
}) })
if err != nil { if err != nil {
zapLogger.Error("failed to create service", zap.Error(err)) zapLogger.Error("failed to create service", zap.Error(err))

@ -7,11 +7,9 @@ import (
quizdal "gitea.pena/SQuiz/common/dal" quizdal "gitea.pena/SQuiz/common/dal"
"gitea.pena/SQuiz/common/middleware" "gitea.pena/SQuiz/common/middleware"
"gitea.pena/SQuiz/common/model" "gitea.pena/SQuiz/common/model"
"gitea.pena/SQuiz/common/utils"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"unicode/utf8" "unicode/utf8"
@ -25,19 +23,13 @@ const (
type Service struct { type Service struct {
dal *quizdal.DAL dal *quizdal.DAL
batch []model.Answer
m sync.Mutex
encrypt *utils.Encrypt
redirectURl string
aiClient *clients.AIClient aiClient *clients.AIClient
quizConfigData GetQuizDataResp quizConfigData GetQuizDataResp
} }
type ServiceDeps struct { type ServiceDeps struct {
Dal *quizdal.DAL Dal *quizdal.DAL
Encrypt *utils.Encrypt AiClient *clients.AIClient
RedirectURl string
AiClient *clients.AIClient
} }
func New(deps ServiceDeps) (*Service, error) { func New(deps ServiceDeps) (*Service, error) {
@ -48,10 +40,6 @@ func New(deps ServiceDeps) (*Service, error) {
return &Service{ return &Service{
dal: deps.Dal, dal: deps.Dal,
m: sync.Mutex{},
batch: []model.Answer{},
encrypt: deps.Encrypt,
redirectURl: deps.RedirectURl,
aiClient: deps.AiClient, aiClient: deps.AiClient,
quizConfigData: quizData, quizConfigData: quizData,
}, nil }, nil