55// SPDX-License-Identifier: Apache-2.0
66
77// snippet-start:[ddb.swift.batchgetitem.movie]
8- import Foundation
98import AWSDynamoDB
9+ import Foundation
1010
1111// snippet-start:[ddb.swift.batchgetitem.info]
1212/// The optional details about a movie.
@@ -16,6 +16,7 @@ public struct Info: Codable {
1616 /// The movie's plot, if available.
1717 var plot : String ?
1818}
19+
1920// snippet-end:[ddb.swift.batchgetitem.info]
2021
2122public struct Movie : Codable {
@@ -42,6 +43,7 @@ public struct Movie: Codable {
4243
4344 self . info = Info ( rating: rating, plot: plot)
4445 }
46+
4547 // snippet-end:[ddb.swift.batchgetitem.movie.init]
4648
4749 // snippet-start:[ddb.swift.batchgetitem.movie.init-info]
@@ -63,21 +65,23 @@ public struct Movie: Codable {
6365 self . info = Info ( rating: nil , plot: nil )
6466 }
6567 }
68+
6669 // snippet-end:[ddb.swift.batchgetitem.movie.init-info]
6770
6871 // snippet-start:[ddb.swift.batchgetitem.movie.init-withitem]
6972 ///
7073 /// Return a new `MovieTable` object, given an array mapping string to Amazon
7174 /// DynamoDB attribute values.
72- ///
75+ ///
7376 /// - Parameter item: The item information provided in the form used by
7477 /// DynamoDB. This is an array of strings mapped to
7578 /// `DynamoDBClientTypes.AttributeValue` values.
76- init ( withItem item: [ Swift . String : DynamoDBClientTypes . AttributeValue ] ) throws {
79+ init ( withItem item: [ Swift . String : DynamoDBClientTypes . AttributeValue ] ) throws {
7780 // Read the attributes.
7881
7982 guard let titleAttr = item [ " title " ] ,
80- let yearAttr = item [ " year " ] else {
83+ let yearAttr = item [ " year " ]
84+ else {
8185 throw MovieError . ItemNotFound
8286 }
8387 let infoAttr = item [ " info " ] ?? nil
@@ -116,6 +120,7 @@ public struct Movie: Codable {
116120
117121 self . info = Info ( rating: rating, plot: plot)
118122 }
123+
119124 // snippet-end:[ddb.swift.batchgetitem.movie.init-withitem]
120125
121126 // snippet-start:[ddb.swift.batchgetitem.movie.getasitem]
@@ -127,19 +132,19 @@ public struct Movie: Codable {
127132 /// - Returns: The movie item as an array of type
128133 /// `[Swift.String:DynamoDBClientTypes.AttributeValue]`.
129134 ///
130- func getAsItem( ) async throws -> [ Swift . String : DynamoDBClientTypes . AttributeValue ] {
135+ func getAsItem( ) async throws -> [ Swift . String : DynamoDBClientTypes . AttributeValue ] {
131136 // Build the item record, starting with the year and title, which are
132137 // always present.
133138
134- var item : [ Swift . String : DynamoDBClientTypes . AttributeValue ] = [
135- " year " : . n( String ( self . year) ) ,
136- " title " : . s( self . title)
139+ var item : [ Swift . String : DynamoDBClientTypes . AttributeValue ] = [
140+ " year " : . n( String ( year) ) ,
141+ " title " : . s( title)
137142 ]
138143
139144 // Add the `info` field with the rating and/or plot if they're
140145 // available.
141146
142- var info : [ Swift . String : DynamoDBClientTypes . AttributeValue ] = [ : ]
147+ var info : [ Swift . String : DynamoDBClientTypes . AttributeValue ] = [ : ]
143148 if self . info. rating != nil {
144149 info [ " rating " ] = . n( String ( self . info. rating!) )
145150 }
@@ -152,4 +157,5 @@ public struct Movie: Codable {
152157 }
153158 // snippet-end:[ddb.swift.batchgetitem.movie.getasitem]
154159}
160+
155161// snippet-end:[ddb.swift.batchgetitem.movie]
0 commit comments