Files
hfb_jysh/backend/internal/modules/notification/service.go
T

50 lines
1.3 KiB
Go

package notification
import (
"context"
"errors"
)
var ErrDependencyUnavailable = errors.New("dependency unavailable")
var ErrNotificationNotFound = errors.New("notification not found")
type Service struct {
repo *Repository
}
func NewService(repo *Repository) *Service {
return &Service{repo: repo}
}
func (s *Service) List(ctx context.Context, userID uint64, page, pageSize int, siteCode ...string) (*PaginatedResult, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.List(ctx, userID, page, pageSize, siteCode...)
}
func (s *Service) MarkRead(ctx context.Context, userID uint64, id uint64, siteCode ...string) error {
if s.repo == nil {
return ErrDependencyUnavailable
}
return s.repo.MarkRead(ctx, userID, id, siteCode...)
}
func (s *Service) UnreadCount(ctx context.Context, userID uint64, siteCode ...string) (*UnreadCountDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
count, err := s.repo.UnreadCount(ctx, userID, siteCode...)
if err != nil {
return nil, err
}
return &UnreadCountDTO{UnreadCount: count}, nil
}
func (s *Service) MarkAllRead(ctx context.Context, userID uint64, siteCode ...string) (int64, error) {
if s.repo == nil {
return 0, ErrDependencyUnavailable
}
return s.repo.MarkAllRead(ctx, userID, siteCode...)
}