1
0

Add REST API for Helen parser

This commit is contained in:
2021-07-02 17:08:13 +03:00
parent bec6898e38
commit 4b29325f32
6 changed files with 49 additions and 12 deletions

View File

@ -3,6 +3,7 @@ dependencies {
implementation "org.thymeleaf:thymeleaf:3.0.11.RELEASE"
implementation project(':caruna-invoice')
implementation project(':helen-invoice')
implementation project(':composite-parsers')
implementation 'org.apache.logging.log4j:log4j-core:2.11.0'

View File

@ -2,6 +2,7 @@ package com.devsoap.parsers.api;
import com.devsoap.parsers.caruna.CarunaParser;
import com.devsoap.parsers.composites.CarunaHelenParser;
import com.devsoap.parsers.helen.HelenParser;
import io.javalin.Javalin;
import io.javalin.http.Context;
import io.javalin.http.UploadedFile;
@ -43,11 +44,23 @@ public class Api {
get(ctx -> ctx.render(renderParserStaticPage(CarunaParser.class, "upload.html")));
post(ctx -> {
withUploadedFile(ctx.uploadedFiles().get(0), carunaFile -> {
renderParserOutput(ctx, result -> CarunaParser.run(carunaFile, result), "caruna-report.csv");
renderParserOutput(ctx, result -> CarunaParser
.run(carunaFile, result), "caruna-report.csv");
});
});
});
path(HelenParser.class.getSimpleName(), () -> {
get(ctx -> ctx.render(renderParserStaticPage(HelenParser.class, "upload.html")));
post(ctx -> {
withUploadedFile(ctx.uploadedFiles().get(0), helenFile -> {
renderParserOutput(ctx, result -> HelenParser
.run(helenFile, ctx.formParam("dayKwh"), ctx.formParam("nightKwh"), result)
, "caruna-report.csv");
});
});
});
path(CarunaHelenParser.class.getSimpleName(), () -> {
get(ctx -> ctx.render(renderParserStaticPage(CarunaHelenParser.class, "upload.html")));
post(ctx -> {
@ -59,6 +72,8 @@ public class Api {
});
});
});
});
});
}