From 0b2c77d4cc80eee34dd0de71f7cf1d1d01bee89c Mon Sep 17 00:00:00 2001 From: quentin Date: Tue, 16 Apr 2024 18:38:11 -0500 Subject: [PATCH] Added api project boilerplate --- .gitignore | 3 ++ API/API.csproj | 24 +++++++++++++++ API/Program.cs | 47 ++++++++++++++++++++++++++++++ API/Properties/launchSettings.json | 41 ++++++++++++++++++++++++++ sanAntonioSeniorGolf.sln | 6 ++++ 5 files changed, 121 insertions(+) create mode 100644 API/API.csproj create mode 100644 API/Program.cs create mode 100644 API/Properties/launchSettings.json diff --git a/.gitignore b/.gitignore index 7e6fa92..7292219 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /DAL/bin/ /DAL/obj/ +/API/bin/ +/API/obj/ +/API/appsettings.* diff --git a/API/API.csproj b/API/API.csproj new file mode 100644 index 0000000..55d898a --- /dev/null +++ b/API/API.csproj @@ -0,0 +1,24 @@ + + + + net8.0 + enable + enable + true + + + + + + + + + + + + + + + + + diff --git a/API/Program.cs b/API/Program.cs new file mode 100644 index 0000000..2b2dc68 --- /dev/null +++ b/API/Program.cs @@ -0,0 +1,47 @@ +using DAL.Contexts; +using Microsoft.EntityFrameworkCore; +using System.Reflection; +using InvalidOperationException = System.InvalidOperationException; + +namespace API +{ + internal class Program + { + public static void Main(string[] args) + { + WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + ConfigurationManager configManager = builder.Configuration; + + builder.Services.AddControllers(); + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(options => + { + string xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + options.IncludeXmlComments(xmlPath, true); + }); + + builder.Services.AddDbContext(options => + { + options.UseMySQL(builder.Configuration["connectionString"] ?? throw new InvalidOperationException("Connection String is null")); + }); + + WebApplication app = builder.Build(); + + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseCookiePolicy(new CookiePolicyOptions + { + MinimumSameSitePolicy = SameSiteMode.Strict + }); + + app.UseHttpsRedirection(); + app.MapControllers(); + app.Run(); + } + } +} \ No newline at end of file diff --git a/API/Properties/launchSettings.json b/API/Properties/launchSettings.json new file mode 100644 index 0000000..6ddd4dc --- /dev/null +++ b/API/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:36321", + "sslPort": 44359 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5279", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7089;http://localhost:5279", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/sanAntonioSeniorGolf.sln b/sanAntonioSeniorGolf.sln index 1c2b4fb..2743f9f 100644 --- a/sanAntonioSeniorGolf.sln +++ b/sanAntonioSeniorGolf.sln @@ -2,6 +2,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL", "DAL\DAL.csproj", "{EE2CF24D-1C19-4915-A6BB-7A244F527CE4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +14,9 @@ Global {EE2CF24D-1C19-4915-A6BB-7A244F527CE4}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE2CF24D-1C19-4915-A6BB-7A244F527CE4}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE2CF24D-1C19-4915-A6BB-7A244F527CE4}.Release|Any CPU.Build.0 = Release|Any CPU + {829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal