Skip to content

Commit d03e5dd

Browse files
committed
format
1 parent fc2da6f commit d03e5dd

50 files changed

Lines changed: 2013 additions & 1116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"csharpier": {
6+
"version": "1.2.6",
7+
"commands": [
8+
"csharpier"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

example/ApplicationDbContext.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
public class ApplicationDbContext : DbContext
44
{
5-
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
5+
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
6+
: base(options) { }
67

78
public DbSet<User> Users => Set<User>();
8-
}
9+
}

example/Controllers/UserController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public UsersController(ApplicationDbContext db, IMapper mapper)
2222
[EnableQuery<UserDto>(maxTop: 10)]
2323
public ActionResult<IEnumerable<UserDto>> Get()
2424
{
25-
var users = _db.Users
26-
.Include(x => x.Company)
25+
var users = _db
26+
.Users.Include(x => x.Company)
2727
.Include(x => x.Addresses)
2828
.ThenInclude(x => x.City)
2929
.Include(x => x.Manager)
@@ -33,4 +33,4 @@ public ActionResult<IEnumerable<UserDto>> Get()
3333

3434
return Ok(users);
3535
}
36-
}
36+
}

example/Dto/UserDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ public record CompanyDto
3636
{
3737
public string Name { get; set; } = string.Empty;
3838
public string Department { get; set; } = string.Empty;
39-
}
39+
}

example/Entities/User.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public enum Gender
5050
{
5151
Male,
5252
Female,
53+
5354
[JsonStringEnumMemberName("Alternative")]
54-
Other
55-
}
55+
Other,
56+
}

example/Profiles/AutoMapperProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ public AutoMapperProfile()
99
CreateMap<City, CityDto>();
1010
CreateMap<Company, CompanyDto>();
1111
}
12-
}
12+
}

example/Program.cs

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
var builder = WebApplication.CreateBuilder(args);
1212

13-
var postgreSqlContainer = new PostgreSqlBuilder()
14-
.WithImage("postgres:15")
15-
.Build();
13+
var postgreSqlContainer = new PostgreSqlBuilder().WithImage("postgres:15").Build();
1614

1715
await postgreSqlContainer.StartAsync();
1816

@@ -56,16 +54,21 @@
5654
.RuleFor(x => x.Test, f => f.Random.Double())
5755
.RuleFor(x => x.NullableInt, f => f.Random.Bool() ? f.Random.Int(1, 100) : null)
5856
.RuleFor(x => x.IsEmailVerified, f => f.Random.Bool())
59-
.Rules((f, u) =>
60-
{
61-
var timeZone = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
62-
var date = f.Date.Past().ToUniversalTime();
63-
64-
u.DateOfBirthUtc = date;
65-
u.DateOfBirthTz = TimeZoneInfo.ConvertTimeFromUtc(date, timeZone);
66-
})
57+
.Rules(
58+
(f, u) =>
59+
{
60+
var timeZone = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
61+
var date = f.Date.Past().ToUniversalTime();
62+
63+
u.DateOfBirthUtc = date;
64+
u.DateOfBirthTz = TimeZoneInfo.ConvertTimeFromUtc(date, timeZone);
65+
}
66+
)
6767
.RuleFor(x => x.Manager, (f, u) => f.CreateManager(3))
68-
.RuleFor(x => x.Addresses, f => f.PickRandom(addresses.Generate(5), f.Random.Int(1, 3)).ToList())
68+
.RuleFor(
69+
x => x.Addresses,
70+
f => f.PickRandom(addresses.Generate(5), f.Random.Int(1, 3)).ToList()
71+
)
6972
.RuleFor(x => x.Tags, f => f.Lorem.Words(f.Random.Int(0, 5)).ToList())
7073
.RuleFor(x => x.Company, f => f.PickRandom(companies.Generate(20)));
7174

@@ -78,27 +81,30 @@
7881

7982
Console.WriteLine($"Postgres connection string: {postgreSqlContainer.GetConnectionString()}");
8083

81-
app.MapGet("/minimal/users", (ApplicationDbContext db, [FromServices] IMapper mapper, [AsParameters] Query query) =>
82-
{
83-
var result = db.Users
84-
.Include(x => x.Company)
85-
.Include(x => x.Addresses)
86-
.ThenInclude(x => x.City)
87-
.Include(x => x.Manager)
88-
.ThenInclude(x => x.Manager)
89-
.Where(x => !x.IsDeleted)
90-
.ProjectTo<UserDto>(mapper.ConfigurationProvider)
91-
.Apply(query);
92-
93-
if (result.IsFailed)
84+
app.MapGet(
85+
"/minimal/users",
86+
(ApplicationDbContext db, [FromServices] IMapper mapper, [AsParameters] Query query) =>
9487
{
95-
return Results.BadRequest(new { message = result.Errors });
96-
}
88+
var result = db
89+
.Users.Include(x => x.Company)
90+
.Include(x => x.Addresses)
91+
.ThenInclude(x => x.City)
92+
.Include(x => x.Manager)
93+
.ThenInclude(x => x.Manager)
94+
.Where(x => !x.IsDeleted)
95+
.ProjectTo<UserDto>(mapper.ConfigurationProvider)
96+
.Apply(query);
97+
98+
if (result.IsFailed)
99+
{
100+
return Results.BadRequest(new { message = result.Errors });
101+
}
97102

98-
var response = new PagedResponse<UserDto>(result.Value.Query.ToList(), result.Value.Count);
103+
var response = new PagedResponse<UserDto>(result.Value.Query.ToList(), result.Value.Count);
99104

100-
return Results.Ok(response);
101-
});
105+
return Results.Ok(response);
106+
}
107+
);
102108

103109
app.MapControllers();
104110

@@ -122,8 +128,11 @@ public static class FakerExtensions
122128
NullableInt = f.Random.Bool() ? f.Random.Int(1, 100) : null,
123129
IsEmailVerified = f.Random.Bool(),
124130
DateOfBirthUtc = f.Date.Past().ToUniversalTime(),
125-
DateOfBirthTz = TimeZoneInfo.ConvertTimeFromUtc(f.Date.Past().ToUniversalTime(), TimeZoneInfo.FindSystemTimeZoneById("America/New_York")),
126-
Manager = f.CreateManager(depth - 1) // Recursive call with reduced depth
131+
DateOfBirthTz = TimeZoneInfo.ConvertTimeFromUtc(
132+
f.Date.Past().ToUniversalTime(),
133+
TimeZoneInfo.FindSystemTimeZoneById("America/New_York")
134+
),
135+
Manager = f.CreateManager(depth - 1), // Recursive call with reduced depth
127136
};
128137
}
129-
}
138+
}

example/example.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
2-
32
<PropertyGroup>
43
<TargetFramework>net9.0</TargetFramework>
54
<Nullable>enable</Nullable>
65
<ImplicitUsings>enable</ImplicitUsings>
76
</PropertyGroup>
87

98
<ItemGroup>
10-
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
9+
<PackageReference
10+
Include="AutoMapper.Extensions.Microsoft.DependencyInjection"
11+
Version="12.0.1"
12+
/>
1113
<PackageReference Include="Bogus" Version="35.6.3" />
1214
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
1315
<PackageReference Include="Testcontainers" Version="4.5.0" />
@@ -18,5 +20,4 @@
1820
<ProjectReference Include="..\src\GoatQuery.AspNetCore\src\GoatQuery.AspNetCore.csproj" />
1921
<PackageReference Include="FluentResults" Version="3.16.0" />
2022
</ItemGroup>
21-
2223
</Project>

src/GoatQuery.AspNetCore/src/Attributes/EnableQueryAttribute.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public EnableQueryAttribute(int maxTop, int maxPropertyMappingDepth = 5)
1212
var options = new QueryOptions()
1313
{
1414
MaxTop = maxTop,
15-
MaxPropertyMappingDepth = maxPropertyMappingDepth
15+
MaxPropertyMappingDepth = maxPropertyMappingDepth,
1616
};
1717

1818
_options = options;
@@ -25,10 +25,12 @@ public override void OnActionExecuting(ActionExecutingContext context) { }
2525
public override void OnActionExecuted(ActionExecutedContext context)
2626
{
2727
var result = context.Result as ObjectResult;
28-
if (result is null) return;
28+
if (result is null)
29+
return;
2930

3031
var queryable = result.Value as IQueryable<T>;
31-
if (queryable is null) return;
32+
if (queryable is null)
33+
return;
3234

3335
var queryString = context.HttpContext.Request.Query;
3436

@@ -37,7 +39,9 @@ public override void OnActionExecuted(ActionExecutedContext context)
3739

3840
if (!int.TryParse(topQuery.ToString(), out int top) && !string.IsNullOrEmpty(topQuery))
3941
{
40-
context.Result = new BadRequestObjectResult(new { Message = "The query parameter 'Top' could not be parsed to an integer" });
42+
context.Result = new BadRequestObjectResult(
43+
new { Message = "The query parameter 'Top' could not be parsed to an integer" }
44+
);
4145
return;
4246
}
4347

@@ -47,7 +51,9 @@ public override void OnActionExecuted(ActionExecutedContext context)
4751

4852
if (!int.TryParse(skipString, out int skip) && !string.IsNullOrEmpty(skipQuery))
4953
{
50-
context.Result = new BadRequestObjectResult(new { Message = "The query parameter 'Skip' could not be parsed to an integer" });
54+
context.Result = new BadRequestObjectResult(
55+
new { Message = "The query parameter 'Skip' could not be parsed to an integer" }
56+
);
5157
return;
5258
}
5359

@@ -57,7 +63,9 @@ public override void OnActionExecuted(ActionExecutedContext context)
5763

5864
if (!bool.TryParse(countString, out bool count) && !string.IsNullOrEmpty(countString))
5965
{
60-
context.Result = new BadRequestObjectResult(new { Message = "The query parameter 'Count' could not be parsed to a boolean" });
66+
context.Result = new BadRequestObjectResult(
67+
new { Message = "The query parameter 'Count' could not be parsed to a boolean" }
68+
);
6169
return;
6270
}
6371

@@ -78,30 +86,34 @@ public override void OnActionExecuted(ActionExecutedContext context)
7886
Count = count,
7987
OrderBy = orderbyQuery.ToString(),
8088
Search = search,
81-
Filter = filterQuery.ToString()
89+
Filter = filterQuery.ToString(),
8290
};
8391

8492
ISearchBinder<T>? searchBinder = null;
8593

8694
if (!string.IsNullOrEmpty(search))
8795
{
88-
searchBinder = context.HttpContext.RequestServices.GetService(typeof(ISearchBinder<T>)) as ISearchBinder<T>;
96+
searchBinder =
97+
context.HttpContext.RequestServices.GetService(typeof(ISearchBinder<T>))
98+
as ISearchBinder<T>;
8999
}
90100

91101
var applyOptions = _options ?? new QueryOptions();
92102

93103
// Auto-resolve JsonNamingPolicy from DI if not explicitly set
94104
if (applyOptions.PropertyNamingPolicy is null)
95105
{
96-
var jsonOptions = context.HttpContext.RequestServices.GetService<IOptions<JsonOptions>>();
106+
var jsonOptions = context.HttpContext.RequestServices.GetService<
107+
IOptions<JsonOptions>
108+
>();
97109
var namingPolicy = jsonOptions?.Value?.JsonSerializerOptions?.PropertyNamingPolicy;
98110
if (namingPolicy is not null)
99111
{
100112
applyOptions = new QueryOptions()
101113
{
102114
MaxTop = applyOptions.MaxTop,
103115
MaxPropertyMappingDepth = applyOptions.MaxPropertyMappingDepth,
104-
PropertyNamingPolicy = namingPolicy
116+
PropertyNamingPolicy = namingPolicy,
105117
};
106118
}
107119
}
@@ -110,10 +122,14 @@ public override void OnActionExecuted(ActionExecutedContext context)
110122
if (applyResult.IsFailed)
111123
{
112124
var message = string.Join(", ", applyResult.Errors.Select(x => x.Message));
113-
context.Result = new BadRequestObjectResult(new { message, errors = applyResult.Errors });
125+
context.Result = new BadRequestObjectResult(
126+
new { message, errors = applyResult.Errors }
127+
);
114128
return;
115129
}
116130

117-
context.Result = new OkObjectResult(new PagedResponse<T>(applyResult.Value.Query.ToList(), applyResult.Value.Count));
131+
context.Result = new OkObjectResult(
132+
new PagedResponse<T>(applyResult.Value.Query.ToList(), applyResult.Value.Count)
133+
);
118134
}
119-
}
135+
}

src/GoatQuery.AspNetCore/src/GoatQuery.AspNetCore.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
54
<LangVersion>11.0</LangVersion>
@@ -23,5 +22,4 @@
2322
<ItemGroup>
2423
<ProjectReference Include="../../GoatQuery/src/GoatQuery.csproj" />
2524
</ItemGroup>
26-
2725
</Project>

0 commit comments

Comments
 (0)