Готово

This commit is contained in:
Allllen4a 2024-04-07 19:43:03 +04:00
parent c664ac9f46
commit d9463e4f4c
17 changed files with 233 additions and 207 deletions

View File

@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "Pi
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{AA78A273-0E83-4B45-A155-F9CAFD64E895}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{AA78A273-0E83-4B45-A155-F9CAFD64E895}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaRestApi", "PizzeriaRestApi\PizzeriaRestApi.csproj", "{86BFFB1F-C08C-4939-91F3-7A582996065B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaRestApi", "PizzeriaRestApi\PizzeriaRestApi.csproj", "{6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaClientApp", "PizzeriaClientApp\PizzeriaClientApp.csproj", "{11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaClientApp", "PizzeriaClientApp\PizzeriaClientApp.csproj", "{8E483155-EC2D-460A-9B65-1B6831C5E441}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -55,14 +55,14 @@ Global
{AA78A273-0E83-4B45-A155-F9CAFD64E895}.Debug|Any CPU.Build.0 = Debug|Any CPU {AA78A273-0E83-4B45-A155-F9CAFD64E895}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.Build.0 = Release|Any CPU {AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.Build.0 = Release|Any CPU
{86BFFB1F-C08C-4939-91F3-7A582996065B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86BFFB1F-C08C-4939-91F3-7A582996065B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86BFFB1F-C08C-4939-91F3-7A582996065B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86BFFB1F-C08C-4939-91F3-7A582996065B}.Release|Any CPU.Build.0 = Release|Any CPU {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Release|Any CPU.Build.0 = Release|Any CPU
{11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8E483155-EC2D-460A-9B65-1B6831C5E441}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E483155-EC2D-460A-9B65-1B6831C5E441}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E483155-EC2D-460A-9B65-1B6831C5E441}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Release|Any CPU.Build.0 = Release|Any CPU {8E483155-EC2D-460A-9B65-1B6831C5E441}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -5,45 +5,45 @@ using System.Text;
namespace PizzeriaClientApp namespace PizzeriaClientApp
{ {
public class APIClient public class APIClient
{ {
private static readonly HttpClient _client = new(); private static readonly HttpClient _client = new();
public static ClientViewModel? Client { get; set; } = null; public static ClientViewModel? Client { get; set; } = null;
public static void Connect(IConfiguration configuration) public static void Connect(IConfiguration configuration)
{ {
_client.BaseAddress = new Uri(configuration["IPAddress"]); _client.BaseAddress = new Uri(configuration["IPAddress"]);
_client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
} }
public static T? GetRequest<T>(string requestUrl) public static T? GetRequest<T>(string requestUrl)
{ {
var response = _client.GetAsync(requestUrl); var response = _client.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result; var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode) if (response.Result.IsSuccessStatusCode)
{ {
return JsonConvert.DeserializeObject<T>(result); return JsonConvert.DeserializeObject<T>(result);
} }
else else
{ {
throw new Exception(result); throw new Exception(result);
} }
} }
public static void PostRequest<T>(string requestUrl, T model) public static void PostRequest<T>(string requestUrl, T model)
{ {
var json = JsonConvert.SerializeObject(model); var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json"); var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _client.PostAsync(requestUrl, data); var response = _client.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result; var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode) if (!response.Result.IsSuccessStatusCode)
{ {
throw new Exception(result); throw new Exception(result);
} }
} }
} }
} }

View File

@ -39,7 +39,7 @@ namespace PizzeriaClientApp.Controllers
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
throw new Exception("Вы не авторизованы"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{ {
@ -121,7 +121,7 @@ namespace PizzeriaClientApp.Controllers
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
throw new Exception("Вы не авторизованы"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (count <= 0) if (count <= 0)
{ {

View File

@ -1,9 +1,9 @@
namespace PizzeriaClientApp.Models namespace PizzeriaClientApp.Models
{ {
public class ErrorViewModel public class ErrorViewModel
{ {
public string? RequestId { get; set; } public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
} }
} }

View File

@ -6,16 +6,12 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Include="..\PizzeriaContracts\ViewModels\OrderViewModel.cs" Link="OrderViewModel.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" /> <ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -8,9 +8,9 @@ var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();
@ -21,7 +21,7 @@ app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllerRoute( app.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run(); app.Run();

View File

@ -3,8 +3,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:28755", "applicationUrl": "http://localhost:59663",
"sslPort": 44389 "sslPort": 44301
} }
}, },
"profiles": { "profiles": {
@ -12,7 +12,7 @@
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "https://localhost:7056;http://localhost:5138", "applicationUrl": "https://localhost:7132;http://localhost:5220",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

View File

@ -6,5 +6,5 @@
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"IPAddress": "http://localhost:5104/" "IPAddress": "http://localhost:5129/"
} }

View File

@ -1,68 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PizzeriaDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitClient : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ClientId",
table: "Orders",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.AddForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropIndex(
name: "IX_Orders_ClientId",
table: "Orders");
migrationBuilder.DropColumn(
name: "ClientId",
table: "Orders");
}
}
}

View File

@ -12,8 +12,8 @@ using PizzeriaDatabaseImplement;
namespace PizzeriaDatabaseImplement.Migrations namespace PizzeriaDatabaseImplement.Migrations
{ {
[DbContext(typeof(PizzeriaDatabase))] [DbContext(typeof(PizzeriaDatabase))]
[Migration("20240403141650_InitClient")] [Migration("20240407121638_InitMigration")]
partial class InitClient partial class InitMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)

View File

@ -5,10 +5,27 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace PizzeriaDatabaseImplement.Migrations namespace PizzeriaDatabaseImplement.Migrations
{ {
/// <inheritdoc />
public partial class InitMigration : Migration public partial class InitMigration : Migration
{ {
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Components", name: "Components",
columns: table => new columns: table => new
@ -43,6 +60,7 @@ namespace PizzeriaDatabaseImplement.Migrations
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
ClientId = table.Column<int>(type: "int", nullable: false),
PizzaId = table.Column<int>(type: "int", nullable: false), PizzaId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false), Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false), Sum = table.Column<double>(type: "float", nullable: false),
@ -53,6 +71,12 @@ namespace PizzeriaDatabaseImplement.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Orders", x => x.Id); table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_Orders_Pizzas_PizzaId", name: "FK_Orders_Pizzas_PizzaId",
column: x => x.PizzaId, column: x => x.PizzaId,
@ -88,6 +112,11 @@ namespace PizzeriaDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Orders_PizzaId", name: "IX_Orders_PizzaId",
table: "Orders", table: "Orders",
@ -104,6 +133,7 @@ namespace PizzeriaDatabaseImplement.Migrations
column: "PizzaId"); column: "PizzaId");
} }
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropTable( migrationBuilder.DropTable(
@ -112,6 +142,9 @@ namespace PizzeriaDatabaseImplement.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "PizzaComponents"); name: "PizzaComponents");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Components"); name: "Components");

View File

@ -12,17 +12,43 @@ using PizzeriaDatabaseImplement;
namespace PizzeriaDatabaseImplement.Migrations namespace PizzeriaDatabaseImplement.Migrations
{ {
[DbContext(typeof(PizzeriaDatabase))] [DbContext(typeof(PizzeriaDatabase))]
[Migration("20240309113549_InitMigration")] [Migration("20240407121716_ClientMigration")]
partial class InitMigration partial class ClientMigration
{ {
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "6.0.27") .HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128); .HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
{ {
@ -30,7 +56,7 @@ namespace PizzeriaDatabaseImplement.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName") b.Property<string>("ComponentName")
.IsRequired() .IsRequired()
@ -50,7 +76,10 @@ namespace PizzeriaDatabaseImplement.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("int"); .HasColumnType("int");
@ -72,6 +101,8 @@ namespace PizzeriaDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("PizzaId"); b.HasIndex("PizzaId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -83,7 +114,7 @@ namespace PizzeriaDatabaseImplement.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PizzaName") b.Property<string>("PizzaName")
.IsRequired() .IsRequired()
@ -103,7 +134,7 @@ namespace PizzeriaDatabaseImplement.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId") b.Property<int>("ComponentId")
.HasColumnType("int"); .HasColumnType("int");
@ -125,12 +156,20 @@ namespace PizzeriaDatabaseImplement.Migrations
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b => modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("PizzeriaDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("PizzaId") .HasForeignKey("PizzaId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client");
b.Navigation("Pizza"); b.Navigation("Pizza");
}); });
@ -153,6 +192,11 @@ namespace PizzeriaDatabaseImplement.Migrations
b.Navigation("Pizza"); b.Navigation("Pizza");
}); });
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
{ {
b.Navigation("PizzaComponents"); b.Navigation("PizzaComponents");

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PizzeriaDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class ClientMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -6,64 +6,64 @@ using PizzeriaContracts.ViewModels;
namespace PizzeriaRestApi.Controllers namespace PizzeriaRestApi.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public class ClientController : Controller public class ClientController : Controller
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IClientLogic _logic; private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger) public ClientController(IClientLogic logic, ILogger<ClientController> logger)
{ {
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
} }
[HttpGet] [HttpGet]
public ClientViewModel? Login(string login, string password) public ClientViewModel? Login(string login, string password)
{ {
try try
{ {
return _logic.ReadElement(new ClientSearchModel return _logic.ReadElement(new ClientSearchModel
{ {
Email = login, Email = login,
Password = password Password = password
}); });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка входа в систему"); _logger.LogError(ex, "Ошибка входа в систему");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void Register(ClientBindingModel model) public void Register(ClientBindingModel model)
{ {
try try
{ {
_logic.Create(model); _logic.Create(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка регистрации"); _logger.LogError(ex, "Ошибка регистрации");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void UpdateData(ClientBindingModel model) public void UpdateData(ClientBindingModel model)
{ {
try try
{ {
_logic.Update(model); _logic.Update(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка обновления данных"); _logger.LogError(ex, "Ошибка обновления данных");
throw; throw;
} }
} }
} }
} }

View File

@ -23,7 +23,7 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c => builder.Services.AddSwaggerGen(c =>
{ {
c.SwaggerDoc("v1", new OpenApiInfo { Title = "PizzeriaRestApi", Version = "v1" }); c.SwaggerDoc("v1", new OpenApiInfo { Title = "PizzeriaRestApi", Version = "v1" });
}); });
var app = builder.Build(); var app = builder.Build();
@ -31,8 +31,8 @@ var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzeriaRestApi v1")); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzeriaRestApi v1"));
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();

View File

@ -4,8 +4,8 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:47639", "applicationUrl": "http://localhost:10859",
"sslPort": 44347 "sslPort": 44324
} }
}, },
"profiles": { "profiles": {
@ -14,7 +14,7 @@
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "swagger", "launchUrl": "swagger",
"applicationUrl": "https://localhost:7075;http://localhost:5104", "applicationUrl": "https://localhost:7043;http://localhost:5129",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

View File

@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Pizzeria;
using PizzeriaContracts.BindingModels; using PizzeriaContracts.BindingModels;
using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.BusinessLogicsContracts;