first commit

This commit is contained in:
2026-04-16 21:05:21 +04:30
commit 49591985ac
283 changed files with 12716 additions and 0 deletions
@@ -0,0 +1,36 @@
using Vizhvizh.BuildingBlocks.Application.Contract;
namespace Vizhvizh.Shop.Api.Configurations
{
public class ExecutionContextAccessor : IExecutionContextAccessor
{
private readonly IHttpContextAccessor _httpContextAccessor;
public ExecutionContextAccessor(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public Guid UserId
{
get
{
if (_httpContextAccessor
.HttpContext?
.User?
.Claims?
.SingleOrDefault(x => x.Type == "sub")?
.Value != null)
{
return Guid.Parse(_httpContextAccessor.HttpContext.User.Claims.Single(
x => x.Type == "sub").Value);
}
throw new ApplicationException("User context is not available");
}
}
public bool IsAvailable => _httpContextAccessor.HttpContext != null;
}
}
@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Mvc;
using Vizhvizh.BuildingBlocks.Infrastructure;
using Vizhvizh.Shop.ApplicationContract.DTOs;
using Vizhvizh.Shop.ApplicationContract.Queries;
namespace Vizhvizh.Shop.Api.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ShopController(IExecutor executor) : ControllerBase
{
[HttpGet]
public async Task<ActionResult<ShopDTO?>> GetById([FromQuery] long shopId, CancellationToken cancellationToken)
=> Ok(await executor.Execute(new GetShopByIdQuery(shopId), cancellationToken));
}
}
@@ -0,0 +1,45 @@
using Microsoft.AspNetCore.Mvc;
using Vizhvizh.BuildingBlocks.Infrastructure;
using Vizhvizh.Shop.Api.RequestModels;
using Vizhvizh.Shop.ApplicationContract.Commands;
using Vizhvizh.Shop.ApplicationContract.DTOs;
using Vizhvizh.Shop.ApplicationContract.Queries;
using Vizhvizh.Shop.Domain.Sliders.ValuesObjects;
namespace Vizhvizh.Shop.Api.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class SliderController(IExecutor executor) : ControllerBase
{
[HttpPost]
public async Task<ActionResult> AddMainSlider([FromBody] CreateSliderRequestModel request, CancellationToken cancellationToken)
{
await executor.Execute(new CreateSliderCommand(request.Title, request.ImageUrl, request.LinkUrl, SliderKeyType.Main, null), cancellationToken);
return Ok();
}
[HttpPost]
public async Task<ActionResult> AddShopSlider([FromHeader] long shopId, [FromBody] CreateSliderRequestModel request, CancellationToken cancellationToken)
{
await executor.Execute(new CreateSliderCommand(request.Title, request.ImageUrl, request.LinkUrl, SliderKeyType.Shop, shopId.ToString()), cancellationToken);
return Ok();
}
[HttpPost]
public async Task<ActionResult> AddCategorySlider([FromHeader] long categoryId, [FromBody] CreateSliderRequestModel request, CancellationToken cancellationToken)
{
await executor.Execute(new CreateSliderCommand(request.Title, request.ImageUrl, request.LinkUrl, SliderKeyType.Category, categoryId.ToString()), cancellationToken);
return Ok();
}
[HttpGet]
public async Task<ActionResult<IEnumerable<SliderDTO>>> GetByKey([FromQuery] GetSlidersByKeyQuery request,CancellationToken cancellationToken)
{
var result = await executor.Execute(request,cancellationToken);
return Ok(result);
}
}
}
+33
View File
@@ -0,0 +1,33 @@
using Vizhvizh.BuildingBlocks.Application.Contract;
using Vizhvizh.Shop.Api.Configurations;
using Vizhvizh.Shop.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddSingleton<IExecutionContextAccessor, ExecutionContextAccessor>();
ShopStartup.Initialize(builder.Services, builder.Configuration.GetConnectionString("Shop")!);
builder.Services.AddControllers();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI(opt =>
{
opt.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
});
//app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
@@ -0,0 +1,51 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "swagger/index.html",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5034"
},
"https": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "swagger/index.html",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7220;http://localhost:5034"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": false,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:16715",
"sslPort": 44331
}
}
}
@@ -0,0 +1,3 @@
namespace Vizhvizh.Shop.Api.RequestModels;
public record CreateSliderRequestModel(string Title,string ImageUrl, string LinkUrl);
+6
View File
@@ -0,0 +1,6 @@
@Vizhvizh.Shop.Api_HostAddress = http://localhost:5034
GET {{Vizhvizh.Shop.Api_HostAddress}}/weatherforecast/
Accept: application/json
###
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>false</InvariantGlobalization>
<UserSecretsId>04e2646d-0282-4616-88fd-1df92577ae95</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.25">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Vichvich.Shop.Infrastructure\Vizhvizh.Shop.Infrastructure.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"Shop": "Data Source=.;Initial Catalog=Vizhvizh.Shop;Integrated Security=True;Trusted_Connection=True; MultipleActiveResultSets=true;TrustServerCertificate=True;"
},
"AllowedHosts": "*"
}