added repos method for new gigachat queries
This commit is contained in:
parent
3db6e9ead6
commit
dd71e1b671
@ -41,7 +41,7 @@ var EmptyResponseErrorGigaChat = errors.New("empty response from GigaChat try ag
|
||||
|
||||
type GigaChatAudience struct {
|
||||
ID int64 `json:"id"`
|
||||
QuizID int32 `json:"quiz_id"`
|
||||
QuizID int64 `json:"quiz_id"`
|
||||
Sex bool `json:"sex"` // false - female, true - male
|
||||
Age string `json:"age"`
|
||||
Deleted bool `json:"deleted"`
|
||||
|
@ -6,10 +6,10 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||
"gitea.pena/SQuiz/common/model"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"strings"
|
||||
"sync"
|
||||
@ -651,3 +651,50 @@ func (r *QuizRepository) TemplateCopy(ctx context.Context, accountID, qID string
|
||||
|
||||
return quizID, nil
|
||||
}
|
||||
|
||||
type DepsCreateQuizAudience struct {
|
||||
QuizID int64 `json:"quiz_id"`
|
||||
Sex bool `json:"sex"` // false - female, true - male
|
||||
Age string `json:"age"`
|
||||
}
|
||||
|
||||
func (r *QuizRepository) CreateQuizAudience(ctx context.Context, audience DepsCreateQuizAudience) (int64, error) {
|
||||
result, err := r.queries.CreateQuizAudience(ctx, sqlcgen.CreateQuizAudienceParams{
|
||||
Quizid: audience.QuizID,
|
||||
Sex: audience.Sex,
|
||||
Age: audience.Age,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *QuizRepository) GetQuizAudience(ctx context.Context, quizID int64) ([]model.GigaChatAudience, error) {
|
||||
rows, err := r.queries.GetQuizAudience(ctx, quizID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var audiences []model.GigaChatAudience
|
||||
for _, row := range rows {
|
||||
audiences = append(audiences, model.GigaChatAudience{
|
||||
ID: row.ID,
|
||||
QuizID: row.ID,
|
||||
Sex: row.Sex,
|
||||
Age: row.Age,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat.Time.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
return audiences, nil
|
||||
}
|
||||
|
||||
func (r *QuizRepository) DeleteQuizAudience(ctx context.Context, quizID int64) error {
|
||||
err := r.queries.DeleteQuizAudience(ctx, quizID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user