@@ -23,11 +23,18 @@ public enum APIError: Error {
23
23
case invalidHandler
24
24
}
25
25
26
- extension Date {
27
- var iso8601 : String {
26
+ extension DateFormatter {
27
+ static var iso8061 : DateFormatter {
28
28
let formatter = DateFormatter ( )
29
29
formatter. dateFormat = " yyyy-MM-dd'T'HH:mm:ss.SSS'Z' "
30
30
formatter. timeZone = TimeZone ( secondsFromGMT: 0 )
31
+ return formatter
32
+ }
33
+ }
34
+
35
+ extension Date {
36
+ var iso8601 : String {
37
+ let formatter = DateFormatter . iso8061
31
38
return formatter. string ( from: self )
32
39
}
33
40
}
@@ -45,9 +52,9 @@ public class ProductService {
45
52
public func createItem( product: Product ) -> EventLoopFuture < Product > {
46
53
47
54
var product = product
48
- let date = Date ( ) . iso8601
49
- product. createdAt = date
50
- product. updatedAt = date
55
+ let date = Date ( )
56
+ product. createdAt = date. iso8601
57
+ product. updatedAt = date. iso8601
51
58
52
59
let input = DynamoDB . PutItemInput (
53
60
item: product. dynamoDictionary,
@@ -60,7 +67,7 @@ public class ProductService {
60
67
61
68
public func readItem( key: String ) -> EventLoopFuture < Product > {
62
69
let input = DynamoDB . GetItemInput (
63
- key: [ ProductField . sku: DynamoDB . AttributeValue ( s: key) ] ,
70
+ key: [ Product . Field . sku: DynamoDB . AttributeValue ( s: key) ] ,
64
71
tableName: tableName
65
72
)
66
73
return db. getItem ( input) . flatMapThrowing { data -> Product in
@@ -70,21 +77,21 @@ public class ProductService {
70
77
71
78
public func updateItem( product: Product ) -> EventLoopFuture < Product > {
72
79
var product = product
73
- let date = Date ( ) . iso8601
74
- product. updatedAt = date
80
+ let date = Date ( )
81
+ product. updatedAt = date. iso8601
75
82
76
83
let input = DynamoDB . UpdateItemInput (
77
84
expressionAttributeNames: [
78
- " #name " : ProductField . name,
79
- " #description " : ProductField . description,
80
- " #updatedAt " : ProductField . updatedAt,
85
+ " #name " : Product . Field . name,
86
+ " #description " : Product . Field . description,
87
+ " #updatedAt " : Product . Field . updatedAt,
81
88
] ,
82
89
expressionAttributeValues: [
83
90
" :name " : DynamoDB . AttributeValue ( s: product. name) ,
84
91
" :description " : DynamoDB . AttributeValue ( s: product. description) ,
85
92
" :updatedAt " : DynamoDB . AttributeValue ( s: product. updatedAt) ,
86
93
] ,
87
- key: [ ProductField . sku: DynamoDB . AttributeValue ( s: product. sku) ] ,
94
+ key: [ Product . Field . sku: DynamoDB . AttributeValue ( s: product. sku) ] ,
88
95
returnValues: DynamoDB . ReturnValue. allNew,
89
96
tableName: tableName,
90
97
updateExpression: " SET #name = :name, #description = :description, #updatedAt = :updatedAt "
@@ -96,7 +103,7 @@ public class ProductService {
96
103
97
104
public func deleteItem( key: String ) -> EventLoopFuture < Void > {
98
105
let input = DynamoDB . DeleteItemInput (
99
- key: [ ProductField . sku: DynamoDB . AttributeValue ( s: key) ] ,
106
+ key: [ Product . Field . sku: DynamoDB . AttributeValue ( s: key) ] ,
100
107
tableName: tableName
101
108
)
102
109
return db. deleteItem ( input) . map { _ in Void ( ) }
0 commit comments