From f658d4531e7f71237d42d0b20f00e0ca9cec977c Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Mon, 4 Mar 2024 10:21:01 +0330 Subject: [PATCH] Add project files. --- .dockerignore | 30 +++++++++++++ HamyanEdalat.Api/Dockerfile | 24 +++++++++++ HamyanEdalat.Api/HamyanEdalat.Api.csproj | 17 ++++++++ HamyanEdalat.Api/HamyanEdalat.Api.http | 6 +++ HamyanEdalat.Api/Program.cs | 42 +++++++++++++++++++ .../Properties/launchSettings.json | 40 ++++++++++++++++++ HamyanEdalat.Api/appsettings.Development.json | 8 ++++ HamyanEdalat.Api/appsettings.json | 9 ++++ HamyanEdalat.sln | 25 +++++++++++ 9 files changed, 201 insertions(+) create mode 100644 .dockerignore create mode 100644 HamyanEdalat.Api/Dockerfile create mode 100644 HamyanEdalat.Api/HamyanEdalat.Api.csproj create mode 100644 HamyanEdalat.Api/HamyanEdalat.Api.http create mode 100644 HamyanEdalat.Api/Program.cs create mode 100644 HamyanEdalat.Api/Properties/launchSettings.json create mode 100644 HamyanEdalat.Api/appsettings.Development.json create mode 100644 HamyanEdalat.Api/appsettings.json create mode 100644 HamyanEdalat.sln diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/HamyanEdalat.Api/Dockerfile b/HamyanEdalat.Api/Dockerfile new file mode 100644 index 0000000..aca889f --- /dev/null +++ b/HamyanEdalat.Api/Dockerfile @@ -0,0 +1,24 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app +EXPOSE 8080 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["HamyanEdalat.Api/HamyanEdalat.Api.csproj", "HamyanEdalat.Api/"] +RUN dotnet restore "./HamyanEdalat.Api/./HamyanEdalat.Api.csproj" +COPY . . +WORKDIR "/src/HamyanEdalat.Api" +RUN dotnet build "./HamyanEdalat.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./HamyanEdalat.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "HamyanEdalat.Api.dll"] \ No newline at end of file diff --git a/HamyanEdalat.Api/HamyanEdalat.Api.csproj b/HamyanEdalat.Api/HamyanEdalat.Api.csproj new file mode 100644 index 0000000..eaef27d --- /dev/null +++ b/HamyanEdalat.Api/HamyanEdalat.Api.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + true + Linux + + + + + + + + + diff --git a/HamyanEdalat.Api/HamyanEdalat.Api.http b/HamyanEdalat.Api/HamyanEdalat.Api.http new file mode 100644 index 0000000..e263669 --- /dev/null +++ b/HamyanEdalat.Api/HamyanEdalat.Api.http @@ -0,0 +1,6 @@ +@HamyanEdalat.Api_HostAddress = http://localhost:5025 + +GET {{HamyanEdalat.Api_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/HamyanEdalat.Api/Program.cs b/HamyanEdalat.Api/Program.cs new file mode 100644 index 0000000..284b700 --- /dev/null +++ b/HamyanEdalat.Api/Program.cs @@ -0,0 +1,42 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +var summaries = new[] +{ + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" +}; + +app.MapGet("/weatherforecast", () => +{ + var forecast = Enumerable.Range(1, 5).Select(index => + new WeatherForecast + ( + DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + Random.Shared.Next(-20, 55), + summaries[Random.Shared.Next(summaries.Length)] + )) + .ToArray(); + return forecast; +}) +.WithName("GetWeatherForecast") +.WithOpenApi(); + +app.Run(); + +internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) +{ + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); +} diff --git a/HamyanEdalat.Api/Properties/launchSettings.json b/HamyanEdalat.Api/Properties/launchSettings.json new file mode 100644 index 0000000..701a89c --- /dev/null +++ b/HamyanEdalat.Api/Properties/launchSettings.json @@ -0,0 +1,40 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5025" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:38588", + "sslPort": 0 + } + } +} \ No newline at end of file diff --git a/HamyanEdalat.Api/appsettings.Development.json b/HamyanEdalat.Api/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/HamyanEdalat.Api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/HamyanEdalat.Api/appsettings.json b/HamyanEdalat.Api/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/HamyanEdalat.Api/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/HamyanEdalat.sln b/HamyanEdalat.sln new file mode 100644 index 0000000..f44eda3 --- /dev/null +++ b/HamyanEdalat.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34316.72 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HamyanEdalat.Api", "HamyanEdalat.Api\HamyanEdalat.Api.csproj", "{FA52F1AF-507E-4F2A-8ACB-FC7B6D275BCA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FA52F1AF-507E-4F2A-8ACB-FC7B6D275BCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA52F1AF-507E-4F2A-8ACB-FC7B6D275BCA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA52F1AF-507E-4F2A-8ACB-FC7B6D275BCA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA52F1AF-507E-4F2A-8ACB-FC7B6D275BCA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1B87B176-1EBC-41CB-A88D-42840BF9CB8B} + EndGlobalSection +EndGlobal