Files
Novault-backend/internal/service/notification_service.go

48 lines
1.3 KiB
Go
Raw Normal View History

package service
import (
"accounting-app/internal/models"
"accounting-app/internal/repository"
)
type NotificationService struct {
repo *repository.NotificationRepository
}
func NewNotificationService(repo *repository.NotificationRepository) *NotificationService {
return &NotificationService{repo: repo}
}
func (s *NotificationService) CreateNotification(userID uint, title, content string, notifType models.NotificationType, link string) error {
notification := &models.Notification{
UserID: userID,
Title: title,
Content: content,
Type: notifType,
Link: link,
}
return s.repo.Create(notification)
}
func (s *NotificationService) GetNotifications(userID uint, page, limit int, isRead *bool) ([]models.Notification, int64, error) {
if page < 1 {
page = 1
}
if limit < 1 {
limit = 10
}
return s.repo.FindAll(userID, page, limit, isRead)
}
func (s *NotificationService) GetUnreadCount(userID uint) (int64, error) {
return s.repo.CountUnread(userID)
}
func (s *NotificationService) MarkAsRead(id uint, userID uint) error {
return s.repo.MarkAsRead(id, userID)
}
func (s *NotificationService) MarkAllAsRead(userID uint) error {
return s.repo.MarkAllAsRead(userID)
}