@@ -6,15 +6,20 @@ import akka.stream.ActorMaterializer
6
6
import akka .util .Timeout
7
7
import hmda .api .http .HmdaCustomDirectives
8
8
import akka .http .scaladsl .server .Directives ._
9
- import hmda .api .model .public .ULIModel .{ Loan , ULI , ULICheck , ULIValidated }
9
+ import hmda .api .model .public .ULIModel ._
10
10
import hmda .validation .engine .lar .ULI ._
11
11
import akka .http .scaladsl .marshallers .sprayjson .SprayJsonSupport ._
12
12
import akka .http .scaladsl .marshalling .ToResponseMarshallable
13
+ import akka .http .scaladsl .model .StatusCodes
14
+ import akka .stream .scaladsl .Sink
15
+ import hmda .api .protocol .processing .ApiErrorProtocol
13
16
import hmda .api .protocol .public .ULIProtocol
17
+ import hmda .api .util .FlowUtils
14
18
15
19
import scala .concurrent .ExecutionContext
20
+ import scala .util .{ Failure , Success }
16
21
17
- trait PublicHttpApi extends PublicLarHttpApi with HmdaCustomDirectives with ULIProtocol {
22
+ trait PublicHttpApi extends PublicLarHttpApi with HmdaCustomDirectives with ApiErrorProtocol with ULIProtocol with FlowUtils {
18
23
implicit val system : ActorSystem
19
24
implicit val materializer : ActorMaterializer
20
25
implicit val timeout : Timeout
@@ -46,7 +51,27 @@ trait PublicHttpApi extends PublicLarHttpApi with HmdaCustomDirectives with ULIP
46
51
val isValid = validateULI(uli)
47
52
val validated = ULIValidated (isValid)
48
53
complete(ToResponseMarshallable (validated))
49
- }
54
+ } ~
55
+ fileUpload(" file" ) {
56
+ case (_, byteSource) =>
57
+ val validatedF = byteSource
58
+ .via(framing)
59
+ .map(_.utf8String)
60
+ .map(uli => (uli, validateULI(uli)))
61
+ .map(validated => ULIBatchValidated (validated._1, validated._2))
62
+ .runWith(Sink .seq)
63
+
64
+ onComplete(validatedF) {
65
+ case Success (validated) =>
66
+ complete(ToResponseMarshallable (ULIBatchValidatedResponse (validated)))
67
+ case Failure (error) =>
68
+ log.error(error.getLocalizedMessage)
69
+ complete(ToResponseMarshallable (StatusCodes .InternalServerError ))
70
+ }
71
+
72
+ case _ =>
73
+ complete(ToResponseMarshallable (StatusCodes .BadRequest ))
74
+ }
50
75
}
51
76
}
52
77
}
0 commit comments