diff --git a/NucuCar.WebApi/Controllers/WeatherForecastController.cs b/NucuCar.WebApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..da04865 --- /dev/null +++ b/NucuCar.WebApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace NucuCar.WebApi.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 _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/NucuCar.WebApi/NucuCar.WebApi.csproj b/NucuCar.WebApi/NucuCar.WebApi.csproj new file mode 100644 index 0000000..68ded6d --- /dev/null +++ b/NucuCar.WebApi/NucuCar.WebApi.csproj @@ -0,0 +1,8 @@ + + + + netcoreapp3.1 + + + + diff --git a/NucuCar.WebApi/Program.cs b/NucuCar.WebApi/Program.cs new file mode 100644 index 0000000..918101b --- /dev/null +++ b/NucuCar.WebApi/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace NucuCar.WebApi +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); + } +} \ No newline at end of file diff --git a/NucuCar.WebApi/Properties/launchSettings.json b/NucuCar.WebApi/Properties/launchSettings.json new file mode 100644 index 0000000..a7f8f4c --- /dev/null +++ b/NucuCar.WebApi/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:3724", + "sslPort": 44304 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "NucuCar.WebApi": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/NucuCar.WebApi/Startup.cs b/NucuCar.WebApi/Startup.cs new file mode 100644 index 0000000..a0446da --- /dev/null +++ b/NucuCar.WebApi/Startup.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace NucuCar.WebApi +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); + } + } +} \ No newline at end of file diff --git a/NucuCar.WebApi/WeatherForecast.cs b/NucuCar.WebApi/WeatherForecast.cs new file mode 100644 index 0000000..e904095 --- /dev/null +++ b/NucuCar.WebApi/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace NucuCar.WebApi +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int) (TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} \ No newline at end of file diff --git a/NucuCar.WebApi/appsettings.Development.json b/NucuCar.WebApi/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/NucuCar.WebApi/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/NucuCar.WebApi/appsettings.json b/NucuCar.WebApi/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/NucuCar.WebApi/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/NucuCar.sln b/NucuCar.sln index dc1abb2..5a64e96 100644 --- a/NucuCar.sln +++ b/NucuCar.sln @@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NucuCar.UnitTests", "NucuCa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NucuCar.Domain.Telemetry", "NucuCar.Domain.Telemetry\NucuCar.Domain.Telemetry.csproj", "{C20407F3-AB62-4590-B4FF-A0DCFCFA232B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NucuCar.WebApi", "NucuCar.WebApi\NucuCar.WebApi.csproj", "{CC5A6A6C-C7F6-4816-A96C-FF9D93D69F5A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -36,5 +38,9 @@ Global {C20407F3-AB62-4590-B4FF-A0DCFCFA232B}.Debug|Any CPU.Build.0 = Debug|Any CPU {C20407F3-AB62-4590-B4FF-A0DCFCFA232B}.Release|Any CPU.ActiveCfg = Release|Any CPU {C20407F3-AB62-4590-B4FF-A0DCFCFA232B}.Release|Any CPU.Build.0 = Release|Any CPU + {CC5A6A6C-C7F6-4816-A96C-FF9D93D69F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC5A6A6C-C7F6-4816-A96C-FF9D93D69F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC5A6A6C-C7F6-4816-A96C-FF9D93D69F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC5A6A6C-C7F6-4816-A96C-FF9D93D69F5A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal