Add project files.

This commit is contained in:
pkus
2025-01-24 13:37:01 +01:00
parent ee70a3c8af
commit ed726eea09
94 changed files with 4591 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using SytelineSaAppEfDataModel.Dtos;
using SytelineSaAppEfDataModel.Services;
namespace FaKrosnoApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class CustomerOrdersController(ICustomerOrderService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<CustomerOrderDto>>> GetAll()
{
IEnumerable<CustomerOrderDto?> ediCustomerOrders = await service.GetAll();
return Ok(ediCustomerOrders);
}
[HttpGet("by-order-number")]
public async Task<ActionResult<CustomerOrderDto?>> GetByCustomerOrderNumber([FromQuery] string customerOrderNumber)
{
CustomerOrderDto? scheduleOrder = await service.GetByOrderNumber(customerOrderNumber);
return scheduleOrder != null ? Ok(scheduleOrder) : NotFound();
}
}
}

View File

@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Mvc;
using SytelineSaAppEfDataModel.Dtos;
using SytelineSaAppEfDataModel.Services;
namespace FaKrosnoApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class EdiCustomerOrdersController(IEdiCustomerOrderService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<EdiCustomerOrderDto>>> GetAll()
{
IEnumerable<EdiCustomerOrderDto?> ediCustomerOrders = await service.GetAll();
return Ok(ediCustomerOrders);
}
[HttpGet("by-date")]
public async Task<ActionResult<IEnumerable<EdiCustomerOrderDto>>> GetByDate([FromQuery] DateTime date)
{
IEnumerable<EdiCustomerOrderDto?> scheduleOrders = await service.GetByDate(date);
return Ok(scheduleOrders);
}
[HttpGet("by-order-number")]
public async Task<ActionResult<EdiCustomerOrderDto>> GetByCustomerOrderNumber([FromQuery] string customerOrderNumber)
{
EdiCustomerOrderDto? scheduleOrder = await service.GetByOrderNumber(customerOrderNumber);
return scheduleOrder != null ? Ok(scheduleOrder) : NotFound();
}
[HttpPost("send-to-syteline")]
public async Task<ActionResult<int>> SendOrderToSyteline([FromQuery] string customerOrderNumber)
{
int result = await service.SendOrderToSyteline(customerOrderNumber);
return result > 0 ? Ok() : BadRequest();
}
}
}

View File

@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using SytelineSaAppEfDataModel.Dtos;
using SytelineSaAppEfDataModel.Services;
namespace FaKrosnoApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ErrorLogController(IErrorLogService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<ErrorLogDto>>> GetAll()
{
IEnumerable<ErrorLogDto?> errorLogs = await service.GetAll();
return Ok(errorLogs);
}
[HttpGet("by-order-number")]
public async Task<ActionResult<IEnumerable<ErrorLogDto>>> GetByCustomerOrderNumber([FromQuery] string customerOrderNumber)
{
var errorLogs = await service.GetByOrderNumber(customerOrderNumber);
return errorLogs.Any() ? Ok(errorLogs) : NotFound();
}
}
}

View File

@@ -0,0 +1,18 @@
using FaKrosnoEfDataModel.Dtos;
using FaKrosnoEfDataModel.Services;
using Microsoft.AspNetCore.Mvc;
namespace FaKrosnoApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ScheduleOrderDetailsController(IScheduleOrderDetailsService service) : Controller
{
[HttpGet("order/{scheduleOrderId:int}")]
public async Task<ActionResult<IEnumerable<ScheduleOrderDto>>> GetByScheduleOrderId(int scheduleOrderId)
{
IEnumerable<ScheduleOrderDetailDto>? scheduleOrderDetails = await service.GetScheduleOrderDetailsAsync(scheduleOrderId);
return Ok(scheduleOrderDetails);
}
}
}

View File

@@ -0,0 +1,50 @@
using AutoMapper;
using FaKrosnoEfDataModel;
using FaKrosnoEfDataModel.Dtos;
using FaKrosnoEfDataModel.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace FaKrosnoApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
//[Authorize]
public class ScheduleOrdersController(IScheduleOrderService service) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<ScheduleOrderDto>>> GetAll()
{
IEnumerable<ScheduleOrderDto?> scheduleOrders = await service.GetEntities();
return Ok(scheduleOrders);
}
[HttpGet("by-date")]
public async Task<ActionResult<IEnumerable<ScheduleOrderDto>>> GetByDate([FromQuery] DateTime date)
{
IEnumerable<ScheduleOrderDto?> scheduleOrders = await service.GetEntitiesByLastUpdateDate(date);
return Ok(scheduleOrders);
}
[HttpGet("{id:int}")]
public async Task<ActionResult<ScheduleOrderDto>> GetById(int id)
{
ScheduleOrderDto? scheduleOrder = await service.GetById(id);
return scheduleOrder != null ? Ok(scheduleOrder) : NotFound();
}
[HttpGet("recipient/{recipientId:int}")]
public async Task<ActionResult<IEnumerable<ScheduleOrderDto>>> GetByRecipientId(int recipientId)
{
IEnumerable<ScheduleOrderDto?> scheduleOrders = await service.GetByRecipientId(recipientId);
return Ok(scheduleOrders);
}
[HttpGet("recipient/{recipientId:int}/date")]
public async Task<ActionResult<IEnumerable<ScheduleOrderDto>>> GetByRecipientAndLastUpdateDate(int recipientId, [FromQuery] DateTime date)
{
IEnumerable<ScheduleOrderDto?> scheduleOrders = await service.GetByRecipientAndLastUpdateDate(recipientId, date);
return Ok(scheduleOrders);
}
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="NSwag.AspNetCore" Version="14.2.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FaKrosnoEfDataModel\FaKrosnoEfDataModel.csproj" />
<ProjectReference Include="..\SytelineSaAppEfDataModel\SytelineSaAppEfDataModel.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
@FaKrosnoApi_HostAddress = http://localhost:5152
### Access Swagger UI
GET {{FaKrosnoApi_HostAddress}}/swagger/index.html
Accept: text/html
###

73
FaKrosnoApi/Program.cs Normal file
View File

@@ -0,0 +1,73 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using FaKrosnoEfDataModel;
using FaKrosnoEfDataModel.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using SytelineSaAppEfDataModel;
using SytelineSaAppEfDataModel.Services;
using FaKrosnoMappingProfile = FaKrosnoEfDataModel.MappingProfile;
using SytelineSaAppMappingProfile = SytelineSaAppEfDataModel.MappingProfile;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddDbContext<FaKrosnoDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("FaKrosnoConnection")));
builder.Services.AddDbContext<SytelineSaAppDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("SytelineSaAppConnection")));
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApiDocument(config =>
{
config.Title = "FaKrosnoApi";
config.Version = "v1";
});
// Configure AutoMapper
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile));
// Configure JWT Authentication
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = builder.Configuration["Jwt:Issuer"],
ValidAudience = builder.Configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
};
});
builder.Services.AddScoped<IScheduleOrderService, ScheduleOrderService>();
builder.Services.AddScoped<IScheduleOrderDetailsService, ScheduleOrderDetailsService>();
builder.Services.AddScoped<IEdiCustomerOrderService, EdiCustomerOrderService>();
builder.Services.AddScoped<IErrorLogService, ErrorLogService>();
builder.Services.AddScoped<ICustomerOrderService, CustomerOrderService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
app.UseOpenApi(); // Serwuje dokument OpenAPI
app.UseSwaggerUi(); // Dodaje interfejs u¿ytkownika Swagger
//}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:16065",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger/index.html",
"applicationUrl": "http://localhost:5152",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger/index.html",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
{
"ConnectionStrings": {
"FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosnotest;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true",
"SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PRODTEST_SA_APP;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Jwt": {
"Key": "ThisIsASecretKeyForJwt",
"Issuer": "FaKrosnoApi",
"Audience": "FaKrosnoClient"
},
"AllowedHosts": "*"
}