Skip to content

Commit 84a78a0

Browse files
committed
apply pr feedback
1 parent b34bd3f commit 84a78a0

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ dotnet test
107107
#### Cleaning
108108

109109
Sometimes the compiled files can be dirty / corrupt from other branches / failed builds.
110-
If your bash prompt supports the globstar, you can recursively delete the `bin` and `obj` directories:
111110

112111
```bash
113-
shopt -s globstar
114-
rm -rf **/bin && rm -rf **/obj
112+
dotnet clean
115113
```

src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,34 +127,22 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
127127

128128
return source.Where(lambdaIn);
129129
}
130-
else if (op == FilterOperations.@is || op == FilterOperations.isnot) {
130+
else if (op == FilterOperations.isnotnull || op == FilterOperations.isnull) {
131+
// {model}
131132
var parameter = Expression.Parameter(concreteType, "model");
132133
// {model.Id}
133134
var left = Expression.PropertyOrField(parameter, property.Name);
134-
var right = Expression.Constant(filterQuery.PropertyValue, typeof(string));
135+
var right = Expression.Constant(null);
135136

136137
var body = GetFilterExpressionLambda(left, right, op);
137138
var lambda = Expression.Lambda<Func<TSource, bool>>(body, parameter);
138139

139140
return source.Where(lambda);
140141
}
141142
else
142-
{
143-
var isNullabe = IsNullable(property.PropertyType);
144-
var propertyValue = filterQuery.PropertyValue;
145-
var value = propertyValue;
146-
147-
if (op == FilterOperations.@isnot || op == FilterOperations.isnot)
148-
{
149-
if (isNullabe && propertyValue == "null")
150-
{
151-
value = null;
152-
}
153-
}
154-
155-
// convert the incoming value to the target value type
143+
{ // convert the incoming value to the target value type
156144
// "1" -> 1
157-
var convertedValue = TypeHelper.ConvertType(value, property.PropertyType);
145+
var convertedValue = TypeHelper.ConvertType(filterQuery.PropertyValue, property.PropertyType);
158146
// {model}
159147
var parameter = Expression.Parameter(concreteType, "model");
160148
// {model.Id}
@@ -264,11 +252,11 @@ private static Expression GetFilterExpressionLambda(Expression left, Expression
264252
case FilterOperations.ne:
265253
body = Expression.NotEqual(left, right);
266254
break;
267-
case FilterOperations.isnot:
255+
case FilterOperations.isnotnull:
268256
// {model.Id != null}
269257
body = Expression.NotEqual(left, right);
270258
break;
271-
case FilterOperations.@is:
259+
case FilterOperations.isnull:
272260
// {model.Id == null}
273261
body = Expression.Equal(left, right);
274262
break;

src/JsonApiDotNetCore/Internal/Query/FilterOperations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum FilterOperations
1212
ne = 6,
1313
@in = 7, // prefix with @ to use keyword
1414
nin = 8,
15-
@is = 9,
16-
isnot = 10
15+
isnull = 9,
16+
isnotnull = 10
1717
}
1818
}

test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public async Task Can_Filter_TodoItems()
9292
}
9393

9494
[Fact]
95-
public async Task Can_Filter_TodoItems_Using_IsNot_Operator()
95+
public async Task Can_Filter_TodoItems_Using_IsNotNull_Operator()
9696
{
9797
// Arrange
9898
var todoItem = _todoItemFaker.Generate();
@@ -101,21 +101,23 @@ public async Task Can_Filter_TodoItems_Using_IsNot_Operator()
101101
_context.SaveChanges();
102102

103103
var httpMethod = new HttpMethod("GET");
104-
var route = $"/api/v1/todo-items?filter[updated-date]=isnot:null";
104+
var route = $"/api/v1/todo-items?filter[updated-date]=isnotnull:";
105105
var request = new HttpRequestMessage(httpMethod, route);
106106

107107
// Act
108108
var response = await _fixture.Client.SendAsync(request);
109+
110+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
111+
109112
var body = await response.Content.ReadAsStringAsync();
110113
var deserializedBody = _fixture.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(body);
111114

112115
// Assert
113-
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
114116
Assert.NotEmpty(deserializedBody);
115117
}
116118

117119
[Fact]
118-
public async Task Can_Filter_TodoItems_Using_Is_Operator()
120+
public async Task Can_Filter_TodoItems_Using_IsNull_Operator()
119121
{
120122
// Arrange
121123
var todoItem = _todoItemFaker.Generate();
@@ -124,16 +126,18 @@ public async Task Can_Filter_TodoItems_Using_Is_Operator()
124126
_context.SaveChanges();
125127

126128
var httpMethod = new HttpMethod("GET");
127-
var route = $"/api/v1/todo-items?filter[updated-date]=is:null";
129+
var route = $"/api/v1/todo-items?filter[updated-date]=isnull:";
128130
var request = new HttpRequestMessage(httpMethod, route);
129131

130132
// Act
131133
var response = await _fixture.Client.SendAsync(request);
134+
135+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
136+
132137
var body = await response.Content.ReadAsStringAsync();
133138
var deserializedBody = _fixture.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(body);
134139

135140
// Assert
136-
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
137141
Assert.NotEmpty(deserializedBody);
138142
}
139143

0 commit comments

Comments
 (0)