-
-
Notifications
You must be signed in to change notification settings - Fork 158
Update examples #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update examples #1269
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
abb6233
PostgreSQL connection strings: remove default port, add error details
bkoelman 93f6532
Use default ASP.NET location for connection strings
bkoelman a4d0836
Drop /v1 from API namespace, because it suggests API versioning shoul…
bkoelman 67f3ef4
Seed core example with sample data, open browser on run, use long IDs
bkoelman f202021
Enable detailed logging
bkoelman c3f5baa
Feed includes from query string to the serializer when custom resourc…
bkoelman 7b63f58
Updates NoEntityFrameworkExample to use a hardcoded in-memory dataset…
bkoelman 2a57fe1
Update documentation
bkoelman d037c75
Reduce logging from tests during cibuild
bkoelman 858228b
Remove unused dependencies on Moq
bkoelman b96cc4e
Revert workaround
bkoelman 012cf4e
Update scripts for breaking change in PowerShell 7.3
bkoelman 6678d87
Fixed: incoming string representation should not be part of the seman…
bkoelman e0464f5
Correct forgotten part in rename
bkoelman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Examples/JsonApiDotNetCoreExample/Data/RotatingList.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace JsonApiDotNetCoreExample.Data; | ||
|
||
internal abstract class RotatingList | ||
{ | ||
public static RotatingList<T> Create<T>(int count, Func<int, T> createElement) | ||
{ | ||
List<T> elements = new(); | ||
|
||
for (int index = 0; index < count; index++) | ||
{ | ||
T element = createElement(index); | ||
elements.Add(element); | ||
} | ||
|
||
return new RotatingList<T>(elements); | ||
} | ||
} | ||
|
||
internal sealed class RotatingList<T> | ||
{ | ||
private int _index = -1; | ||
|
||
public IList<T> Elements { get; } | ||
|
||
public RotatingList(IList<T> elements) | ||
{ | ||
Elements = elements; | ||
} | ||
|
||
public T GetNext() | ||
{ | ||
_index++; | ||
return Elements[_index % Elements.Count]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCoreExample.Models; | ||
|
||
namespace JsonApiDotNetCoreExample.Data; | ||
|
||
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] | ||
internal sealed class Seeder | ||
{ | ||
public static async Task CreateSampleDataAsync(AppDbContext dbContext) | ||
{ | ||
const int todoItemCount = 500; | ||
const int personCount = 50; | ||
const int tagCount = 25; | ||
|
||
RotatingList<Person> people = RotatingList.Create(personCount, index => new Person | ||
{ | ||
FirstName = $"FirstName{index + 1:D2}", | ||
LastName = $"LastName{index + 1:D2}" | ||
}); | ||
|
||
RotatingList<Tag> tags = RotatingList.Create(tagCount, index => new Tag | ||
{ | ||
Name = $"TagName{index + 1:D2}" | ||
}); | ||
|
||
RotatingList<TodoItemPriority> priorities = RotatingList.Create(3, index => (TodoItemPriority)(index + 1)); | ||
|
||
RotatingList<TodoItem> todoItems = RotatingList.Create(todoItemCount, index => | ||
{ | ||
var todoItem = new TodoItem | ||
{ | ||
Description = $"TodoItem{index + 1:D3}", | ||
Priority = priorities.GetNext(), | ||
DurationInHours = index, | ||
CreatedAt = DateTimeOffset.UtcNow, | ||
Owner = people.GetNext(), | ||
Tags = new HashSet<Tag> | ||
{ | ||
tags.GetNext(), | ||
tags.GetNext(), | ||
tags.GetNext() | ||
} | ||
}; | ||
|
||
if (index % 3 == 0) | ||
{ | ||
todoItem.Assignee = people.GetNext(); | ||
} | ||
|
||
return todoItem; | ||
}); | ||
|
||
dbContext.TodoItems.AddRange(todoItems.Elements); | ||
await dbContext.SaveChangesAsync(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.