Complete 4-layer notification module as reference template: domain → infrastructure → application → interfaces. 10 unit tests covering all service methods with mock repository.
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
type Notification struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
TenantID string `json:"tenant_id" gorm:"size:36;not null;index"`
|
|
UserID uint `json:"user_id" gorm:"not null;index"`
|
|
Title string `json:"title" gorm:"size:256;not null"`
|
|
Content string `json:"content" gorm:"type:text"`
|
|
Type string `json:"type" gorm:"size:32;default:info"`
|
|
IsRead bool `json:"is_read" gorm:"default:false"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (Notification) TableName() string {
|
|
return "notifications"
|
|
}
|
|
|
|
type NotificationDTO struct {
|
|
ID uint `json:"id"`
|
|
TenantID string `json:"tenant_id"`
|
|
UserID uint `json:"user_id"`
|
|
Title string `json:"title"`
|
|
Content string `json:"content"`
|
|
Type string `json:"type"`
|
|
IsRead bool `json:"is_read"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func ToNotificationDTO(n *Notification) NotificationDTO {
|
|
return NotificationDTO{
|
|
ID: n.ID,
|
|
TenantID: n.TenantID,
|
|
UserID: n.UserID,
|
|
Title: n.Title,
|
|
Content: n.Content,
|
|
Type: n.Type,
|
|
IsRead: n.IsRead,
|
|
CreatedAt: n.CreatedAt,
|
|
}
|
|
}
|
|
|
|
type CreateNotificationRequest struct {
|
|
UserID uint `json:"user_id" binding:"required"`
|
|
Title string `json:"title" binding:"required"`
|
|
Content string `json:"content"`
|
|
Type string `json:"type"`
|
|
}
|