Skip to content

Commit 070b204

Browse files
Improve formatting
1 parent 49aedc7 commit 070b204

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

Examples/LambdaFunctions/Sources/ProductAPI/APIGateway+Extensions.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ extension APIGateway.V2.Response {
3737
]
3838

3939
init(with error: Error, statusCode: AWSLambdaEvents.HTTPResponseStatus) {
40-
4140
self.init(
4241
statusCode: statusCode,
4342
headers: APIGateway.V2.Response.defaultHeaders,
@@ -49,7 +48,6 @@ extension APIGateway.V2.Response {
4948

5049
init<Out: Encodable>(with object: Out, statusCode: AWSLambdaEvents.HTTPResponseStatus) {
5150
let encoder = JSONEncoder()
52-
5351
var body: String = "{}"
5452
if let data = try? encoder.encode(object) {
5553
body = String(data: data, encoding: .utf8) ?? body
@@ -61,7 +59,6 @@ extension APIGateway.V2.Response {
6159
body: body,
6260
isBase64Encoded: false
6361
)
64-
6562
}
6663

6764
init<Out: Encodable>(with result: Result<Out, Error>, statusCode: AWSLambdaEvents.HTTPResponseStatus) {

Examples/LambdaFunctions/Sources/ProductAPI/ProductLambda.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,22 @@ struct EmptyResponse: Codable {
3434

3535
struct ProductLambda: LambdaHandler {
3636

37-
//typealias In = APIGateway.SimpleRequest
3837
typealias In = APIGateway.V2.Request
3938
typealias Out = APIGateway.V2.Response
4039

4140
let dbTimeout: Int64 = 30
42-
4341
let region: Region
4442
let db: AWSDynamoDB.DynamoDB
4543
let service: ProductService
4644
let tableName: String
4745
let operation: Operation
48-
4946
var httpClient: HTTPClient
5047

5148
static func currentRegion() -> Region {
52-
5349
if let awsRegion = Lambda.env("AWS_REGION") {
5450
let value = Region(rawValue: awsRegion)
5551
return value
56-
5752
} else {
58-
//Default configuration
5953
return .useast1
6054
}
6155
}
@@ -89,7 +83,6 @@ struct ProductLambda: LambdaHandler {
8983

9084
self.db = AWSDynamoDB.DynamoDB(region: region, httpClientProvider: .shared(self.httpClient))
9185
logger.info("DynamoDB")
92-
9386
self.tableName = (try? Self.tableName()) ?? ""
9487

9588
self.service = ProductService(
@@ -103,9 +96,8 @@ struct ProductLambda: LambdaHandler {
10396
context: Lambda.Context, event: APIGateway.V2.Request,
10497
callback: @escaping (Result<APIGateway.V2.Response, Error>) -> Void
10598
) {
106-
let _ = ProductLambdaHandler(service: service, operation: operation).handle(
107-
context: context, event: event
108-
)
99+
let _ = ProductLambdaHandler(service: service, operation: operation)
100+
.handle(context: context, event: event)
109101
.always { (result) in
110102
callback(result)
111103
}

Examples/LambdaFunctions/Sources/ProductAPI/ProductLambdaHandler.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ struct ProductLambdaHandler: EventLoopLambdaHandler {
166166
self.service = service
167167
}
168168

169-
func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<
170-
Result<Product, Error>
171-
> {
169+
func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<Result<Product, Error>> {
172170

173171
guard let product: Product = try? event.object() else {
174172
let error = APIError.invalidRequest
@@ -190,9 +188,7 @@ struct ProductLambdaHandler: EventLoopLambdaHandler {
190188
self.service = service
191189
}
192190

193-
func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<
194-
Result<EmptyResponse, Error>
195-
> {
191+
func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<Result<EmptyResponse, Error>> {
196192

197193
guard let sku = event.pathParameters?["sku"] else {
198194
let error = APIError.invalidRequest
@@ -214,9 +210,7 @@ struct ProductLambdaHandler: EventLoopLambdaHandler {
214210
self.service = service
215211
}
216212

217-
func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<
218-
Result<[Product], Error>
219-
> {
213+
func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<Result<[Product], Error>> {
220214

221215
let future = service.listItems()
222216
.flatMapThrowing { data -> Result<[Product], Error> in

0 commit comments

Comments
 (0)