commit 9d232598cd1cfafde8bbfd3a9fb14f9665c0f2dd Author: erius Date: Tue Oct 29 23:38:02 2024 +0300 Initial commit diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38bece4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*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 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/.idea/.idea.EffetiveTask/.idea/.gitignore b/.idea/.idea.EffetiveTask/.idea/.gitignore new file mode 100644 index 0000000..bbf4674 --- /dev/null +++ b/.idea/.idea.EffetiveTask/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/projectSettingsUpdater.xml +/modules.xml +/contentModel.xml +/.idea.EffetiveTask.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.EffetiveTask/.idea/encodings.xml b/.idea/.idea.EffetiveTask/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.EffetiveTask/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.EffetiveTask/.idea/indexLayout.xml b/.idea/.idea.EffetiveTask/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.EffetiveTask/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.EffetiveTask/.idea/vcs.xml b/.idea/.idea.EffetiveTask/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.EffetiveTask/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DeliveryWebApi/DeliveryWebApi.csproj b/DeliveryWebApi/DeliveryWebApi.csproj new file mode 100644 index 0000000..5b4161d --- /dev/null +++ b/DeliveryWebApi/DeliveryWebApi.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + Linux + + + + + + + + + + + + .dockerignore + + + + diff --git a/DeliveryWebApi/DeliveryWebApi.http b/DeliveryWebApi/DeliveryWebApi.http new file mode 100644 index 0000000..7f482ce --- /dev/null +++ b/DeliveryWebApi/DeliveryWebApi.http @@ -0,0 +1,6 @@ +@DeliveryWebApi_HostAddress = http://localhost:5153 + +GET {{DeliveryWebApi_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/DeliveryWebApi/Dockerfile b/DeliveryWebApi/Dockerfile new file mode 100644 index 0000000..b9e4567 --- /dev/null +++ b/DeliveryWebApi/Dockerfile @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["DeliveryWebApi/DeliveryWebApi.csproj", "DeliveryWebApi/"] +RUN dotnet restore "DeliveryWebApi/DeliveryWebApi.csproj" +COPY . . +WORKDIR "/src/DeliveryWebApi" +RUN dotnet build "DeliveryWebApi.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "DeliveryWebApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "DeliveryWebApi.dll"] diff --git a/DeliveryWebApi/Model/BaseEntity.cs b/DeliveryWebApi/Model/BaseEntity.cs new file mode 100644 index 0000000..8414305 --- /dev/null +++ b/DeliveryWebApi/Model/BaseEntity.cs @@ -0,0 +1,6 @@ +namespace DeliveryWebApi.Model; + +public class BaseEntity +{ + public Guid Id { get; init; } = Guid.NewGuid(); +} \ No newline at end of file diff --git a/DeliveryWebApi/Model/DeliveryContext.cs b/DeliveryWebApi/Model/DeliveryContext.cs new file mode 100644 index 0000000..d01c552 --- /dev/null +++ b/DeliveryWebApi/Model/DeliveryContext.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; + +namespace DeliveryWebApi.Model; + +public class DeliveryContext(DbContextOptions options) : DbContext(options) +{ + public DbSet Districts { get; init; } + public DbSet Orders { get; init; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasMany(e => e.Orders) + .WithOne(e => e.District) + .HasForeignKey(e => e.DistrictId) + .IsRequired(); + } +} \ No newline at end of file diff --git a/DeliveryWebApi/Model/District.cs b/DeliveryWebApi/Model/District.cs new file mode 100644 index 0000000..f02f328 --- /dev/null +++ b/DeliveryWebApi/Model/District.cs @@ -0,0 +1,7 @@ +namespace DeliveryWebApi.Model; + +public class District(string name) : BaseEntity +{ + public string Name { get; init; } + public ICollection Orders { get; init; } = new List(); +} \ No newline at end of file diff --git a/DeliveryWebApi/Model/Order.cs b/DeliveryWebApi/Model/Order.cs new file mode 100644 index 0000000..3baaef6 --- /dev/null +++ b/DeliveryWebApi/Model/Order.cs @@ -0,0 +1,9 @@ +namespace DeliveryWebApi.Model; + +public class Order : BaseEntity +{ + public float Weight { get; init; } + public Guid DistrictId { get; init; } + public District District { get; init; } = null!; + public DateTime DeliveryDate { get; init; } +} \ No newline at end of file diff --git a/DeliveryWebApi/Program.cs b/DeliveryWebApi/Program.cs new file mode 100644 index 0000000..5edc626 --- /dev/null +++ b/DeliveryWebApi/Program.cs @@ -0,0 +1,38 @@ +using DeliveryWebApi.Model; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +if (builder.Configuration.GetValue("UseInMemoryDatabase")) + builder.Services.AddDbContext(options => options.UseInMemoryDatabase("Delivery")); +else +{ + builder.Services.AddDbContext(options => + { + var connectionString = builder.Configuration.GetConnectionString("DatabaseConnection"); + options.UseNpgsql(connectionString); + }); +} + + +var app = builder.Build(); + +// swagger setup +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.MapPut("/addOrder", (float weight, long districtId, DateTime deliveryTime) => + { + + }) + .WithName("GetWeatherForecast") + .WithOpenApi(); + +app.Run(); diff --git a/DeliveryWebApi/Properties/launchSettings.json b/DeliveryWebApi/Properties/launchSettings.json new file mode 100644 index 0000000..14557e3 --- /dev/null +++ b/DeliveryWebApi/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:11675", + "sslPort": 44327 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5153", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7248;http://localhost:5153", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/DeliveryWebApi/appsettings.Development.json b/DeliveryWebApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/DeliveryWebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/DeliveryWebApi/appsettings.json b/DeliveryWebApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/DeliveryWebApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/EffetiveTask.sln b/EffetiveTask.sln new file mode 100644 index 0000000..1f3e157 --- /dev/null +++ b/EffetiveTask.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeliveryWebApi", "DeliveryWebApi\DeliveryWebApi.csproj", "{DD287298-7F16-493C-9170-69D6C4869575}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DD287298-7F16-493C-9170-69D6C4869575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD287298-7F16-493C-9170-69D6C4869575}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD287298-7F16-493C-9170-69D6C4869575}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD287298-7F16-493C-9170-69D6C4869575}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/EffetiveTask.sln.DotSettings.user b/EffetiveTask.sln.DotSettings.user new file mode 100644 index 0000000..eae4c8e --- /dev/null +++ b/EffetiveTask.sln.DotSettings.user @@ -0,0 +1,2 @@ + + ForceIncluded \ No newline at end of file