feat: rabbitMQ is now calling from seatchtitles
This commit is contained in:
parent
c6cebb0ed2
commit
77a63a1c74
7 changed files with 237 additions and 124 deletions
|
|
@ -5,8 +5,10 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
oapi "nyanimedb/api"
|
||||
"nyanimedb/modules/backend/rmq"
|
||||
sqlc "nyanimedb/sql"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
@ -154,6 +156,29 @@ func (s Server) GetTitle(ctx context.Context, request oapi.GetTitleRequestObject
|
|||
}
|
||||
|
||||
func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObject) (oapi.GetTitlesResponseObject, error) {
|
||||
|
||||
if request.Params.ExtSearch != nil && *request.Params.ExtSearch {
|
||||
// Публикуем событие — как и просили
|
||||
event := rmq.RabbitRequest{
|
||||
Name: "Attack on titans",
|
||||
// Status oapi.TitleStatus `json:"titlestatus,omitempty"`
|
||||
// Rating float64 `json:"titleraring,omitempty"`
|
||||
// Year int32 `json:"year,omitempty"`
|
||||
// Season oapi.ReleaseSeason `json:"season,omitempty"`
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
|
||||
// Контекст с таймаутом (не блокируем ответ)
|
||||
publishCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := s.publisher.Publish(publishCtx, "events.user", event); err != nil {
|
||||
log.Errorf("RMQ publish failed (non-critical): %v", err)
|
||||
} else {
|
||||
log.Infof("RMQ publish succeed %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
opai_titles := make([]oapi.Title, 0)
|
||||
|
||||
word := Word2Sqlc(request.Params.Word)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue