separate ans repo for 2 repo, worker and answer, now worker if que type == fie getting file url and content for render img in mailbox
This commit is contained in:
parent
2fd9569574
commit
e1322a679d
@ -31,6 +31,7 @@ type DAL struct {
|
||||
ResultRepo *result.ResultRepository
|
||||
WorkerRepo *workers.WorkerRepository
|
||||
StatisticsRepo *statistics.StatisticsRepository
|
||||
WorkerAnsRepo *answer.WorkerAnswerRepository
|
||||
}
|
||||
|
||||
func New(ctx context.Context, cred string, minioClient *minio.Client) (*DAL, error) {
|
||||
@ -62,12 +63,17 @@ func New(ctx context.Context, cred string, minioClient *minio.Client) (*DAL, err
|
||||
}
|
||||
}
|
||||
|
||||
answerRepo := answer.NewAnswerRepository(answer.Deps{
|
||||
workerAnsRepo := answer.NewWorkerAnswerRepo(answer.Deps{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
AnswerMinio: storerAnswer,
|
||||
})
|
||||
|
||||
answerRepo := answer.NewAnswerRepository(answer.Deps{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
})
|
||||
|
||||
questionRepo := question.NewQuestionRepository(question.Deps{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
@ -102,6 +108,7 @@ func New(ctx context.Context, cred string, minioClient *minio.Client) (*DAL, err
|
||||
ResultRepo: resultRepo,
|
||||
WorkerRepo: workerRepo,
|
||||
StatisticsRepo: statisticsRepo,
|
||||
WorkerAnsRepo: workerAnsRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -15,16 +15,14 @@ type Deps struct {
|
||||
}
|
||||
|
||||
type AnswerRepository struct {
|
||||
queries *sqlcgen.Queries
|
||||
pool *sql.DB
|
||||
answerMinio *StorerAnswer
|
||||
queries *sqlcgen.Queries
|
||||
pool *sql.DB
|
||||
}
|
||||
|
||||
func NewAnswerRepository(deps Deps) *AnswerRepository {
|
||||
return &AnswerRepository{
|
||||
queries: deps.Queries,
|
||||
pool: deps.Pool,
|
||||
answerMinio: deps.AnswerMinio,
|
||||
queries: deps.Queries,
|
||||
pool: deps.Pool,
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,17 +109,6 @@ func (r *AnswerRepository) GetAllAnswersByQuizID(ctx context.Context, session st
|
||||
}
|
||||
|
||||
for _, row := range rows {
|
||||
//todo тут забыл добавить проверку на то что minio !=nil
|
||||
/*if row.Questiontype == model.TypeFile {
|
||||
fmt.Println("GALL", row.Qid, row.QuestionID, row.Content)
|
||||
fileURL, err := r.answerMinio.GetAnswerURL(ctx, row.Qid.UUID.String(), row.QuestionID, row.Content.String)
|
||||
if err != nil {
|
||||
fmt.Println("GetAnswerURL dal answer minio answer", err)
|
||||
return nil, err
|
||||
}
|
||||
row.Content = sql.NullString{String: fmt.Sprintf("%s|%s", fileURL, row.Content.String), Valid: true}
|
||||
}*/
|
||||
|
||||
resultAnswer := model.ResultAnswer{
|
||||
Content: row.Content.String,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
|
55
repository/answer/worker_answer.go
Normal file
55
repository/answer/worker_answer.go
Normal file
@ -0,0 +1,55 @@
|
||||
package answer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
type WorkerAnswerRepository struct {
|
||||
queries *sqlcgen.Queries
|
||||
pool *sql.DB
|
||||
answerMinio *StorerAnswer
|
||||
}
|
||||
|
||||
func NewWorkerAnswerRepo(deps Deps) *WorkerAnswerRepository {
|
||||
return &WorkerAnswerRepository{
|
||||
queries: deps.Queries,
|
||||
pool: deps.Pool,
|
||||
answerMinio: deps.AnswerMinio,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *WorkerAnswerRepository) GetAllAnswersByQuizID(ctx context.Context, session string) ([]model.ResultAnswer, error) {
|
||||
var results []model.ResultAnswer
|
||||
|
||||
rows, err := r.queries.GetAllAnswersByQuizID(ctx, sql.NullString{String: session, Valid: true})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, row := range rows {
|
||||
if row.Questiontype == model.TypeFile && r.answerMinio != nil {
|
||||
fmt.Println("GALL", row.Qid, row.QuestionID, row.Content)
|
||||
fileURL, err := r.answerMinio.GetAnswerURL(ctx, row.Qid.UUID.String(), row.QuestionID, row.Content.String)
|
||||
if err != nil {
|
||||
fmt.Println("GetAnswerURL dal answer minio answer", err)
|
||||
return nil, err
|
||||
}
|
||||
row.Content = sql.NullString{String: fmt.Sprintf("%s|%s", fileURL, row.Content.String), Valid: true}
|
||||
}
|
||||
|
||||
resultAnswer := model.ResultAnswer{
|
||||
Content: row.Content.String,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
QuestionID: uint64(row.QuestionID),
|
||||
AnswerID: uint64(row.ID),
|
||||
}
|
||||
|
||||
results = append(results, resultAnswer)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user