Initial commit

This commit is contained in:
Egor 2024-10-29 23:38:02 +03:00
commit 9d232598cd
19 changed files with 267 additions and 0 deletions

25
.dockerignore Normal file
View file

@ -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

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0-rc.2.24474.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0-rc.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
</Project>

View file

@ -0,0 +1,6 @@
@DeliveryWebApi_HostAddress = http://localhost:5153
GET {{DeliveryWebApi_HostAddress}}/weatherforecast/
Accept: application/json
###

23
DeliveryWebApi/Dockerfile Normal file
View file

@ -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"]

View file

@ -0,0 +1,6 @@
namespace DeliveryWebApi.Model;
public class BaseEntity
{
public Guid Id { get; init; } = Guid.NewGuid();
}

View file

@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore;
namespace DeliveryWebApi.Model;
public class DeliveryContext(DbContextOptions<DeliveryContext> options) : DbContext(options)
{
public DbSet<District> Districts { get; init; }
public DbSet<Order> Orders { get; init; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<District>()
.HasMany(e => e.Orders)
.WithOne(e => e.District)
.HasForeignKey(e => e.DistrictId)
.IsRequired();
}
}

View file

@ -0,0 +1,7 @@
namespace DeliveryWebApi.Model;
public class District(string name) : BaseEntity
{
public string Name { get; init; }
public ICollection<Order> Orders { get; init; } = new List<Order>();
}

View file

@ -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; }
}

38
DeliveryWebApi/Program.cs Normal file
View file

@ -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<bool>("UseInMemoryDatabase"))
builder.Services.AddDbContext<DeliveryContext>(options => options.UseInMemoryDatabase("Delivery"));
else
{
builder.Services.AddDbContext<DeliveryContext>(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();

View file

@ -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"
}
}
}
}

View file

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View file

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

16
EffetiveTask.sln Normal file
View file

@ -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

View file

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWebApplication_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F847c7bc70f83436e9c281d8cea5531a17d10_003F7f_003F26f6c2e2_003FWebApplication_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>