This commit is contained in:
parent
7af3f682b8
commit
811783e1c4
@ -116,7 +116,7 @@ type ErrorCreateIndex struct {
|
||||
}
|
||||
|
||||
func (d *DAL) CreateMessageIndex(ctx context.Context) error {
|
||||
keys := bson.D{{"$**", "text"}}
|
||||
keys := bson.D{{Key: "$**", Value: "text"}}
|
||||
|
||||
opts := options.Index().SetDefaultLanguage("russian")
|
||||
|
||||
@ -130,7 +130,7 @@ func (d *DAL) CreateMessageIndex(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (d *DAL) CreateTicketIndex(ctx context.Context) error {
|
||||
keys := bson.D{{"$**", "text"}}
|
||||
keys := bson.D{{Key: "$**", Value: "text"}}
|
||||
|
||||
opts := options.Index().SetDefaultLanguage("russian")
|
||||
|
||||
@ -144,7 +144,7 @@ func (d *DAL) CreateTicketIndex(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (d *DAL) CreateAccountIndex(ctx context.Context) error {
|
||||
keys := bson.D{{"$**", "text"}}
|
||||
keys := bson.D{{Key: "$**", Value: "text"}}
|
||||
|
||||
opts := options.Index().SetDefaultLanguage("russian")
|
||||
|
||||
@ -249,7 +249,7 @@ func (d *DAL) CreateTicket(
|
||||
ctx context.Context,
|
||||
userID,
|
||||
sessionID,
|
||||
origin,
|
||||
origin,
|
||||
title, message string,
|
||||
files []string,
|
||||
) (string, error) {
|
||||
@ -265,7 +265,7 @@ func (d *DAL) CreateTicket(
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
Rate: -1,
|
||||
Origin: origin,
|
||||
Origin: origin,
|
||||
TopMessage: model.Message{
|
||||
ID: xid.New().String(),
|
||||
UserID: userID,
|
||||
@ -351,8 +351,8 @@ func (d *DAL) WatchTickets(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
yield func(ticket model.Ticket) error) error {
|
||||
operationTypes := []bson.D{{{"operationType", "insert"}},
|
||||
{{"operationType", "update"}}}
|
||||
operationTypes := []bson.D{{{Key: "operationType", Value: "insert"}},
|
||||
{{Key: "operationType", Value: "update"}}}
|
||||
|
||||
matchStage := bson.M{
|
||||
"$and": bson.A{
|
||||
@ -362,7 +362,7 @@ func (d *DAL) WatchTickets(
|
||||
}
|
||||
|
||||
matchPipeline := mongo.Pipeline{
|
||||
bson.D{{"$match", matchStage}},
|
||||
bson.D{{Key: "$match", Value: matchStage}},
|
||||
}
|
||||
|
||||
cs, err := d.colTck.Watch(ctx, matchPipeline,
|
||||
@ -418,7 +418,7 @@ func (d *DAL) YieldActiveTickets(
|
||||
}
|
||||
|
||||
func (d *DAL) YieldTickets(ctx context.Context, limit int64) ([]model.Ticket, int64, error) {
|
||||
sort := bson.D{{"State", -1}, {"UpdatedAt", 1}}
|
||||
sort := bson.D{{Key: "State", Value: -1}, {Key: "UpdatedAt", Value: 1}}
|
||||
|
||||
cursor, err := d.colTck.Find(ctx, bson.M{}, options.Find().SetLimit(limit).SetSort(sort))
|
||||
if err != nil {
|
||||
@ -447,7 +447,7 @@ func (d *DAL) YieldUserTickets(ctx context.Context, userID string, limit, offset
|
||||
}
|
||||
fmt.Println("UserID", userID)
|
||||
|
||||
sort := bson.D{{"State", -1}, {"UpdatedAt", -1}}
|
||||
sort := bson.D{{Key: "State", Value: -1}, {Key: "UpdatedAt", Value: -1}}
|
||||
|
||||
cursor, err := d.colTck.Find(ctx, query, options.Find().SetSort(sort).SetLimit(limit).SetSkip(offset))
|
||||
if err != nil {
|
||||
@ -472,15 +472,15 @@ func (d *DAL) YieldUserTickets(ctx context.Context, userID string, limit, offset
|
||||
|
||||
func (d *DAL) WatchAllTickets(ctx context.Context, yield func(ticket model.Ticket) error) error {
|
||||
operationTypes := []bson.D{
|
||||
{{"operationType", "insert"}},
|
||||
{{"operationType", "update"}},
|
||||
{{Key: "operationType", Value: "insert"}},
|
||||
{{Key: "operationType", Value: "update"}},
|
||||
}
|
||||
|
||||
matchStage := bson.D{{"$or", operationTypes}}
|
||||
matchStage := bson.D{{Key: "$or", Value: operationTypes}}
|
||||
|
||||
matchPipeline := mongo.Pipeline{
|
||||
bson.D{
|
||||
{"$match", matchStage},
|
||||
{Key: "$match", Value: matchStage},
|
||||
},
|
||||
}
|
||||
|
||||
@ -533,7 +533,7 @@ func (d *DAL) YieldMessages(
|
||||
yield func(ticket model.Message) error) error {
|
||||
cursor, err := d.colMsg.Find(ctx, bson.M{
|
||||
"TicketID": ticketID,
|
||||
}, options.Find().SetLimit(20).SetSort(bson.D{{"CreatedAt", -1}}))
|
||||
}, options.Find().SetLimit(20).SetSort(bson.D{{Key: "CreatedAt", Value: -1}}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -601,22 +601,22 @@ type Change struct {
|
||||
|
||||
func (d *DAL) WatchMessages(
|
||||
ctx context.Context, ticketID string, yield func(ticket model.Message) error) error {
|
||||
operationTypes := []bson.D{{{"operationType", "insert"}},
|
||||
{{"operationType", "update"}}}
|
||||
operationTypes := []bson.D{{{Key: "operationType", Value: "insert"}},
|
||||
{{Key: "operationType", Value: "update"}}}
|
||||
|
||||
matchStage := bson.D{{"$and", []bson.D{
|
||||
matchStage := bson.D{{Key: "$and", Value: []bson.D{
|
||||
{
|
||||
{"$or", operationTypes},
|
||||
{Key: "$or", Value: operationTypes},
|
||||
},
|
||||
{
|
||||
{
|
||||
"fullDocument.TicketID", ticketID,
|
||||
Key: "fullDocument.TicketID", Value: ticketID,
|
||||
},
|
||||
},
|
||||
}}}
|
||||
|
||||
matchPipeline := mongo.Pipeline{
|
||||
bson.D{{"$match", matchStage}},
|
||||
bson.D{{Key: "$match", Value: matchStage}},
|
||||
}
|
||||
|
||||
cs, err := d.colMsg.Watch(ctx, matchPipeline,
|
||||
@ -635,7 +635,10 @@ func (d *DAL) WatchMessages(
|
||||
return err
|
||||
}
|
||||
|
||||
bson.Unmarshal(change.FullDocument, &piece)
|
||||
err := bson.Unmarshal(change.FullDocument, &piece)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := yield(piece); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -685,7 +688,7 @@ func (d *DAL) GetTicketPage(
|
||||
}
|
||||
}
|
||||
|
||||
sort := bson.D{{"State", -1}, {"UpdatedAt", -1}}
|
||||
sort := bson.D{{Key: "State", Value: -1}, {Key: "UpdatedAt", Value: -1}}
|
||||
|
||||
cur, err := d.colTck.Find(ctx, query, options.Find().SetSort(sort).SetLimit(limit).SetSkip(skip*limit))
|
||||
if err != nil {
|
||||
@ -730,7 +733,7 @@ func (d *DAL) GetMessagesPage(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
sort := bson.D{{"CreatedAt", -1}}
|
||||
sort := bson.D{{Key: "CreatedAt", Value: -1}}
|
||||
|
||||
cur, err := d.colMsg.Find(ctx, query, options.Find().SetLimit(limit).SetSkip(limit*offset).SetSort(sort))
|
||||
if err != nil {
|
||||
@ -803,7 +806,7 @@ func (d *DAL) GetAdditionalData(ctx context.Context, id string) (*Additional, er
|
||||
if err := d.client.Database("bb-identity").Collection("tp-users").FindOne(ctx, bson.M{
|
||||
"_id": id,
|
||||
}, options.FindOne().SetProjection(bson.D{{
|
||||
"Identities", 1,
|
||||
Key: "Identities", Value: 1,
|
||||
}})).Decode(&idens); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -819,7 +822,7 @@ func (d *DAL) GetAdditionalData(ctx context.Context, id string) (*Additional, er
|
||||
if err := d.client.Database("profile").Collection("profile").FindOne(ctx, bson.M{
|
||||
"_id": id,
|
||||
}, options.FindOne().SetProjection(bson.D{{
|
||||
"display_id", 1,
|
||||
Key: "display_id", Value: 1,
|
||||
}})).Decode(&u); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -912,7 +915,7 @@ func (d *DAL) GetAccountPage(ctx context.Context, search string, offset, limit i
|
||||
|
||||
count, err := d.colAcc.CountDocuments(ctx, query)
|
||||
|
||||
sort := bson.D{{"CreatedAt", -1}}
|
||||
sort := bson.D{{Key: "CreatedAt", Value: -1}}
|
||||
|
||||
cur, err := d.colAcc.Find(ctx, query, options.Find().SetLimit(limit).SetSkip(limit*offset).SetSort(sort))
|
||||
if err != nil {
|
||||
|
@ -29,12 +29,12 @@ func main() {
|
||||
fmt.Println("Ошибка подключения к монго:", err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
defer func(client *mongo.Client, ctx context.Context) {
|
||||
err := client.Disconnect(ctx)
|
||||
if err != nil {
|
||||
fmt.Println("CAN NOT DISCONNECT", err)
|
||||
return
|
||||
}
|
||||
} ()
|
||||
}(client, ctx)
|
||||
|
||||
collection := client.Database(mongoDBName).Collection(collectionName)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user