Рабочий чат
This commit is contained in:
@@ -43,18 +43,25 @@ internal class ProfileRepository : IProfileRepository
|
||||
|
||||
public async Task<List<UserProfileDto>> SearchAsync(string query, int limit = 20, CancellationToken ct = default)
|
||||
{
|
||||
var baseFilter = Builders<ProfileDocument>.Filter.And(
|
||||
Builders<ProfileDocument>.Filter.Ne(p => p.IsBanned, true),
|
||||
Builders<ProfileDocument>.Filter.Ne(p => p.IsDeleted, true)
|
||||
);
|
||||
|
||||
List<ProfileDocument> docs;
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
docs = await _profiles.Find(_ => true).Limit(limit).ToListAsync(ct);
|
||||
docs = await _profiles.Find(baseFilter).Limit(limit).ToListAsync(ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
var filter = Builders<ProfileDocument>.Filter.Or(
|
||||
var searchFilter = Builders<ProfileDocument>.Filter.Or(
|
||||
Builders<ProfileDocument>.Filter.Regex(p => p.Username, new BsonRegularExpression(query, "i")),
|
||||
Builders<ProfileDocument>.Filter.Regex(p => p.DisplayName, new BsonRegularExpression(query, "i"))
|
||||
);
|
||||
docs = await _profiles.Find(filter).Limit(limit).ToListAsync(ct);
|
||||
|
||||
var combinedFilter = Builders<ProfileDocument>.Filter.And(baseFilter, searchFilter);
|
||||
docs = await _profiles.Find(combinedFilter).Limit(limit).ToListAsync(ct);
|
||||
}
|
||||
return docs.Select(p => p.ToDto()).ToList();
|
||||
}
|
||||
@@ -82,6 +89,16 @@ internal class ProfileRepository : IProfileRepository
|
||||
return Result.Success(profile.ToDto());
|
||||
}
|
||||
|
||||
public async Task<Result> UpdateStatusAsync(Guid userId, bool isBanned, bool isDeleted, CancellationToken ct = default)
|
||||
{
|
||||
var profile = await _profiles.Find(p => p.Id == userId).FirstOrDefaultAsync(ct);
|
||||
if (profile is null) return Result.Failure(ProfilesErrors.ProfileNotFound);
|
||||
|
||||
profile.UpdateStatus(isBanned, isDeleted);
|
||||
await _profiles.ReplaceOneAsync(p => p.Id == userId, profile, cancellationToken: ct);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
public async Task<Result> DeleteAsync(Guid userId, CancellationToken ct = default)
|
||||
{
|
||||
var result = await _profiles.DeleteOneAsync(p => p.Id == userId, ct);
|
||||
|
||||
Reference in New Issue
Block a user