Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
fix(db): Time type field use pointer to solve 0000-00-00 issue.
Browse files Browse the repository at this point in the history
Signed-off-by: qwqcode <[email protected]>
  • Loading branch information
qwqcode committed Apr 23, 2022
1 parent 9ca2a80 commit fd1be63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions model/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type Notify struct {
CommentID uint `gorm:"index"` // 待查看的评论

IsRead bool
ReadAt time.Time
ReadAt *time.Time
IsEmailed bool
EmailAt time.Time
EmailAt *time.Time

Key string `gorm:"index;size:255"`

Expand Down Expand Up @@ -72,13 +72,15 @@ func (n *Notify) SetInitial() error {

func (n *Notify) SetRead() error {
n.IsRead = true
n.ReadAt = time.Now()
nowTime := time.Now()
n.ReadAt = &nowTime
return lib.DB.Save(n).Error
}

func (n *Notify) SetEmailed() error {
n.IsEmailed = true
n.EmailAt = time.Now()
nowTime := time.Now()
n.EmailAt = &nowTime
return lib.DB.Save(n).Error
}

Expand Down
4 changes: 3 additions & 1 deletion model/query_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ func UserNotifyMarkAllAsRead(userID uint) error {
return errors.New("user not found")
}

nowTime := time.Now()

lib.DB.Model(&Notify{}).Where("user_id = ?", userID).Updates(&Notify{
IsRead: true,
ReadAt: time.Now(),
ReadAt: &nowTime,
})

return nil
Expand Down

1 comment on commit fd1be63

@qwqcode
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Please sign in to comment.