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

This commit is contained in:
2023-03-11 19:38:01 +07:00
parent 38a21e4568
commit ccd55a6702
3 changed files with 84 additions and 22 deletions
+33 -2
View File
@@ -81,6 +81,9 @@ func AddChat(chatID int64) error {
}
func AddWorkout(chatID int64, workout *Workout) error {
if workout.Count <= 0 {
return nil
}
if err := AddChat(chatID); err != nil {
return err
}
@@ -104,7 +107,7 @@ func AddWorkout(chatID int64, workout *Workout) error {
return err
}
func GetUserInfo(chatID int64) (*ChatInfoDTO, error) {
func GetChatInfo(chatID int64) (*ChatInfoDTO, error) {
if err := AddChat(chatID); err != nil {
return nil, err
}
@@ -124,7 +127,7 @@ func GetUserInfo(chatID int64) (*ChatInfoDTO, error) {
return chatInfoDTO, err
}
func SetStatusInUser(chatID int64, status UserState) error {
func SetStatusToChat(chatID int64, status UserState) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
@@ -181,3 +184,31 @@ func GetStat(chatID int64) (map[string]int, error) {
}
return res, err
}
func GetAllChats() ([]int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
client, err := mongo.Connect(ctx, options.Client().ApplyURI(cfg.MongoURL))
if err != nil {
return nil, err
}
collection := client.Database(cfg.DBName).Collection(cfg.ChatsCollectionName)
cursor, err := collection.Find(ctx,bson.M{})
if err != nil {
return nil, err
}
var res []int64
for cursor.Next(context.Background()) {
var result ChatInfoDTO
if err := cursor.Decode(&result); err != nil {
log.Fatal(err)
}
res = append(res, result.ChatID)
}
if err := cursor.Err(); err != nil {
log.Fatal(err)
}
return res, err
}