add new all command
This commit is contained in:
@@ -10,7 +10,8 @@ import (
|
||||
)
|
||||
|
||||
type chatDTO struct {
|
||||
ChatID int64 `bson:"chat_id"`
|
||||
ChatID int64 `bson:"chat_id"`
|
||||
Users []string `bson:"users"`
|
||||
}
|
||||
|
||||
var cfg *config.Config
|
||||
@@ -41,6 +42,10 @@ func AddChat(chatID int64) error {
|
||||
}
|
||||
|
||||
func AddUserInChat(chatID int64, username string) error {
|
||||
if username == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := AddChat(chatID); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -61,3 +66,20 @@ func AddUserInChat(chatID int64, username string) error {
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUsers(chatID int64) ([]string, 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)
|
||||
chatDTO := &chatDTO{}
|
||||
if err := collection.FindOne(ctx, bson.M{"chat_id": chatID}).Decode(chatDTO); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return chatDTO.Users, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user