IsUsernameUsed returns true if the given username has been used other than the excluded user (a non-positive ID effectively meaning check against all users).
(ctx context.Context, username string, excludeUserID int64)
| 789 | // the excluded user (a non-positive ID effectively meaning check against all |
| 790 | // users). |
| 791 | func (s *UsersStore) IsUsernameUsed(ctx context.Context, username string, excludeUserID int64) bool { |
| 792 | if username == "" { |
| 793 | return false |
| 794 | } |
| 795 | return s.db.WithContext(ctx). |
| 796 | Select("id"). |
| 797 | Where("lower_name = ? AND id != ?", strings.ToLower(username), excludeUserID). |
| 798 | First(&User{}). |
| 799 | Error != gorm.ErrRecordNotFound |
| 800 | } |
| 801 | |
| 802 | // List returns a list of users. Results are paginated by given page and page |
| 803 | // size, and sorted by primary key (id) in ascending order. |