Skip to content

Commit

Permalink
Added search by client ID in projects
Browse files Browse the repository at this point in the history
  • Loading branch information
amahdysancsoft committed May 15, 2024
1 parent 03d5180 commit e33db8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dotnet/HQ.Abstractions/Projects/GetProjectsV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Request : PagedRequestV1
{
public string? Search { get; set; }
public Guid? Id { get; set; }

public Guid? clientId { get; set; }
public SortColumn SortBy { get; set; } = SortColumn.Name;
public SortDirection SortDirection { get; set; } = SortDirection.Asc;
}
Expand Down
9 changes: 7 additions & 2 deletions src/dotnet/HQ.Server/Services/ProjectServiceV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ public ProjectServiceV1(HQDbContext context)
.OrderByDescending(t => t.CreatedAt)
.AsQueryable();

var total = await records.CountAsync(ct);
if (request.clientId.HasValue)
{
records = records.Where(t => t.ClientId == request.clientId);
}

if (!string.IsNullOrEmpty(request.Search))
{
records = records.Where(t =>
t.Name.ToLower().Contains(request.Search.ToLower()) ||
t.Name.ToLower().Contains(request.Search.ToLower()) ||
t.Client.Name.ToLower().Contains(request.Search.ToLower()) ||
(t.ChargeCode != null ? t.ChargeCode.Code.ToLower().Contains(request.Search.ToLower()) : false)
);
Expand Down Expand Up @@ -140,6 +143,8 @@ public ProjectServiceV1(HQDbContext context)
{
mapped = mapped.Take(request.Take.Value);
}

var total = await records.CountAsync(ct);

var response = new GetProjectsV1.Response()
{
Expand Down

0 comments on commit e33db8a

Please sign in to comment.