Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/in-depth/server/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class TodoItemController : TableController<TodoItem>
}
```

* 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.
* 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`.
* The controller must inherit from `TableController<TEntity>`, where `<TEntity>` is an implementation of the `ITableData` implementation for your repository type.
* Assign a repository based on the same type as your model.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.Datasync.Server;
using CommunityToolkit.Datasync.Server.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;
using Sample.Datasync.Server.Db;

namespace Sample.Datasync.Server.Controllers;

[Route("tables/[controller]")]
public class TodoListController : TableController<TodoList>
{
public TodoListController(AppDbContext context) : base(new EntityTableRepository<TodoList>(context))
{
Options = new TableControllerOptions { EnableSoftDelete = true };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)

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

public DbSet<TodoList> TodoLists => Set<TodoList>();

public async Task InitializeDatabaseAsync()
{
await Database.EnsureCreatedAsync();
_ = await Database.EnsureCreatedAsync();
}
}
16 changes: 16 additions & 0 deletions samples/datasync-server/src/Sample.Datasync.Server/Db/TodoList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.Datasync.Server.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;

namespace Sample.Datasync.Server.Db;

public class TodoList : EntityTableData
{
[Required, MinLength(1)]
public string Title { get; set; } = string.Empty;

public string? ListId { get; set; }
}
7 changes: 5 additions & 2 deletions samples/datasync-server/src/Sample.Datasync.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@

if (nswagEnabled)
{
_ = builder.Services.AddOpenApiDocument(options => options.AddDatasyncProcessor());
_ = builder.Services
.AddOpenApiDocument(options => options.AddDatasyncProcessor());
}

if (swashbuckleEnabled)
{
_ = builder.Services.AddSwaggerGen(options => options.AddDatasyncControllers());
_ = builder.Services
.AddEndpointsApiExplorer()
.AddSwaggerGen(options => options.AddDatasyncControllers());
}

WebApplication app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
},
"Swagger": {
"Driver": "NSwag"
"Driver": "Swashbuckle"
}
}