+13
-3
@@ -48,7 +48,17 @@ func (db *DB) AddChat(chatID int64) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return result.Err()
|
||||
if result.Err() != nil {
|
||||
return result.Err()
|
||||
}
|
||||
loc, _ := time.LoadLocation("Asia/Novosibirsk")
|
||||
t := time.Now().In(loc)
|
||||
_, err := db.chatsColection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"chat_id": chatID},
|
||||
bson.M{"$set": bson.M{"last_time": t}},
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *DB) AddWorkout(chatID int64, workout *Workout) error {
|
||||
@@ -87,14 +97,14 @@ func (db *DB) AddCalories(chatID int64, calories *Calories) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *DB) GetChatInfo(chatID int64) (*ChatInfo, error) {
|
||||
func (db *DB) GetChatInfo(chatID int64, username string) (*ChatInfo, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
if err := db.AddChat(chatID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chatInfoDTO := &ChatInfo{}
|
||||
chatInfoDTO := &ChatInfo{Username: username}
|
||||
if err := db.chatsColection.FindOne(ctx, bson.M{"chat_id": chatID}).Decode(chatInfoDTO); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user