45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"spark-server/internal/module/user/entity"
|
|
"spark-server/internal/pkg/errs"
|
|
)
|
|
|
|
func (m *Repo) SetUserStatus(ctx context.Context, userID int64, status entity.Status) error {
|
|
db, err := m.session(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
res := db.Model(&User{}).Where("id = ?", userID).Updates(map[string]any{
|
|
"status": int(status),
|
|
"updated_at": time.Now(),
|
|
})
|
|
if res.Error != nil {
|
|
return mapDBErr(res.Error)
|
|
}
|
|
if res.RowsAffected == 0 {
|
|
return errs.ErrNotFound
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *Repo) ExtendSendMutedUntil(ctx context.Context, userID int64, until time.Time) error {
|
|
db, err := m.session(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// GREATEST(IFNULL(send_muted_until, '1970-01-01'), ?)
|
|
res := db.Exec(`UPDATE t_users SET send_muted_until = GREATEST(COALESCE(send_muted_until, '1970-01-01 00:00:00.000'), ?), updated_at = ? WHERE id = ?`,
|
|
until, time.Now(), userID)
|
|
if res.Error != nil {
|
|
return mapDBErr(res.Error)
|
|
}
|
|
if res.RowsAffected == 0 {
|
|
return errs.ErrNotFound
|
|
}
|
|
return nil
|
|
}
|