Skip to content

Commit

Permalink
Merge pull request #2 from CloudStriver/dev-Lansong
Browse files Browse the repository at this point in the history
  • Loading branch information
Love-YeLin authored Jan 19, 2024
2 parents d30aa59 + b6e6596 commit 464688b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions biz/infrastructure/mapper/balance/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

const CollectionName = "Balance"
const CollectionName = "balance"

var PrefixUserCacheKey = "cache:Balance:"
var PrefixBalanceCacheKey = "cache:balance:"

var _ IBalanceMongoMapper = (*MongoMapper)(nil)

Expand Down Expand Up @@ -48,7 +48,7 @@ func (m *MongoMapper) Insert(ctx context.Context, data *Balance) (string, error)
data.ID = primitive.NewObjectID()
}

key := PrefixUserCacheKey + data.ID.Hex()
key := PrefixBalanceCacheKey + data.ID.Hex()
ID, err := m.conn.InsertOne(ctx, key, data)
if err != nil {
return "", err
Expand All @@ -62,7 +62,7 @@ func (m *MongoMapper) FindOne(ctx context.Context, id string) (*Balance, error)
return nil, consts.ErrInvalidObjectId
}
var data Balance
key := PrefixUserCacheKey + id
key := PrefixBalanceCacheKey + id
err = m.conn.FindOne(ctx, key, &data, bson.M{consts.ID: oid})
switch {
case err == nil:
Expand Down Expand Up @@ -92,7 +92,7 @@ func (b *Balance) ToBson() bson.M {
}

func (m *MongoMapper) Update(ctx context.Context, data *Balance, oldBalance *Balance) (*mongo.UpdateResult, error) {
key := PrefixUserCacheKey + oldBalance.ID.Hex()
key := PrefixBalanceCacheKey + oldBalance.ID.Hex()
res, err := m.conn.UpdateOne(ctx, key, oldBalance.ToBson(), bson.M{"$set": data})
return res, err
}
Expand All @@ -102,7 +102,7 @@ func (m *MongoMapper) Delete(ctx context.Context, id string) (int64, error) {
if err != nil {
return 0, err
}
key := PrefixUserCacheKey + id
key := PrefixBalanceCacheKey + id
res, err := m.conn.DeleteOne(ctx, key, bson.M{consts.ID: oid})
return res, err
}
12 changes: 6 additions & 6 deletions biz/infrastructure/mapper/stock/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

const CollectionName = "Stock"
const CollectionName = "stock"

var PrefixUserCacheKey = "cache:Stock:"
var PrefixStockCacheKey = "cache:stock:"

var _ IStockMongoMapper = (*MongoMapper)(nil)

Expand Down Expand Up @@ -66,7 +66,7 @@ func (m *MongoMapper) Insert(ctx context.Context, data *Stock) (string, error) {
data.ID = primitive.NewObjectID()
}

key := PrefixUserCacheKey + data.ID.Hex()
key := PrefixStockCacheKey + data.ID.Hex()
ID, err := m.conn.InsertOne(ctx, key, data)
if err != nil {
return "", err
Expand All @@ -80,7 +80,7 @@ func (m *MongoMapper) FindOne(ctx context.Context, id string) (*Stock, error) {
return nil, consts.ErrInvalidObjectId
}
var data Stock
key := PrefixUserCacheKey + id
key := PrefixStockCacheKey + id
err = m.conn.FindOne(ctx, key, &data, bson.M{"_id": oid})
switch {
case err == nil:
Expand All @@ -93,7 +93,7 @@ func (m *MongoMapper) FindOne(ctx context.Context, id string) (*Stock, error) {
}

func (m *MongoMapper) Update(ctx context.Context, data *Stock, oldAmount *int64) (*mongo.UpdateResult, error) {
key := PrefixUserCacheKey + data.ID.Hex()
key := PrefixStockCacheKey + data.ID.Hex()
res, err := m.conn.UpdateOne(ctx, key, bson.M{consts.ID: data.ID, consts.Amount: oldAmount}, bson.M{"$set": data})
return res, err
}
Expand All @@ -103,7 +103,7 @@ func (m *MongoMapper) Delete(ctx context.Context, id string) (int64, error) {
if err != nil {
return 0, err
}
key := PrefixUserCacheKey + id
key := PrefixStockCacheKey + id
res, err := m.conn.DeleteOne(ctx, key, bson.M{"_id": oid})
return res, err
}

0 comments on commit 464688b

Please sign in to comment.