pg_read_sent_notification_service.go
1.5 KB
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
package domain_service
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
)
type ReadSentNotificationService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *ReadSentNotificationService) Read(sentNotificationId int64) (*domain.SentNotification, error) {
var sentNotificationRepository domain.SentNotificationRepository
if repository, err := repository.NewSentNotificationRepository(service.transactionContext); err != nil {
return nil, err
} else {
sentNotificationRepository = repository
}
sentNotification, err := sentNotificationRepository.FindOne(map[string]interface{}{
"sentNotificationId": sentNotificationId,
})
if err != nil {
return nil, err
}
if sentNotification == nil {
return nil, fmt.Errorf("无效的任务")
}
if err := sentNotification.Read(); err != nil {
return nil, err
}
if sentNotification, err := sentNotificationRepository.Save(sentNotification); err != nil {
return nil, err
} else {
return sentNotification, nil
}
}
func NewReadSentNotificationService(transactionContext *pgTransaction.TransactionContext) (*ReadSentNotificationService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ReadSentNotificationService{
transactionContext: transactionContext,
}, nil
}
}