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