github.com/infraboard/keyauth@v0.8.1/apps/system/impl/dao.go (about)

     1  package impl
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/infraboard/mcube/exception"
     7  	"go.mongodb.org/mongo-driver/bson"
     8  
     9  	"github.com/infraboard/keyauth/apps/system"
    10  	"github.com/infraboard/keyauth/apps/system/notify/mail"
    11  	"github.com/infraboard/keyauth/apps/system/notify/sms"
    12  	"github.com/infraboard/keyauth/apps/verifycode"
    13  )
    14  
    15  func (s *service) save(conf *system.Config) error {
    16  	if _, err := s.col.InsertOne(context.TODO(), conf); err != nil {
    17  		return exception.NewInternalServerError("save config document error, %s", err)
    18  	}
    19  	return nil
    20  }
    21  
    22  func (s *service) updateEmail(conf *mail.Config) error {
    23  	_, err := s.col.UpdateOne(context.TODO(), bson.M{"_id": system.DEFAULT_CONFIG_VERSION}, bson.M{"$set": bson.M{
    24  		"email": conf,
    25  	}})
    26  	if err != nil {
    27  		return exception.NewInternalServerError("update email config document error, %s", err)
    28  	}
    29  
    30  	return nil
    31  }
    32  
    33  func (s *service) updateSMS(conf *sms.Config) error {
    34  	_, err := s.col.UpdateOne(context.TODO(), bson.M{"_id": system.DEFAULT_CONFIG_VERSION}, bson.M{"$set": bson.M{
    35  		"sms": conf,
    36  	}})
    37  	if err != nil {
    38  		return exception.NewInternalServerError("update sms config document error, %s", err)
    39  	}
    40  
    41  	return nil
    42  }
    43  
    44  func (s *service) updateVerifyCode(conf *verifycode.Config) error {
    45  	_, err := s.col.UpdateOne(context.TODO(), bson.M{"_id": system.DEFAULT_CONFIG_VERSION}, bson.M{"$set": bson.M{
    46  		"verify_code": conf,
    47  	}})
    48  	if err != nil {
    49  		return exception.NewInternalServerError("update verify code config document error, %s", err)
    50  	}
    51  
    52  	return nil
    53  }