-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_users_service.go
67 lines (56 loc) · 1.67 KB
/
alert_users_service.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package service
import (
"github.com/DWHengr/aurora/internal/models"
"github.com/DWHengr/aurora/internal/models/mysql"
"github.com/DWHengr/aurora/internal/page"
"github.com/DWHengr/aurora/internal/service/utils"
"github.com/DWHengr/aurora/pkg/id"
"gorm.io/gorm"
)
type AlertUsersService interface {
Create(user *models.AlertUsers) (*CreateAlertUserResp, error)
Deletes(ids []string) error
Update(user *models.AlertUsers) (*CreateAlertUserResp, error)
Page(page *page.ReqPage) (*page.RespPage, error)
All() ([]*models.AlertUsers, error)
}
type alertUsersService struct {
db *gorm.DB
alertUsersRepo models.AlertUsersRepo
}
func NewAlertUsersService() (AlertUsersService, error) {
db := utils.GetMysqlInstance()
return &alertUsersService{
db: db,
alertUsersRepo: mysql.NewAlertUsersRepo(),
}, nil
}
type CreateAlertUserResp struct {
ID string `json:"id"`
}
func (s *alertUsersService) Create(user *models.AlertUsers) (*CreateAlertUserResp, error) {
user.ID = "usr-" + id.ShortID(8)
err := s.alertUsersRepo.Create(s.db, user)
if err != nil {
return nil, err
}
return &CreateAlertUserResp{
ID: user.ID,
}, nil
}
func (s *alertUsersService) Deletes(ids []string) error {
err := s.alertUsersRepo.Deletes(s.db, ids)
return err
}
func (s *alertUsersService) Update(user *models.AlertUsers) (*CreateAlertUserResp, error) {
err := s.alertUsersRepo.Update(s.db, user)
return &CreateAlertUserResp{
ID: user.ID,
}, err
}
func (s *alertUsersService) Page(page *page.ReqPage) (*page.RespPage, error) {
return s.alertUsersRepo.Page(s.db, page)
}
func (s *alertUsersService) All() ([]*models.AlertUsers, error) {
return s.alertUsersRepo.All(s.db)
}