@@ -27,17 +27,15 @@ import AWSLambdaRuntime
27
27
import Logging
28
28
import NIO
29
29
30
- #if compiler(>=5.5) && canImport(_Concurrency)
31
-
32
30
struct AsyncProductLambdaHandler {
33
31
34
- typealias In = APIGateway . V2 . Request
35
- typealias Out = APIGateway . V2 . Response
32
+ typealias Event = APIGatewayV2Request
33
+ typealias Output = APIGatewayV2Response
36
34
37
35
let service : ProductService
38
36
let operation : Operation
39
37
40
- func handle( context: Lambda . Context , event: APIGateway . V2 . Request ) async -> APIGateway . V2 . Response {
38
+ func handle( context: AWSLambdaRuntimeCore . LambdaContext , event: APIGatewayV2Request ) async -> APIGatewayV2Response {
41
39
42
40
switch self . operation {
43
41
case . create:
@@ -53,66 +51,64 @@ struct AsyncProductLambdaHandler {
53
51
}
54
52
}
55
53
56
- func createLambdaHandler( context: Lambda . Context , event: APIGateway . V2 . Request ) async -> APIGateway . V2 . Response {
54
+ func createLambdaHandler( context: AWSLambdaRuntimeCore . LambdaContext , event: APIGatewayV2Request ) async -> APIGatewayV2Response {
57
55
guard let product: Product = try ? event. bodyObject ( ) else {
58
56
let error = APIError . invalidRequest
59
- return APIGateway . V2 . Response ( with: error, statusCode: . forbidden)
57
+ return APIGatewayV2Response ( with: error, statusCode: . forbidden)
60
58
}
61
59
do {
62
60
let result = try await service. createItem ( product: product)
63
- return APIGateway . V2 . Response ( with: result, statusCode: . created)
61
+ return APIGatewayV2Response ( with: result, statusCode: . created)
64
62
} catch {
65
- return APIGateway . V2 . Response ( with: error, statusCode: . forbidden)
63
+ return APIGatewayV2Response ( with: error, statusCode: . forbidden)
66
64
}
67
65
}
68
66
69
- func readLambdaHandler( context: Lambda . Context , event: APIGateway . V2 . Request ) async -> APIGateway . V2 . Response {
67
+ func readLambdaHandler( context: AWSLambdaRuntimeCore . LambdaContext , event: APIGatewayV2Request ) async -> APIGatewayV2Response {
70
68
guard let sku = event. pathParameters ? [ " sku " ] else {
71
69
let error = APIError . invalidRequest
72
- return APIGateway . V2 . Response ( with: error, statusCode: . forbidden)
70
+ return APIGatewayV2Response ( with: error, statusCode: . forbidden)
73
71
}
74
72
do {
75
73
let result = try await service. readItem ( key: sku)
76
- return APIGateway . V2 . Response ( with: result, statusCode: . ok)
74
+ return APIGatewayV2Response ( with: result, statusCode: . ok)
77
75
} catch {
78
- return APIGateway . V2 . Response ( with: error, statusCode: . notFound)
76
+ return APIGatewayV2Response ( with: error, statusCode: . notFound)
79
77
}
80
78
}
81
79
82
- func updateLambdaHandler( context: Lambda . Context , event: APIGateway . V2 . Request ) async -> APIGateway . V2 . Response {
80
+ func updateLambdaHandler( context: AWSLambdaRuntimeCore . LambdaContext , event: APIGatewayV2Request ) async -> APIGatewayV2Response {
83
81
guard let product: Product = try ? event. bodyObject ( ) else {
84
82
let error = APIError . invalidRequest
85
- return APIGateway . V2 . Response ( with: error, statusCode: . forbidden)
83
+ return APIGatewayV2Response ( with: error, statusCode: . forbidden)
86
84
}
87
85
do {
88
86
let result = try await service. updateItem ( product: product)
89
- return APIGateway . V2 . Response ( with: result, statusCode: . ok)
87
+ return APIGatewayV2Response ( with: result, statusCode: . ok)
90
88
} catch {
91
- return APIGateway . V2 . Response ( with: error, statusCode: . notFound)
89
+ return APIGatewayV2Response ( with: error, statusCode: . notFound)
92
90
}
93
91
}
94
92
95
- func deleteUpdateLambdaHandler( context: Lambda . Context , event: APIGateway . V2 . Request ) async -> APIGateway . V2 . Response {
93
+ func deleteUpdateLambdaHandler( context: AWSLambdaRuntimeCore . LambdaContext , event: APIGatewayV2Request ) async -> APIGatewayV2Response {
96
94
guard let sku = event. pathParameters ? [ " sku " ] else {
97
95
let error = APIError . invalidRequest
98
- return APIGateway . V2 . Response ( with: error, statusCode: . forbidden)
96
+ return APIGatewayV2Response ( with: error, statusCode: . forbidden)
99
97
}
100
98
do {
101
99
try await service. deleteItem ( key: sku)
102
- return APIGateway . V2 . Response ( with: EmptyResponse ( ) , statusCode: . ok)
100
+ return APIGatewayV2Response ( with: EmptyResponse ( ) , statusCode: . ok)
103
101
} catch {
104
- return APIGateway . V2 . Response ( with: error, statusCode: . notFound)
102
+ return APIGatewayV2Response ( with: error, statusCode: . notFound)
105
103
}
106
104
}
107
105
108
- func listUpdateLambdaHandler( context: Lambda . Context , event: APIGateway . V2 . Request ) async -> APIGateway . V2 . Response {
106
+ func listUpdateLambdaHandler( context: AWSLambdaRuntimeCore . LambdaContext , event: APIGatewayV2Request ) async -> APIGatewayV2Response {
109
107
do {
110
108
let result = try await service. listItems ( )
111
- return APIGateway . V2 . Response ( with: result, statusCode: . ok)
109
+ return APIGatewayV2Response ( with: result, statusCode: . ok)
112
110
} catch {
113
- return APIGateway . V2 . Response ( with: error, statusCode: . forbidden)
111
+ return APIGatewayV2Response ( with: error, statusCode: . forbidden)
114
112
}
115
113
}
116
114
}
117
-
118
- #endif
0 commit comments