Skip to content

Commit

Permalink
Merge pull request #19 from arslanaybars/fpaganetto-support-guid-type
Browse files Browse the repository at this point in the history
Fpaganetto support guid type pr
  • Loading branch information
arslanaybars committed Jul 15, 2020
2 parents c28029d + 21216a2 commit b9e3ff0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 15 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ Supported operators for type are below;

Fop uses these query sign for preparing expression.

|Operators |Query Sign |Int/Long |String | Char |DateTime|
|-------------------|------------|---------|-------|------|--------|
|Equal |`==` | ✔️ | ✔️ | ✔️ | ✔️ |
|NotEqual |`!=` | ✔️ | ✔️ | ✔️ | ✔️ |
|GreaterThan |`>` | ✔️ ||| ✔️ |
|GreaterOrEqualThan |`>=` | ✔️ ||| ✔️ |
|LessThan |`<` | ✔️ ||| ✔️ |
|LessOrEqualThan |`<=` | ✔️ ||| ✔️ |
|Contains |`~=` | | ✔️ || |
|NotContains |`!~=` | | ✔️ || |
|StartsWith |`_=` | | ✔️ |||
|NotStartsWith |`!_=` | | ✔️ |||
|EndsWith |`\|=` | | ✔️ |||
|NotEndsWith |`!\|=` | | ✔️ |||
|Operators |Query Sign |Int/Long |String | Char |DateTime|Guid|
|-------------------|------------|----|-------|------|--------|----|
|Equal |`==` | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|NotEqual |`!=` | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|GreaterThan |`>` | ✔️ ||| ✔️ | |
|GreaterOrEqualThan |`>=` | ✔️ ||| ✔️ | |
|LessThan |`<` | ✔️ ||| ✔️ | |
|LessOrEqualThan |`<=` | ✔️ ||| ✔️ | |
|Contains |`~=` || ✔️ ||||
|NotContains |`!~=` || ✔️ ||||
|StartsWith |`_=` || ✔️ ||| |
|NotStartsWith |`!_=` || ✔️ ||| |
|EndsWith |`\|=` || ✔️ ||| |
|NotEndsWith |`!\|=` || ✔️ ||| |

##### Example
api/students/
Expand Down
9 changes: 9 additions & 0 deletions src/Exceptions/GuidDataTypeNotSupportedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Fop.Exceptions
{
public class GuidDataTypeNotSupportedException : FopException
{

public GuidDataTypeNotSupportedException(string message) : base(message) { }

}
}
1 change: 1 addition & 0 deletions src/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static Extensions()
DataTypeStrategies.Add(FilterDataTypes.DateTime, new DateTimeDataTypeStrategy());
DataTypeStrategies.Add(FilterDataTypes.Boolean, new BooleanDataTypeStrategy());
DataTypeStrategies.Add(FilterDataTypes.Enum, new EnumDataTypeStrategy());
DataTypeStrategies.Add(FilterDataTypes.Guid, new GuidTypeStrategy());
}

public static (IQueryable<T>, int) ApplyFop<T>(this IQueryable<T> source, IFopRequest request)
Expand Down
3 changes: 2 additions & 1 deletion src/Filter/FilterEnumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum FilterDataTypes : byte
Char,
DateTime,
Boolean,
Enum
Enum,
Guid
}
}
5 changes: 5 additions & 0 deletions src/FopExpression/FopExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ private static FilterDataTypes GetFilterDataTypes(PropertyInfo pi)
return FilterDataTypes.Boolean;
}

if (propertyName == "Guid")
{
return FilterDataTypes.Guid;
}

throw new ArgumentOutOfRangeException();
}

Expand Down
31 changes: 31 additions & 0 deletions src/Strategies/GuidTypeStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Fop.Exceptions;
using Fop.Filter;

namespace Fop.Strategies
{
public class GuidTypeStrategy : IFilterDataTypeStrategy
{
public string ConvertFilterToText(IFilter filter)
{
switch (filter.Operator)
{
case FilterOperators.Equal:
return filter.Key + " == new Guid(\"" + filter.Value + "\")";
case FilterOperators.NotEqual:
return filter.Key + " != new Guid(\"" + filter.Value + "\")";
case FilterOperators.Contains:
case FilterOperators.NotContains:
case FilterOperators.StartsWith:
case FilterOperators.NotStartsWith:
case FilterOperators.EndsWith:
case FilterOperators.NotEndsWith:
case FilterOperators.GreaterThan:
case FilterOperators.GreaterOrEqualThan:
case FilterOperators.LessThan:
case FilterOperators.LessOrEqualThan:
default:
throw new GuidDataTypeNotSupportedException($"Guid filter does not support {filter.Operator}");
}
}
}
}

0 comments on commit b9e3ff0

Please sign in to comment.