WIP: ZugferdRESTService

This commit is contained in:
Jonathan Jenne
2020-03-10 16:33:28 +01:00
parent 1c2fb43f6a
commit 540d021e27
12 changed files with 259 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ZUGFeRDRESTService.Controllers
{
public class ZugferdValidationResponse
{
public string status;
public string message;
public List<string> errors;
public static string RESPONSE_OK = "OK";
public static string RESPONSE_ERROR = "ERROR";
public ZugferdValidationResponse()
{
status = RESPONSE_OK;
message = String.Empty;
errors = new List<string>();
}
}
[Route("api/[controller]")]
[ApiController]
public class ZugferdValidationController : ControllerBase
{
private readonly IZugferdValidationDataService _dataService;
public ZugferdValidationController(IZugferdValidationDataService dataService)
{
_dataService = dataService;
}
// POST: api/ZugferdValidation
[HttpPost]
public ZugferdValidationResponse Post(List<IFormFile> files)
{
var oFiles = files;
var oResponse = new ZugferdValidationResponse
{
message = "You uploaded " + oFiles.Count + " files."
};
return oResponse;
}
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ZUGFeRDRESTService
{
public interface IZugferdValidationDataService
{
}
}

View File

@@ -0,0 +1,16 @@
@page
@{
ViewData["Title"] = "UploadTest";
}
<h1>UploadTest</h1>
<form method="post" action="/api/zugferdvalidation" enctype="multipart/form-data" >
<p>
<span>PDF Datei:</span>
<input type="file" />
</p>
<button type="submit">Submit</button>
</form>

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ZUGFeRDRESTService
{
public class UploadTestModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ZUGFeRDRESTService
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

View File

@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52235",
"sslPort": 44388
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/zugferdvalidation",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ZUGFeRDRESTService": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/zugferdvalidation",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ZUGFeRDRESTService
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddNewtonsoftJson();
services.AddRazorPages();
services.AddTransient<IZugferdValidationDataService, ZugferdValidationDataService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRazorPages();
});
}
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ZUGFeRDRESTService
{
public class ZugferdValidationDataService: IZugferdValidationDataService
{
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}