Migrape API to NET8
Use entity schema from root, add controller, add CORS for proxy
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
 | 
					<Project Sdk="Microsoft.NET.Sdk.Web">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <PropertyGroup>
 | 
					  <PropertyGroup>
 | 
				
			||||||
    <TargetFramework>net8.0</TargetFramework>
 | 
					    <TargetFramework>net8.0</TargetFramework>
 | 
				
			||||||
@@ -6,4 +6,14 @@
 | 
				
			|||||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
					    <ImplicitUsings>enable</ImplicitUsings>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <ItemGroup>
 | 
				
			||||||
 | 
					    <Compile Include="..\DbCycleVDP\DbFurnace.cs" Link="Db/DbFurnace.cs" />
 | 
				
			||||||
 | 
					    <Compile Include="..\DbCycleVDP\TableCycle.cs" Link="Db/TableCycle.cs" />
 | 
				
			||||||
 | 
					  </ItemGroup>
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					  <ItemGroup>
 | 
				
			||||||
 | 
					    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
 | 
				
			||||||
 | 
					    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
 | 
				
			||||||
 | 
					  </ItemGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +0,0 @@
 | 
				
			|||||||
@APICycleVDP_HostAddress = http://localhost:5127
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
GET {{APICycleVDP_HostAddress}}/weatherforecast/
 | 
					 | 
				
			||||||
Accept: application/json
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
###
 | 
					 | 
				
			||||||
							
								
								
									
										71
									
								
								APICycleVDP/Controller/CyclesController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								APICycleVDP/Controller/CyclesController.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
				
			|||||||
 | 
					using Microsoft.AspNetCore.Cors;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
 | 
					using Newtonsoft.Json.Linq;
 | 
				
			||||||
 | 
					using DbCycleVDP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace APICycleVDP.Controller
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    [EnableCors("All")]
 | 
				
			||||||
 | 
					    public class CyclesController : ControllerBase
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        [HttpPost]
 | 
				
			||||||
 | 
					        public ActionResult<string> CurrCycles()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var result = new JObject
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ["currTime"] = DateTime.Now
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var tasks = new List<Task<TableCycle>>();
 | 
				
			||||||
 | 
					            //var v = new DB.WorkDB();
 | 
				
			||||||
 | 
					            for (var i = 1; i <= 48; i++)
 | 
				
			||||||
 | 
					                tasks.Add(WorkDB.GetCycle(i));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var arr = new JArray();
 | 
				
			||||||
 | 
					            for (var i = 0; i < tasks.Count; i++)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var tmp = tasks[i].GetAwaiter().GetResult();
 | 
				
			||||||
 | 
					                if (tmp != null)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var t = new JObject();
 | 
				
			||||||
 | 
					                    t["vdp"] = tmp.NumVdp;
 | 
				
			||||||
 | 
					                    t["cycle"] = tmp.NumCycle;
 | 
				
			||||||
 | 
					                    t["factStart"] = tmp.FactStart;
 | 
				
			||||||
 | 
					                    t["factEnd"] = tmp.FactEnd;
 | 
				
			||||||
 | 
					                    t["thinkEnd"] = tmp.ThinkEnd;
 | 
				
			||||||
 | 
					                    arr.Add(t);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            result["data"] = arr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return Content(result.ToString(), "application/json");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static class WorkDB
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        async public static Task<TableCycle> GetCycle(int vdp)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var result = new TableCycle();
 | 
				
			||||||
 | 
					            await Task.Run(() =>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                try
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    using var db = new DbFurnace();
 | 
				
			||||||
 | 
					                    var tmp = (from u in db.Cycles
 | 
				
			||||||
 | 
					                               where
 | 
				
			||||||
 | 
					                                    u.NumVdp == vdp
 | 
				
			||||||
 | 
					                               orderby u.FactStart descending
 | 
				
			||||||
 | 
					                               select u).FirstOrDefault();
 | 
				
			||||||
 | 
					                    result = tmp;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch (Exception e)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    Console.WriteLine(e.Message);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            return result;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,27 +1,22 @@
 | 
				
			|||||||
var builder = WebApplication.CreateBuilder(args);
 | 
					var builder = WebApplication.CreateBuilder(args);
 | 
				
			||||||
var app = builder.Build();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
var summaries = new[]
 | 
					builder.Services.AddControllers();
 | 
				
			||||||
 | 
					builder.Services.AddCors(options =>
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
 | 
					    options.AddPolicy("AllowAllOrigins",
 | 
				
			||||||
};
 | 
					        builder =>
 | 
				
			||||||
 | 
					 | 
				
			||||||
app.MapGet("/weatherforecast", () =>
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
    var forecast = Enumerable.Range(1, 5).Select(index =>
 | 
					            builder.AllowAnyOrigin() 
 | 
				
			||||||
        new WeatherForecast
 | 
					                   .AllowAnyMethod() 
 | 
				
			||||||
        (
 | 
					                   .AllowAnyHeader();
 | 
				
			||||||
            DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
 | 
					        });
 | 
				
			||||||
            Random.Shared.Next(-20, 55),
 | 
					 | 
				
			||||||
            summaries[Random.Shared.Next(summaries.Length)]
 | 
					 | 
				
			||||||
        ))
 | 
					 | 
				
			||||||
        .ToArray();
 | 
					 | 
				
			||||||
    return forecast;
 | 
					 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.Run();
 | 
					var app = builder.Build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
 | 
					app.UseCors("AllowAllOrigins");
 | 
				
			||||||
{
 | 
					
 | 
				
			||||||
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
 | 
					app.MapControllerRoute(name: "CurrCycles", pattern: "/currcycles",
 | 
				
			||||||
}
 | 
					          defaults: new { controller = "Cycles", action = "CurrCycles" });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.Run();
 | 
				
			||||||
@@ -13,8 +13,8 @@
 | 
				
			|||||||
      "commandName": "Project",
 | 
					      "commandName": "Project",
 | 
				
			||||||
      "dotnetRunMessages": true,
 | 
					      "dotnetRunMessages": true,
 | 
				
			||||||
      "launchBrowser": true,
 | 
					      "launchBrowser": true,
 | 
				
			||||||
      "launchUrl": "weatherforecast",
 | 
					      "launchUrl": "currcycles",
 | 
				
			||||||
      "applicationUrl": "http://localhost:5127",
 | 
					      "applicationUrl": "http://localhost:65041",
 | 
				
			||||||
      "environmentVariables": {
 | 
					      "environmentVariables": {
 | 
				
			||||||
        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
					        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
    "IIS Express": {
 | 
					    "IIS Express": {
 | 
				
			||||||
      "commandName": "IISExpress",
 | 
					      "commandName": "IISExpress",
 | 
				
			||||||
      "launchBrowser": true,
 | 
					      "launchBrowser": true,
 | 
				
			||||||
      "launchUrl": "weatherforecast",
 | 
					      "launchUrl": "currcycles",
 | 
				
			||||||
      "environmentVariables": {
 | 
					      "environmentVariables": {
 | 
				
			||||||
        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
					        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,11 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  "Kestrel": {
 | 
				
			||||||
 | 
					    "Endpoints": {
 | 
				
			||||||
 | 
					      "Http": {
 | 
				
			||||||
 | 
					        "Url": "http://*:65041"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
  "Logging": {
 | 
					  "Logging": {
 | 
				
			||||||
    "LogLevel": {
 | 
					    "LogLevel": {
 | 
				
			||||||
      "Default": "Information",
 | 
					      "Default": "Information",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user