add service
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m44s
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m44s
This commit is contained in:
@@ -29,7 +29,7 @@ type InviteService interface {
|
||||
}
|
||||
|
||||
type RequestService interface {
|
||||
CreateTZ(ctx context.Context, userID int, requestTxt string) (uuid.UUID, string, error)
|
||||
CreateTZ(ctx context.Context, userID int, requestTxt string, fileData []byte, fileName string) (uuid.UUID, string, error)
|
||||
ApproveTZ(ctx context.Context, requestID uuid.UUID, tzText string, userID int) ([]*model.Supplier, error)
|
||||
GetMailingList(ctx context.Context, userID int) ([]*model.Request, error)
|
||||
GetMailingListByID(ctx context.Context, requestID uuid.UUID, userID int) (*model.RequestDetail, error)
|
||||
|
||||
@@ -2,12 +2,14 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/ai"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/fileparser"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
@@ -42,21 +44,37 @@ func NewRequestService(
|
||||
}
|
||||
}
|
||||
|
||||
func (s *requestService) CreateTZ(ctx context.Context, userID int, requestTxt string) (uuid.UUID, string, error) {
|
||||
func (s *requestService) CreateTZ(ctx context.Context, userID int, requestTxt string, fileData []byte, fileName string) (uuid.UUID, string, error) {
|
||||
combinedText := requestTxt
|
||||
|
||||
if len(fileData) > 0 && fileName != "" {
|
||||
fileContent, err := fileparser.ExtractText(fileData, fileName)
|
||||
if err != nil {
|
||||
return uuid.Nil, "", err
|
||||
}
|
||||
if fileContent != "" {
|
||||
if combinedText != "" {
|
||||
combinedText = fmt.Sprintf("%s\n\nСодержимое файла (%s):\n%s", combinedText, fileName, fileContent)
|
||||
} else {
|
||||
combinedText = fmt.Sprintf("Содержимое файла (%s):\n%s", fileName, fileContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
req := &model.Request{
|
||||
UserID: userID,
|
||||
RequestTxt: requestTxt,
|
||||
RequestTxt: combinedText,
|
||||
}
|
||||
|
||||
if err := s.requestRepo.Create(ctx, req); err != nil {
|
||||
return uuid.Nil, "", err
|
||||
}
|
||||
|
||||
if requestTxt == "" {
|
||||
if combinedText == "" {
|
||||
return req.ID, "", nil
|
||||
}
|
||||
|
||||
tzText, err := s.openAI.GenerateTZ(requestTxt)
|
||||
tzText, err := s.openAI.GenerateTZ(combinedText)
|
||||
if err != nil {
|
||||
if err := s.requestRepo.UpdateWithTZ(ctx, req.ID, "", false); err != nil {
|
||||
return req.ID, "", err
|
||||
|
||||
Reference in New Issue
Block a user