DeleteUser 删除用户
(ctx context.Context, username string, password string, uid int64)
| 145 | |
| 146 | // DeleteUser 删除用户 |
| 147 | func (us *userService) DeleteUser(ctx context.Context, username string, password string, uid int64) error { |
| 148 | u, err := us.repo.FindByUsername(ctx, username) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | if err := u.VerifyPassword(password); err != nil { |
| 154 | return ErrInvalidUserOrPassword |
| 155 | } |
| 156 | |
| 157 | u.MarkAsDeleted() |
| 158 | |
| 159 | if err := us.repo.DeleteUser(ctx, username, uid); err != nil { |
| 160 | return err |
| 161 | } |
| 162 | |
| 163 | // 异步删除搜索索引 |
| 164 | go func() { |
| 165 | ctx := context.Background() |
| 166 | if err := us.searchRepo.DeleteUserIndex(ctx, uid); err != nil { |
| 167 | us.l.Error("从搜索引擎中删除用户失败", |
| 168 | zap.Int64("用户ID", uid), |
| 169 | zap.Error(err)) |
| 170 | } |
| 171 | }() |
| 172 | |
| 173 | return nil |
| 174 | } |
| 175 | |
| 176 | // UpdateProfile 更新用户资料 |
| 177 | func (us *userService) UpdateProfile(ctx context.Context, profile domain.Profile) error { |
nothing calls this directly
no test coverage detected