From decc9ef2be056198daea7a3ece5aa0dc1afafc9c Mon Sep 17 00:00:00 2001 From: Isaac Levin <8878502+isaacrlevin@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:39:30 -0800 Subject: [PATCH] Remove Old C# Sample per @jongio --- templates/todo/api/csharp/.gitignore | 4 - templates/todo/api/csharp/ListsController.cs | 159 ------------------ templates/todo/api/csharp/ListsRepository.cs | 132 --------------- templates/todo/api/csharp/Program.cs | 36 ---- .../api/csharp/Properties/launchSettings.json | 28 --- templates/todo/api/csharp/Todo.Api.csproj | 16 -- templates/todo/api/csharp/Todo.Api.sln | 25 --- templates/todo/api/csharp/TodoItem.cs | 20 --- templates/todo/api/csharp/TodoList.cs | 15 -- .../api/csharp/appsettings.Development.json | 8 - templates/todo/api/csharp/appsettings.json | 9 - 11 files changed, 452 deletions(-) delete mode 100644 templates/todo/api/csharp/.gitignore delete mode 100644 templates/todo/api/csharp/ListsController.cs delete mode 100644 templates/todo/api/csharp/ListsRepository.cs delete mode 100644 templates/todo/api/csharp/Program.cs delete mode 100644 templates/todo/api/csharp/Properties/launchSettings.json delete mode 100644 templates/todo/api/csharp/Todo.Api.csproj delete mode 100644 templates/todo/api/csharp/Todo.Api.sln delete mode 100644 templates/todo/api/csharp/TodoItem.cs delete mode 100644 templates/todo/api/csharp/TodoList.cs delete mode 100644 templates/todo/api/csharp/appsettings.Development.json delete mode 100644 templates/todo/api/csharp/appsettings.json diff --git a/templates/todo/api/csharp/.gitignore b/templates/todo/api/csharp/.gitignore deleted file mode 100644 index 040309e60b0..00000000000 --- a/templates/todo/api/csharp/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -obj -bin -.vs -.idea \ No newline at end of file diff --git a/templates/todo/api/csharp/ListsController.cs b/templates/todo/api/csharp/ListsController.cs deleted file mode 100644 index f34369eda5e..00000000000 --- a/templates/todo/api/csharp/ListsController.cs +++ /dev/null @@ -1,159 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace SimpleTodo.Api; - -[ApiController] -[Route("/lists")] -public class ListsController : ControllerBase -{ - private readonly ListsRepository _repository; - - public ListsController(ListsRepository repository) - { - _repository = repository; - } - - [HttpGet] - [ProducesResponseType(200)] - public async Task>> GetLists([FromQuery] int? skip = null, [FromQuery] int? batchSize = null) - { - return Ok(await _repository.GetListsAsync(skip, batchSize)); - } - - [HttpPost] - [ProducesResponseType(201)] - public async Task CreateList([FromBody]CreateUpdateTodoList list) - { - var todoList = new TodoList(list.name) - { - Description = list.description - }; - - await _repository.AddListAsync(todoList); - - return CreatedAtAction(nameof(GetList), new { list_id = todoList.Id }, todoList); - } - - [HttpGet("{list_id}")] - [ProducesResponseType(200)] - [ProducesResponseType(404)] - public async Task>> GetList(string list_id) - { - var list = await _repository.GetListAsync(list_id); - - return list == null ? NotFound() : Ok(list); - } - - [HttpPut("{list_id}")] - [ProducesResponseType(200)] - public async Task> UpdateList(string list_id, [FromBody]CreateUpdateTodoList list) - { - var existingList = await _repository.GetListAsync(list_id); - if (existingList == null) - { - return NotFound(); - } - - existingList.Name = list.name; - existingList.Description = list.description; - existingList.UpdatedDate = DateTimeOffset.UtcNow; - - await _repository.UpdateList(existingList); - - return Ok(existingList); - } - - [HttpDelete("{list_id}")] - [ProducesResponseType(204)] - public async Task DeleteList(string list_id) - { - if (await _repository.GetListAsync(list_id) == null) - { - return NotFound(); - } - - await _repository.DeleteListAsync(list_id); - - return NoContent(); - } - - [HttpGet("{list_id}/items")] - [ProducesResponseType(200)] - public async Task>> GetListItems(string list_id, [FromQuery] int? skip = null, [FromQuery] int? batchSize = null) - { - return Ok(await _repository.GetListItemsAsync(list_id, skip, batchSize)); - } - - [HttpPost("{list_id}/items")] - [ProducesResponseType(201)] - public async Task> CreateListItem(string list_id, [FromBody] CreateUpdateTodoItem item) - { - var newItem = new TodoItem(list_id, item.name) - { - Name = item.name, - Description = item.description, - State = item.state, - CreatedDate = DateTimeOffset.UtcNow - }; - - await _repository.AddListItemAsync(newItem); - - return CreatedAtAction(nameof(GetListItem), new { list_id = list_id, item_id = newItem.Id }, newItem); - } - - [HttpGet("{list_id}/items/{item_id}")] - [ProducesResponseType(200)] - public async Task> GetListItem(string list_id, string item_id) - { - var item = await _repository.GetListItemAsync(list_id, item_id); - - return item == null ? NotFound() : Ok(item); - } - - [HttpPut("{list_id}/items/{item_id}")] - [ProducesResponseType(200)] - public async Task> UpdateListItem(string list_id, string item_id, [FromBody] CreateUpdateTodoItem item) - { - var existingItem = await _repository.GetListItemAsync(list_id, item_id); - if (existingItem == null) - { - return NotFound(); - } - - existingItem.Name = item.name; - existingItem.Description = item.description; - existingItem.CompletedDate = item.completedDate; - existingItem.DueDate = item.dueDate; - existingItem.State = item.state; - existingItem.UpdatedDate = DateTimeOffset.UtcNow; - - await _repository.UpdateListItem(existingItem); - - return Ok(existingItem); - } - - [HttpDelete("{list_id}/items/{item_id}")] - [ProducesResponseType(204)] - [ProducesResponseType(404)] - public async Task DeleteListItem(string list_id, string item_id) - { - if (await _repository.GetListItemAsync(list_id, item_id) == null) - { - return NotFound(); - } - - await _repository.DeleteListItemAsync(list_id, item_id); - - return NoContent(); - } - - [HttpGet("{list_id}/state/{state}")] - [ProducesResponseType(200)] - public async Task>> GetListItemsByState(string list_id, string state, [FromQuery] int? skip = null, [FromQuery] int? batchSize = null) - { - return Ok(await _repository.GetListItemsByStateAsync(list_id, state, skip, batchSize)); - } - - public record CreateUpdateTodoList(string name, string? description = null); - public record CreateUpdateTodoItem(string name, string state, DateTimeOffset? dueDate, DateTimeOffset? completedDate, string? description = null); -} \ No newline at end of file diff --git a/templates/todo/api/csharp/ListsRepository.cs b/templates/todo/api/csharp/ListsRepository.cs deleted file mode 100644 index 5b3ce657bc6..00000000000 --- a/templates/todo/api/csharp/ListsRepository.cs +++ /dev/null @@ -1,132 +0,0 @@ -using MongoDB.Bson; -using MongoDB.Bson.Serialization; -using MongoDB.Bson.Serialization.Conventions; -using MongoDB.Bson.Serialization.IdGenerators; -using MongoDB.Bson.Serialization.Serializers; -using MongoDB.Driver; - -namespace SimpleTodo.Api; - -public class ListsRepository -{ - private readonly IMongoCollection _listsCollection; - private readonly IMongoCollection _itemsCollection; - - static ListsRepository() - { - var conventionPack = new ConventionPack - { - new CamelCaseElementNameConvention() - }; - - ConventionRegistry.Register( - name: "Camel case", - conventions: conventionPack, - filter: t => t == typeof(TodoList) || t == typeof(TodoItem)); - - var objectIdSerializer = new StringSerializer(BsonType.ObjectId); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.MapIdProperty(item => item.Id) - .SetIgnoreIfDefault(true) - .SetIdGenerator(StringObjectIdGenerator.Instance) - .SetSerializer(objectIdSerializer); - }); - - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.MapIdProperty(item => item.Id) - .SetIgnoreIfDefault(true) - .SetIdGenerator(StringObjectIdGenerator.Instance) - .SetSerializer(objectIdSerializer); - map.MapProperty(item => item.ListId).SetSerializer(objectIdSerializer); - }); - } - - public ListsRepository(MongoClient client, IConfiguration configuration) - { - var database = client.GetDatabase(configuration["AZURE_COSMOS_DATABASE_NAME"]); - _listsCollection = database.GetCollection("TodoList"); - _itemsCollection = database.GetCollection("TodoItem"); - } - - public async Task> GetListsAsync(int? skip, int? batchSize) - { - var cursor = await _listsCollection.FindAsync( - _ => true, - new FindOptions() - { - Skip = skip, - BatchSize = batchSize - }); - return await cursor.ToListAsync(); - } - - public async Task GetListAsync(string listId) - { - var cursor = await _listsCollection.FindAsync(list => list.Id == listId); - return await cursor.FirstOrDefaultAsync(); - } - - public async Task DeleteListAsync(string listId) - { - await _listsCollection.DeleteOneAsync(list => list.Id == listId); - } - - public async Task AddListAsync(TodoList list) - { - await _listsCollection.InsertOneAsync(list); - } - - public async Task UpdateList(TodoList existingList) - { - await _listsCollection.ReplaceOneAsync(list => list.Id == existingList.Id, existingList); - } - - public async Task> GetListItemsAsync(string listId, int? skip, int? batchSize) - { - var cursor = await _itemsCollection.FindAsync( - item => item.ListId == listId, - new FindOptions() - { - Skip = skip, - BatchSize = batchSize - }); - return await cursor.ToListAsync(); - } - - public async Task> GetListItemsByStateAsync(string listId, string state, int? skip, int? batchSize) - { - var cursor = await _itemsCollection.FindAsync( - item => item.ListId == listId && item.State == state, - new FindOptions() - { - Skip = skip, - BatchSize = batchSize - }); - return await cursor.ToListAsync(); - } - - public async Task AddListItemAsync(TodoItem item) - { - await _itemsCollection.InsertOneAsync(item); - } - - public async Task GetListItemAsync(string listId, string itemId) - { - var cursor = await _itemsCollection.FindAsync(item => item.Id == itemId && item.ListId == listId); - return await cursor.FirstOrDefaultAsync(); - } - - public async Task DeleteListItemAsync(string listId, string itemId) - { - await _itemsCollection.DeleteOneAsync(item => item.Id == itemId && item.ListId == listId); - } - - public async Task UpdateListItem(TodoItem existingItem) - { - await _itemsCollection.ReplaceOneAsync(item => item.Id == existingItem.Id, existingItem); - } -} \ No newline at end of file diff --git a/templates/todo/api/csharp/Program.cs b/templates/todo/api/csharp/Program.cs deleted file mode 100644 index 0df00335b75..00000000000 --- a/templates/todo/api/csharp/Program.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Azure.Identity; -using Microsoft.ApplicationInsights.AspNetCore.Extensions; -using MongoDB.Driver; -using SimpleTodo.Api; - -var builder = WebApplication.CreateBuilder(args); -var credential = new DefaultAzureCredential(); -builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"]), credential); - -builder.Services.AddSingleton(); -builder.Services.AddSingleton(_ => new MongoClient(builder.Configuration[builder.Configuration["AZURE_COSMOS_CONNECTION_STRING_KEY"]])); -builder.Services.AddControllers(); -builder.Services.AddApplicationInsightsTelemetry(builder.Configuration); - -var app = builder.Build(); - -app.UseCors(policy => -{ - policy.AllowAnyOrigin(); - policy.AllowAnyHeader(); - policy.AllowAnyMethod(); -}); - -// Swagger UI -app.UseSwaggerUI(options => { - options.SwaggerEndpoint("./openapi.yaml", "v1"); - options.RoutePrefix = ""; -}); - -app.UseStaticFiles(new StaticFileOptions{ - // Serve openapi.yaml file - ServeUnknownFileTypes = true, -}); - -app.MapControllers(); -app.Run(); \ No newline at end of file diff --git a/templates/todo/api/csharp/Properties/launchSettings.json b/templates/todo/api/csharp/Properties/launchSettings.json deleted file mode 100644 index ea40366740a..00000000000 --- a/templates/todo/api/csharp/Properties/launchSettings.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:13087", - "sslPort": 44375 - } - }, - "profiles": { - "net": { - "commandName": "Project", - "dotnetRunMessages": false, - "launchBrowser": false, - "applicationUrl": "https://localhost:3101;http://localhost:3100", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/templates/todo/api/csharp/Todo.Api.csproj b/templates/todo/api/csharp/Todo.Api.csproj deleted file mode 100644 index c8ec06ab69e..00000000000 --- a/templates/todo/api/csharp/Todo.Api.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - diff --git a/templates/todo/api/csharp/Todo.Api.sln b/templates/todo/api/csharp/Todo.Api.sln deleted file mode 100644 index ec4c80e672d..00000000000 --- a/templates/todo/api/csharp/Todo.Api.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.1.31903.286 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Todo.Api", "Todo.Api.csproj", "{A40339D0-DEF8-4CF7-9E57-CA227AA78056}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A40339D0-DEF8-4CF7-9E57-CA227AA78056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A40339D0-DEF8-4CF7-9E57-CA227AA78056}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A40339D0-DEF8-4CF7-9E57-CA227AA78056}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A40339D0-DEF8-4CF7-9E57-CA227AA78056}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9DE28BD5-F5D0-4A5F-98AC-5404AC5F2FC1} - EndGlobalSection -EndGlobal diff --git a/templates/todo/api/csharp/TodoItem.cs b/templates/todo/api/csharp/TodoItem.cs deleted file mode 100644 index da6d3d67f83..00000000000 --- a/templates/todo/api/csharp/TodoItem.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace SimpleTodo.Api; - -public class TodoItem -{ - public TodoItem(string listId, string name) - { - ListId = listId; - Name = name; - } - - public string? Id { get; set; } - public string ListId { get; set; } - public string Name { get; set; } - public string? Description { get; set; } - public string State { get; set; } = "todo"; - public DateTimeOffset? DueDate { get; set; } - public DateTimeOffset? CompletedDate { get; set; } - public DateTimeOffset? CreatedDate { get; set; } = DateTimeOffset.UtcNow; - public DateTimeOffset? UpdatedDate { get; set; } -} \ No newline at end of file diff --git a/templates/todo/api/csharp/TodoList.cs b/templates/todo/api/csharp/TodoList.cs deleted file mode 100644 index 2eb10660d86..00000000000 --- a/templates/todo/api/csharp/TodoList.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace SimpleTodo.Api; - -public class TodoList -{ - public TodoList(string name) - { - Name = name; - } - - public string? Id { get; set; } - public string Name { get; set; } - public string? Description { get; set; } - public DateTimeOffset CreatedDate { get; set; } = DateTimeOffset.UtcNow; - public DateTimeOffset? UpdatedDate { get; set; } -} \ No newline at end of file diff --git a/templates/todo/api/csharp/appsettings.Development.json b/templates/todo/api/csharp/appsettings.Development.json deleted file mode 100644 index 0c208ae9181..00000000000 --- a/templates/todo/api/csharp/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/templates/todo/api/csharp/appsettings.json b/templates/todo/api/csharp/appsettings.json deleted file mode 100644 index 10f68b8c8b4..00000000000 --- a/templates/todo/api/csharp/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -}