Skip to content

Commit 246bdaa

Browse files
committed
feat: added functionality to filter by properties on nested objects
1 parent 63da894 commit 246bdaa

File tree

14 files changed

+556
-199
lines changed

14 files changed

+556
-199
lines changed

example/Dto/UserDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ public record UserDto
1313
public int? NullableInt { get; set; }
1414
public DateTime DateOfBirthUtc { get; set; }
1515
public DateTime DateOfBirthTz { get; set; }
16+
public User? Manager { get; set; }
1617
}

example/Entities/User.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ public record User
1616

1717
[Column(TypeName = "timestamp without time zone")]
1818
public DateTime DateOfBirthTz { get; set; }
19+
public User? Manager { get; set; }
1920
}

example/Program.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050

5151
u.DateOfBirthUtc = date;
5252
u.DateOfBirthTz = TimeZoneInfo.ConvertTimeFromUtc(date, timeZone);
53-
});
53+
})
54+
.RuleFor(x => x.Manager, (f, u) => f.CreateManager(3));
5455

5556
context.Users.AddRange(users.Generate(1_000));
5657
context.SaveChanges();
@@ -59,6 +60,8 @@
5960
}
6061
}
6162

63+
Console.WriteLine($"Postgres connection string: {postgreSqlContainer.GetConnectionString()}");
64+
6265
app.MapGet("/minimal/users", (ApplicationDbContext db, [FromServices] IMapper mapper, [AsParameters] Query query) =>
6366
{
6467
var result = db.Users
@@ -79,3 +82,27 @@
7982
app.MapControllers();
8083

8184
app.Run();
85+
86+
public static class FakerExtensions
87+
{
88+
public static User? CreateManager(this Faker f, int depth)
89+
{
90+
if (depth <= 0 || !f.Random.Bool(0.6f)) // 60% chance of having manager, stop at depth 0
91+
return null;
92+
93+
return new User
94+
{
95+
Id = f.Random.Guid(),
96+
Firstname = f.Person.FirstName,
97+
Lastname = f.Person.LastName,
98+
Age = f.Random.Int(0, 100),
99+
IsDeleted = f.Random.Bool(),
100+
Test = f.Random.Double(),
101+
NullableInt = f.Random.Bool() ? f.Random.Int(1, 100) : null,
102+
IsEmailVerified = f.Random.Bool(),
103+
DateOfBirthUtc = f.Date.Past().ToUniversalTime(),
104+
DateOfBirthTz = TimeZoneInfo.ConvertTimeFromUtc(f.Date.Past().ToUniversalTime(), TimeZoneInfo.FindSystemTimeZoneById("America/New_York")),
105+
Manager = f.CreateManager(depth - 1) // Recursive call with reduced depth
106+
};
107+
}
108+
}

src/GoatQuery/src/Ast/Node.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public Node(Token token)
77
_token = token;
88
}
99

10-
public string TokenLiteral()
10+
public virtual string TokenLiteral()
1111
{
1212
return _token.Literal;
1313
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
public sealed class PropertyPath : QueryExpression
4+
{
5+
public List<string> Segments { get; }
6+
7+
public PropertyPath(Token token, List<string> segments) : base(token)
8+
{
9+
Segments = segments;
10+
}
11+
12+
public override string TokenLiteral()
13+
{
14+
return string.Join("/", Segments);
15+
}
16+
}

0 commit comments

Comments
 (0)