From 0414401ada8b86ab31e0903120f8c471f6f1b1d7 Mon Sep 17 00:00:00 2001 From: admin <1297598740@qq.com> Date: Wed, 28 Jan 2026 08:38:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=A0=B8=E5=BF=83?= =?UTF-8?q?=E9=87=91=E8=9E=8D=E6=A8=A1=E5=9E=8B=E3=80=81=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=BB=A5=E5=8F=8A=E8=B7=AF=E7=94=B1=E5=92=8C?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E4=BB=93=E5=BA=93=E7=9A=84=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/models/models.go | 29 ------------------- internal/models/notification.go | 25 +++++++++------- .../repository/notification_repository.go | 20 ++++--------- internal/router/router.go | 9 ++---- 4 files changed, 24 insertions(+), 59 deletions(-) diff --git a/internal/models/models.go b/internal/models/models.go index d02fd3d..141bd9e 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -835,35 +835,6 @@ func (AllocationRecordDetail) TableName() string { return "allocation_record_details" } -// NotificationType represents the type of notification -type NotificationType string - -const ( - NotificationTypeBudgetAlert NotificationType = "budget_alert" // 预算超支提醒 - NotificationTypeRecurring NotificationType = "recurring" // 周期交易提醒 - NotificationTypeSystem NotificationType = "system" // 系统公告 - NotificationTypePaymentReminder NotificationType = "payment_reminder" // 还款提醒 - NotificationTypeSavingsGoal NotificationType = "savings_goal" // 储蓄目标提醒 -) - -// Notification represents a user notification -// Feature: notification-center -type Notification struct { - ID uint `gorm:"primarykey" json:"id"` - UserID uint `gorm:"not null;index" json:"user_id"` - Type NotificationType `gorm:"size:30;not null;index" json:"type"` - Title string `gorm:"size:200;not null" json:"title"` - Content string `gorm:"size:1000;not null" json:"content"` - IsRead bool `gorm:"default:false;index" json:"is_read"` - RelatedID *uint `gorm:"index" json:"related_id,omitempty"` // 关联实体 ID (如预算、周期交易等) - CreatedAt time.Time `json:"created_at"` -} - -// TableName specifies the table name for Notification -func (Notification) TableName() string { - return "notifications" -} - // AllModels returns all models for database migration func AllModels() []interface{} { return []interface{}{ diff --git a/internal/models/notification.go b/internal/models/notification.go index 895244c..f57d333 100644 --- a/internal/models/notification.go +++ b/internal/models/notification.go @@ -8,21 +8,26 @@ import ( type NotificationType string const ( - NotificationTypeSystem NotificationType = "system" - NotificationTypeAlert NotificationType = "alert" - NotificationTypeInfo NotificationType = "info" + NotificationTypeSystem NotificationType = "system" + NotificationTypeAlert NotificationType = "alert" + NotificationTypeInfo NotificationType = "info" + NotificationTypeBudgetAlert NotificationType = "budget_alert" // 预算超支提醒 + NotificationTypeRecurring NotificationType = "recurring" // 周期交易提醒 + NotificationTypePaymentReminder NotificationType = "payment_reminder" // 还款提醒 + NotificationTypeSavingsGoal NotificationType = "savings_goal" // 储蓄目标提醒 ) // Notification represents a system notification for a user type Notification struct { BaseModel - UserID uint `gorm:"not null;index" json:"user_id"` - Title string `gorm:"size:200;not null" json:"title"` - Content string `gorm:"type:text;not null" json:"content"` - Type NotificationType `gorm:"size:20;not null;default:'system'" json:"type"` - IsRead bool `gorm:"default:false" json:"is_read"` - Link string `gorm:"size:255" json:"link,omitempty"` // Optional link to redirect - ReadAt *time.Time `json:"read_at,omitempty"` + UserID uint `gorm:"not null;index" json:"user_id"` + Title string `gorm:"size:200;not null" json:"title"` + Content string `gorm:"type:text;not null" json:"content"` + Type NotificationType `gorm:"size:30;not null;default:'system';index" json:"type"` + IsRead bool `gorm:"default:false;index" json:"is_read"` + Link string `gorm:"size:255" json:"link,omitempty"` // Optional link to redirect + ReadAt *time.Time `json:"read_at,omitempty"` + RelatedID *uint `gorm:"index" json:"related_id,omitempty"` // 关联实体 ID (如预算、周期交易等) // Relationships User User `gorm:"foreignKey:UserID" json:"-"` diff --git a/internal/repository/notification_repository.go b/internal/repository/notification_repository.go index 3b075b2..f14a50c 100644 --- a/internal/repository/notification_repository.go +++ b/internal/repository/notification_repository.go @@ -3,6 +3,7 @@ package repository import ( "errors" "fmt" + "time" "accounting-app/internal/models" @@ -119,20 +120,12 @@ func (r *NotificationRepository) MarkAsRead(userID uint, id uint) error { // MarkAllAsRead marks all notifications as read for a user func (r *NotificationRepository) MarkAllAsRead(userID uint) error { -<<<<<<< HEAD - return r.db.Model(&models.Notification{}). - Where("user_id = ? AND is_read = ?", userID, false). - Updates(map[string]interface{}{ - "is_read": true, - "read_at": time.Now(), - }).Error -======= - if err := r.db.Model(&models.Notification{}). + return r.db.Model(&models.Notification{}). Where("user_id = ? AND is_read = ?", userID, false). - Update("is_read", true).Error; err != nil { - return fmt.Errorf("failed to mark all notifications as read: %w", err) - } - return nil + Updates(map[string]interface{}{ + "is_read": true, + "read_at": time.Now(), + }).Error } // Delete deletes a notification by its ID @@ -156,5 +149,4 @@ func (r *NotificationRepository) GetUnreadCount(userID uint) (int64, error) { return 0, fmt.Errorf("failed to count unread notifications: %w", err) } return count, nil ->>>>>>> 2dc66d478cbe3aafaae601f0939ab448b690365e } diff --git a/internal/router/router.go b/internal/router/router.go index 2d3d5db..b82e97c 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -92,9 +92,6 @@ func Setup(db *gorm.DB, yunAPIClient *service.YunAPIClient, cfg *config.Config) interestService := service.NewInterestService(accountRepo, transactionRepo, db) userSettingsServiceWithAccounts := service.NewUserSettingsServiceWithAccountRepo(userSettingsRepo, accountRepo) - // Feature: notification-center - Initialize notification service - notificationService := service.NewNotificationService(notificationRepo) - // Feature: health-score - Initialize health score service healthScoreService := service.NewHealthScoreService(reportRepo, accountRepo, budgetRepo) @@ -128,9 +125,6 @@ func Setup(db *gorm.DB, yunAPIClient *service.YunAPIClient, cfg *config.Config) defaultAccountHandler := handler.NewDefaultAccountHandler(userSettingsServiceWithAccounts) interestHandler := handler.NewInterestHandler(interestService, nil) - // Feature: notification-center - Initialize notification handler - notificationHandler := handler.NewNotificationHandler(notificationService) - // Feature: health-score - Initialize health score handler healthScoreHandler := handler.NewHealthScoreHandler(healthScoreService) @@ -258,6 +252,9 @@ func Setup(db *gorm.DB, yunAPIClient *service.YunAPIClient, cfg *config.Config) // Register notification routes notificationHandler.RegisterRoutes(protected) + + // Register health score routes + healthScoreHandler.RegisterRoutes(protected) } }