-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Adds .NET 9 sample to mongo app #35189
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
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b540a68
copy-paste to 9.x
timdeschryver f3c3265
update code to .NET 9
timdeschryver 031e2f0
update references to code
timdeschryver a3139f1
update references to 8.x code
timdeschryver d321b62
upate ms date
timdeschryver 1c1eceb
add missing snapshot
timdeschryver b282bb8
Update aspnetcore/tutorials/first-mongo-app.md
wadepickett 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
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
15 changes: 15 additions & 0 deletions
15
aspnetcore/tutorials/first-mongo-app/samples/9.x/BookStoreApi/BookStoreApi.csproj
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,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" /> | ||
| <PackageReference Include="MongoDB.Driver" Version="3.3.0" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
72 changes: 72 additions & 0 deletions
72
aspnetcore/tutorials/first-mongo-app/samples/9.x/BookStoreApi/Controllers/BooksController.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,72 @@ | ||
| using BookStoreApi.Models; | ||
| using BookStoreApi.Services; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace BookStoreApi.Controllers; | ||
|
|
||
| [ApiController] | ||
| [Route("api/[controller]")] | ||
| public class BooksController : ControllerBase | ||
| { | ||
| private readonly BooksService _booksService; | ||
|
|
||
| public BooksController(BooksService booksService) => | ||
| _booksService = booksService; | ||
|
|
||
| [HttpGet] | ||
| public async Task<List<Book>> Get() => | ||
| await _booksService.GetAsync(); | ||
|
|
||
| [HttpGet("{id:length(24)}")] | ||
| public async Task<ActionResult<Book>> Get(string id) | ||
| { | ||
| var book = await _booksService.GetAsync(id); | ||
|
|
||
| if (book is null) | ||
| { | ||
| return NotFound(); | ||
| } | ||
|
|
||
| return book; | ||
| } | ||
|
|
||
| [HttpPost] | ||
| public async Task<IActionResult> Post(Book newBook) | ||
| { | ||
| await _booksService.CreateAsync(newBook); | ||
|
|
||
| return CreatedAtAction(nameof(Get), new { id = newBook.Id }, newBook); | ||
| } | ||
|
|
||
| [HttpPut("{id:length(24)}")] | ||
| public async Task<IActionResult> Update(string id, Book updatedBook) | ||
| { | ||
| var book = await _booksService.GetAsync(id); | ||
|
|
||
| if (book is null) | ||
| { | ||
| return NotFound(); | ||
| } | ||
|
|
||
| updatedBook.Id = book.Id; | ||
|
|
||
| await _booksService.UpdateAsync(id, updatedBook); | ||
|
|
||
| return NoContent(); | ||
| } | ||
|
|
||
| [HttpDelete("{id:length(24)}")] | ||
| public async Task<IActionResult> Delete(string id) | ||
| { | ||
| var book = await _booksService.GetAsync(id); | ||
|
|
||
| if (book is null) | ||
| { | ||
| return NotFound(); | ||
| } | ||
|
|
||
| await _booksService.RemoveAsync(id); | ||
|
|
||
| return NoContent(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...torials/first-mongo-app/samples/9.x/BookStoreApi/Controllers/WeatherForecastController.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,32 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace BookStoreApi.Controllers; | ||
|
|
||
| [ApiController] | ||
| [Route("[controller]")] | ||
| public class WeatherForecastController : ControllerBase | ||
| { | ||
| private static readonly string[] Summaries = new[] | ||
| { | ||
| "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
| }; | ||
|
|
||
| private readonly ILogger<WeatherForecastController> _logger; | ||
|
|
||
| public WeatherForecastController(ILogger<WeatherForecastController> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| [HttpGet(Name = "GetWeatherForecast")] | ||
| public IEnumerable<WeatherForecast> Get() | ||
| { | ||
| return Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
| { | ||
| Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
| TemperatureC = Random.Shared.Next(-20, 55), | ||
| Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
| }) | ||
| .ToArray(); | ||
| } | ||
| } |
Oops, something went wrong.
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.