add last_time
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-09 14:47:38 +07:00
parent d1f2c359a2
commit ada1a97999
12 changed files with 30 additions and 19 deletions
+3 -2
View File
@@ -14,8 +14,9 @@ type Chat struct {
}
type ChatInfo struct {
ChatID int64 `bson:"chat_id"`
Status string `bson:"status"`
ChatID int64 `bson:"chat_id"`
Status string `bson:"status"`
Username string `bson:"username"`
}
func (c *ChatInfo) GetStatus() UserState {
+13 -3
View File
@@ -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
}