Skip to content

Commit 09cc32a

Browse files
committed
example(no-ef): rename models, controllers seem to cause conflict
1 parent 194d31d commit 09cc32a

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

src/JsonApiDotNetCoreExample/Controllers/TodoItemsTestController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ public abstract class AbstractTodoItemsController<T> : JsonApiController<T> wher
1111
{
1212
protected AbstractTodoItemsController(
1313
IJsonApiContext jsonApiContext,
14-
IEntityRepository<T, int> entityRepository,
14+
IResourceService<T, int> service,
1515
ILoggerFactory loggerFactory)
16-
: base(jsonApiContext, entityRepository, loggerFactory)
16+
: base(jsonApiContext, service, loggerFactory)
1717
{
1818
}
19-
}
19+
}
2020
public class TodoItemsTestController : AbstractTodoItemsController<TodoItem>
2121
{
2222
public TodoItemsTestController(
2323
IJsonApiContext jsonApiContext,
24-
IEntityRepository<TodoItem> entityRepository,
24+
IResourceService<TodoItem> service,
2525
ILoggerFactory loggerFactory)
26-
: base(jsonApiContext, entityRepository, loggerFactory)
26+
: base(jsonApiContext, service, loggerFactory)
2727
{ }
2828
}
2929
}

src/NoEntityFrameworkExample/Controllers/TodoItemsController.cs renamed to src/NoEntityFrameworkExample/Controllers/MyModelsController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
namespace NoEntityFrameworkExample.Controllers
77
{
8-
public class TodoItemsController : JsonApiController<TodoItem>
8+
public class MyModelsController : JsonApiController<MyModel>
99
{
10-
public TodoItemsController(
10+
public MyModelsController(
1111
IJsonApiContext jsonApiContext,
12-
IResourceService<TodoItem> resourceService,
12+
IResourceService<MyModel> resourceService,
1313
ILoggerFactory loggerFactory)
1414
: base(jsonApiContext, resourceService, loggerFactory)
1515
{ }

src/NoEntityFrameworkExample/Models/TodoItem.cs renamed to src/NoEntityFrameworkExample/Models/MyModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace NoEntityFrameworkExample.Models
44
{
5-
public class TodoItem : Identifiable
5+
public class MyModel : Identifiable
66
{
77
[Attr("description")]
88
public string Description { get; set; }

src/NoEntityFrameworkExample/Services/TodoItemService.cs renamed to src/NoEntityFrameworkExample/Services/MyModelService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace NoEntityFrameworkExample.Services
99
{
10-
public class TodoItemService : IResourceService<TodoItem>
10+
public class MyModelService : IResourceService<MyModel>
1111
{
12-
public Task<TodoItem> CreateAsync(TodoItem entity)
12+
public Task<MyModel> CreateAsync(MyModel entity)
1313
{
1414
throw new NotImplementedException();
1515
}
@@ -19,19 +19,19 @@ public Task<bool> DeleteAsync(int id)
1919
throw new NotImplementedException();
2020
}
2121

22-
public Task<IEnumerable<TodoItem>> GetAsync()
22+
public Task<IEnumerable<MyModel>> GetAsync()
2323
{
24-
return Task.Run<IEnumerable<TodoItem>>(() => {
25-
return new List<TodoItem> {
26-
new TodoItem {
24+
return Task.Run<IEnumerable<MyModel>>(() => {
25+
return new List<MyModel> {
26+
new MyModel {
2727
Id = 1,
2828
Description = "description"
2929
}
3030
};
3131
});
3232
}
3333

34-
public Task<TodoItem> GetAsync(int id)
34+
public Task<MyModel> GetAsync(int id)
3535
{
3636
throw new NotImplementedException();
3737
}
@@ -46,7 +46,7 @@ public Task<object> GetRelationshipsAsync(int id, string relationshipName)
4646
throw new NotImplementedException();
4747
}
4848

49-
public Task<TodoItem> UpdateAsync(int id, TodoItem entity)
49+
public Task<MyModel> UpdateAsync(int id, MyModel entity)
5050
{
5151
throw new NotImplementedException();
5252
}

src/NoEntityFrameworkExample/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void ConfigureServices(IServiceCollection services)
3434
services.AddJsonApi(options => {
3535
options.Namespace = "api/v1";
3636
options.BuildContextGraph((builder) => {
37-
builder.AddResource<TodoItem>("TodoItems");
37+
builder.AddResource<MyModel>("MyModels");
3838
});
3939
}, mvcBuilder);
4040

41-
services.AddScoped<IResourceService<TodoItem>, TodoItemService>();
41+
services.AddScoped<IResourceService<MyModel>, MyModelService>();
4242
}
4343

4444
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ public async Task Can_Implement_Custom_IResourceService_Without_EFAsync()
2525
var client = server.CreateClient();
2626

2727
var httpMethod = new HttpMethod("GET");
28-
var route = $"/api/v1/todo-items";
28+
var route = $"/api/v1/my-models";
2929

3030
var request = new HttpRequestMessage(httpMethod, route);
3131

3232
// act
3333
var response = await client.SendAsync(request);
3434
var responseBody = await response.Content.ReadAsStringAsync();
3535
Console.WriteLine(responseBody);
36-
var deserializedBody = server.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(responseBody);
36+
var deserializedBody = server.GetService<IJsonApiDeSerializer>()
37+
.DeserializeList<MyModel>(responseBody);
3738

3839
// assert
3940
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

0 commit comments

Comments
 (0)