Skip to content

Commit 6dca5c0

Browse files
committed
feat(reader): deserialize operations document
1 parent 8e6a240 commit 6dca5c0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
using System;
22
using System.IO;
33
using System.Threading.Tasks;
4-
using JsonApiDotNetCore.Internal;
5-
using JsonApiDotNetCore.Serialization;
6-
using JsonApiDotNetCore.Services;
4+
using JsonApiDotNetCore.Models.Operations;
75
using Microsoft.AspNetCore.Mvc.Formatters;
8-
using Microsoft.Extensions.Logging;
96
using Newtonsoft.Json;
107

118
namespace JsonApiDotNetCore.Formatters
@@ -17,28 +14,26 @@ public interface IJsonApiOperationsReader
1714

1815
public class JsonApiOperationsReader : IJsonApiOperationsReader
1916
{
20-
public JsonApiOperationsReader()
21-
{
22-
}
23-
2417
public Task<InputFormatterResult> ReadAsync(InputFormatterContext context)
2518
{
2619
if (context == null)
2720
throw new ArgumentNullException(nameof(context));
2821

2922
var request = context.HttpContext.Request;
30-
if (request.ContentLength == 0)
23+
if (request.ContentLength == null || request.ContentLength == 0)
3124
return InputFormatterResult.FailureAsync();
3225

26+
var body = GetRequestBody(request.Body);
27+
28+
var operations = JsonConvert.DeserializeObject<OperationsDocument>(body);
29+
3330
return InputFormatterResult.SuccessAsync(null);
3431
}
3532

3633
private string GetRequestBody(Stream body)
3734
{
3835
using (var reader = new StreamReader(body))
39-
{
4036
return reader.ReadToEnd();
41-
}
4237
}
4338
}
4439
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace JsonApiDotNetCore.Models.Operations
4+
{
5+
public class OperationsDocument
6+
{
7+
public List<Operation> Operations { get; set; }
8+
}
9+
}

0 commit comments

Comments
 (0)