Skip to content

Commit fb3018d

Browse files
authored
(#122) Fixed documentation for using of right RouteAttribute (#123)
1 parent be92580 commit fb3018d

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

docs/content/in-depth/server/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class TodoItemController : TableController<TodoItem>
109109
}
110110
```
111111

112-
* The controller must have a route. By convention, the client looks for table controllers on a subpath of '/tables', but they can be placed anywhere.
112+
* The controller must have a route. By convention, the client looks for table controllers on a subpath of '/tables', but they can be placed anywhere. Make sure you are using the `RouteAttribute` from `Microsoft.AspNetCore.Mvc`. Your routing will appear broken if you are using `Microsoft.AspNetCore.Components.RouteAttribute`.
113113
* The controller must inherit from `TableController<TEntity>`, where `<TEntity>` is an implementation of the `ITableData` implementation for your repository type.
114114
* Assign a repository based on the same type as your model.
115115

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using CommunityToolkit.Datasync.Server;
6+
using CommunityToolkit.Datasync.Server.EntityFrameworkCore;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Sample.Datasync.Server.Db;
9+
10+
namespace Sample.Datasync.Server.Controllers;
11+
12+
[Route("tables/[controller]")]
13+
public class TodoListController : TableController<TodoList>
14+
{
15+
public TodoListController(AppDbContext context) : base(new EntityTableRepository<TodoList>(context))
16+
{
17+
Options = new TableControllerOptions { EnableSoftDelete = true };
18+
}
19+
}

samples/datasync-server/src/Sample.Datasync.Server/Db/AppDbContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
1515

1616
public DbSet<TodoItem> TodoItems => Set<TodoItem>();
1717

18+
public DbSet<TodoList> TodoLists => Set<TodoList>();
19+
1820
public async Task InitializeDatabaseAsync()
1921
{
20-
await Database.EnsureCreatedAsync();
22+
_ = await Database.EnsureCreatedAsync();
2123
}
2224
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using CommunityToolkit.Datasync.Server.EntityFrameworkCore;
6+
using System.ComponentModel.DataAnnotations;
7+
8+
namespace Sample.Datasync.Server.Db;
9+
10+
public class TodoList : EntityTableData
11+
{
12+
[Required, MinLength(1)]
13+
public string Title { get; set; } = string.Empty;
14+
15+
public string? ListId { get; set; }
16+
}

samples/datasync-server/src/Sample.Datasync.Server/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323

2424
if (nswagEnabled)
2525
{
26-
_ = builder.Services.AddOpenApiDocument(options => options.AddDatasyncProcessor());
26+
_ = builder.Services
27+
.AddOpenApiDocument(options => options.AddDatasyncProcessor());
2728
}
2829

2930
if (swashbuckleEnabled)
3031
{
31-
_ = builder.Services.AddSwaggerGen(options => options.AddDatasyncControllers());
32+
_ = builder.Services
33+
.AddEndpointsApiExplorer()
34+
.AddSwaggerGen(options => options.AddDatasyncControllers());
3235
}
3336

3437
WebApplication app = builder.Build();

samples/datasync-server/src/Sample.Datasync.Server/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
}
77
},
88
"Swagger": {
9-
"Driver": "NSwag"
9+
"Driver": "Swashbuckle"
1010
}
1111
}

0 commit comments

Comments
 (0)