Skip to content

Commit

Permalink
fix whitespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joukevandermaas committed Nov 10, 2015
1 parent 769910b commit cb2d7f1
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 115 deletions.
1 change: 1 addition & 0 deletions Saule.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9D2F8CA1-79B8-4492-907E-5BCF88429168}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
README.md = README.md
StyleCop.Analyzers.ruleset = StyleCop.Analyzers.ruleset
Expand Down
29 changes: 17 additions & 12 deletions Saule/ApiResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected ApiResource()
var type = GetType();

var name = type.Name;
OfType(name.ToUpperInvariant().EndsWith("RESOURCE")
? name.Remove(name.Length - "RESOURCE".Length)
OfType(name.ToUpperInvariant().EndsWith("RESOURCE")
? name.Remove(name.Length - "RESOURCE".Length)
: name);

Resources.TryAdd(type, this);
Expand All @@ -58,7 +58,7 @@ protected void OfType(string value)
/// is the name of the class (without 'Resource', if it exists).
/// </summary>
/// <param name="value">The type of the resource.</param>
/// <param name="path">The url pathspec of this relationship (default is the
/// <param name="path">The url pathspec of this relationship (default is the
/// pluralized version of the type name)</param>
protected void OfType(string value, string path)
{
Expand Down Expand Up @@ -99,8 +99,9 @@ private static void VerifyPropertyName(string name)
/// Specify a to-one relationship of this resource.
/// </summary>
/// <param name="name">The name of the relationship.</param>
protected ResourceRelationship BelongsTo<T>(string name) where T : ApiResource, new()
{
protected ResourceRelationship BelongsTo<T>(string name)
where T : ApiResource, new()
{
return BelongsTo<T>(name, name);
}

Expand All @@ -110,8 +111,9 @@ private static void VerifyPropertyName(string name)
/// <param name="name">The name of the relationship.</param>
/// <param name="path">The url pathspec of this relationship (default
/// is the name)</param>
protected ResourceRelationship BelongsTo<T>(string name, string path) where T : ApiResource, new()
{
protected ResourceRelationship BelongsTo<T>(string name, string path)
where T : ApiResource, new()
{
VerifyPropertyName(name);

var resource = GetUniqueResource<T>();
Expand All @@ -126,8 +128,9 @@ private static void VerifyPropertyName(string name)
/// Specify a to-many relationship of this resource.
/// </summary>
/// <param name="name">The name of the relationship.</param>
protected ResourceRelationship HasMany<T>(string name) where T : ApiResource, new()
{
protected ResourceRelationship HasMany<T>(string name)
where T : ApiResource, new()
{
return HasMany<T>(name, name);
}

Expand All @@ -137,8 +140,9 @@ private static void VerifyPropertyName(string name)
/// <param name="name">The name of the relationship.</param>
/// <param name="path">The url pathspec of this relationship (default
/// is the name)</param>
protected ResourceRelationship HasMany<T>(string name, string path) where T : ApiResource, new()
{
protected ResourceRelationship HasMany<T>(string name, string path)
where T : ApiResource, new()
{
VerifyPropertyName(name);

var resource = GetUniqueResource<T>();
Expand All @@ -149,7 +153,8 @@ private static void VerifyPropertyName(string name)
return result;
}

private static T GetUniqueResource<T>() where T : ApiResource, new()
private static T GetUniqueResource<T>()
where T : ApiResource, new()
{
var type = typeof(T);
var resource = Resources.ContainsKey(type)
Expand Down
5 changes: 2 additions & 3 deletions Saule/Http/JsonApiMediaTypeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ internal JsonApiMediaTypeFormatter(HttpRequestMessage request, IUrlPathBuilder u

if (request.Properties.ContainsKey(Constants.PaginationContextPropertyName))
{
var paginationContext = (PaginationContext) request.Properties[Constants.PaginationContextPropertyName];
var paginationContext = (PaginationContext)request.Properties[Constants.PaginationContextPropertyName];
jsonApi.PaginationContext = paginationContext;
}

if (request.Properties.ContainsKey(Constants.RequestPropertyName))
{
_resource = (ApiResource) request.Properties[Constants.RequestPropertyName];
_resource = (ApiResource)request.Properties[Constants.RequestPropertyName];
}

_jsonApiSerializer = jsonApi;
Expand Down Expand Up @@ -149,6 +149,5 @@ public override MediaTypeFormatter GetPerRequestFormatterInstance(
{
return new JsonApiMediaTypeFormatter(request, _urlBuilder);
}

}
}
10 changes: 7 additions & 3 deletions Saule/Http/PaginatedAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public sealed class PaginatedAttribute : ActionFilterAttribute
/// </summary>
public int PerPage
{
get { return _perPage; }
get
{
return _perPage;
}

set
{
if (value < 1)
Expand All @@ -31,7 +35,7 @@ public int PerPage
}

/// <summary>
///
///
/// </summary>
/// <param name="actionContext"></param>
public override void OnActionExecuting(HttpActionContext actionContext)
Expand All @@ -44,7 +48,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
}

/// <summary>
///
///
/// </summary>
/// <param name="actionExecutedContext"></param>
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
Expand Down
1 change: 1 addition & 0 deletions Saule/Http/ReturnsResourceAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
// no json api media type without parameters
actionContext.Response = new HttpResponseMessage(HttpStatusCode.NotAcceptable);
}

var contentType = actionContext.Request.Content?.Headers?.ContentType;
if (contentType != null && contentType.Parameters.Any())
{
Expand Down
12 changes: 8 additions & 4 deletions Saule/JsonApiException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class JsonApiException : Exception
/// Initializes a new instance of the <see cref="JsonApiException"/> class.
///
/// </summary>
public JsonApiException() : base("An error occured while serializing or deserializing a Json Api document")
public JsonApiException()
: base("An error occured while serializing or deserializing a Json Api document")
{
}

Expand All @@ -26,7 +27,8 @@ public class JsonApiException : Exception
/// The caller of this constructor is required to ensure that this string has been localized
/// for the current system culture.
/// </param>
public JsonApiException(string message) : base(message)
public JsonApiException(string message)
: base(message)
{
}

Expand All @@ -42,7 +44,8 @@ public JsonApiException(string message) : base(message)
/// The exception that is the cause of the current exception. If the innerException parameter
/// is not null, the current exception is raised in a catch block that handles the inner exception.
/// </param>
public JsonApiException(string message, Exception innerException) : base(message, innerException)
public JsonApiException(string message, Exception innerException)
: base(message, innerException)
{
}

Expand All @@ -51,7 +54,8 @@ public JsonApiException(string message, Exception innerException) : base(message
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
protected JsonApiException(SerializationInfo info, StreamingContext context) : base(info, context)
protected JsonApiException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Expand Down
61 changes: 3 additions & 58 deletions Saule/JsonApiSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace Saule
internal sealed class JsonApiSerializer
{
public List<JsonConverter> JsonConverters { get; } = new List<JsonConverter>();

public PaginationContext PaginationContext { get; set; } = null;

public IUrlPathBuilder UrlPathBuilder { get; set; } = new DefaultUrlPathBuilder();

public JToken Serialize(object @object, ApiResource resource, Uri requestUri)
Expand Down Expand Up @@ -47,6 +49,7 @@ private JsonSerializer GetJsonSerializer()
{
serializer.Converters.Add(converter);
}

return serializer;
}

Expand All @@ -69,62 +72,4 @@ private static JToken SerializeAsError(object @object)
return null;
}
}

/// <summary>
/// Used to manually serialize objects into Json Api.
/// </summary>
/// <typeparam name="T">The resource type of the objects this serializer can serialize.</typeparam>
public sealed class JsonApiSerializer<T> where T : ApiResource, new()
{
private readonly JsonApiSerializer _serializer;

/// <summary>
/// Initializes a new instance of the <see cref="JsonApiSerializer{T}"/> class.
/// </summary>
public JsonApiSerializer()
{
_serializer = new JsonApiSerializer();
}

/// <summary>
/// Produces the Json Api response that represents the given @object.
/// </summary>
/// <param name="object">The object to serialize.</param>
/// <param name="requestUri">The request uri that prompted the response.</param>
/// <returns></returns>
public JToken Serialize(object @object, Uri requestUri)
{
if (!Paginate) return _serializer.Serialize(@object, new T(), requestUri);

var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
var context = new PaginationContext(request.GetQueryNameValuePairs(), ItemsPerPage);
_serializer.PaginationContext = context;

return _serializer.Serialize(@object, new T(), requestUri);
}

/// <summary>
/// Contains converters to influence the serialization process.
/// </summary>
public ICollection<JsonConverter> JsonConverters => _serializer.JsonConverters;

/// <summary>
/// True if responses should be paginated, otherwise false.
/// </summary>
public bool Paginate { get; set; }

/// <summary>
/// The number of items per page, if the responses are paginated.
/// </summary>
public int ItemsPerPage { get; set; }

/// <summary>
/// The url path builder to use during serialization.
/// </summary>
public IUrlPathBuilder UrlPathBuilder
{
get { return _serializer.UrlPathBuilder; }
set { _serializer.UrlPathBuilder = value; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

namespace Saule
{

/// <summary>
/// Used to manually serialize objects into Json Api.
/// </summary>
/// <typeparam name="T">The resource type of the objects this serializer can serialize.</typeparam>
public sealed class JsonApiSerializer<T> where T : ApiResource, new()
{
public sealed class JsonApiSerializer<T>
where T : ApiResource, new()
{
private readonly JsonApiSerializer _serializer;

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Saule/Queries/PaginationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ private int GetNumber()
}

public int Page { get; }

public int PerPage { get; }

public IDictionary<string, string> ClientFilters { get; }
}
}
3 changes: 1 addition & 2 deletions Saule/Queries/PaginationInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public IQueryable Apply(IQueryable queryable)
// order the queryable first, before we can apply pagination.
var isOrdered = queryable.GetType().GetInterfaces()
.Where(i => i.IsGenericType)
.Any(i => i.GetGenericTypeDefinition() == typeof (IOrderedQueryable<>));
.Any(i => i.GetGenericTypeDefinition() == typeof(IOrderedQueryable<>));

var ordered = isOrdered ? queryable : OrderById(queryable);

Expand Down Expand Up @@ -82,6 +82,5 @@ public IEnumerable Apply(IEnumerable queryable)

return filtered;
}

}
}
2 changes: 2 additions & 0 deletions Saule/Queries/PaginationQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public PaginationQuery(PaginationContext context)
}

public string FirstPage { get; }

public string NextPage { get; }

public string PreviousPage { get; }

private static string CreateQueryString(
Expand Down
11 changes: 7 additions & 4 deletions Saule/Queries/QueryMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Saule.Queries
internal class QueryMethod
{
// This idea was borrowed from the OData repo. See the following url:
// https://github.com/OData/WebApi/blob/master/OData/src/System.Web.Http.OData/OData/ExpressionHelperMethods.cs
// https://github.com/OData/WebApi/blob/master/OData/src/System.Web.Http.OData/OData/ExpressionHelperMethods.cs
public static QueryMethod Skip => new QueryMethod(
GetGenericMethodInfo(_ => default(IQueryable<int>).Skip(default(int))),
GetGenericMethodInfo(_ => default(IEnumerable<int>).Skip(default(int))));
Expand Down Expand Up @@ -53,14 +53,15 @@ protected static Type[] GetTypeArguments(object o)
.GetType()
.GetInterfaces()
.Where(i => i.IsGenericType)
.First(i => typeof (IEnumerable<>).IsAssignableFrom(i.GetGenericTypeDefinition()));
.First(i => typeof(IEnumerable<>).IsAssignableFrom(i.GetGenericTypeDefinition()));
return enumerable.GetGenericArguments();
}

private static MethodInfo GetGenericMethodInfo<TReturn>(Expression<Func<object, TReturn>> expression)
{
return GetGenericMethodInfo(expression as Expression);
}

private static MethodInfo GetGenericMethodInfo(Expression expression)
{
var lambdaExpression = expression as LambdaExpression;
Expand All @@ -70,10 +71,12 @@ private static MethodInfo GetGenericMethodInfo(Expression expression)

private class OrderByQueryMethod : QueryMethod
{
public OrderByQueryMethod() : base(
public OrderByQueryMethod()
: base(
GetGenericMethodInfo(_ => default(IQueryable<int>).OrderBy(default(Expression<Func<int, int>>))),
GetGenericMethodInfo(_ => default(IQueryable<int>).OrderBy(default(Expression<Func<int, int>>))))
{ }
{
}

protected override object ApplyToInternal(MethodInfo method, object[] arguments)
{
Expand Down
1 change: 1 addition & 0 deletions Saule/RelationshipKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum RelationshipKind
/// A to-one relationship between resources.
/// </summary>
BelongsTo,

/// <summary>
/// A to-many relationship between resources.
/// </summary>
Expand Down
11 changes: 0 additions & 11 deletions Saule/ResourceRelationship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,4 @@ protected ResourceRelationship(
/// </summary>
public RelationshipKind Kind { get; }
}

/// <summary>
/// Represents a related resource (to-one or to-many).
/// </summary>
internal class ResourceRelationship<T> : ResourceRelationship where T : ApiResource, new()
{
internal ResourceRelationship(string name, string urlPath, RelationshipKind kind, T resource)
: base(name, urlPath, kind, resource)
{
}
}
}
Loading

0 comments on commit cb2d7f1

Please sign in to comment.