Skip to content

Commit e840c3e

Browse files
committed
manually modify codegenerated models
1 parent 47fcd08 commit e840c3e

File tree

1 file changed

+50
-27
lines changed
  • AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginLazyLoadTests/Models

1 file changed

+50
-27
lines changed

AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginLazyLoadTests/Models/Comment4V2.swift

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,53 @@ import Amplify
33
import Foundation
44

55
public struct Comment4V2: Model {
6-
public let id: String
7-
public var content: String
8-
public var post: Post4V2?
9-
public var createdAt: Temporal.DateTime?
10-
public var updatedAt: Temporal.DateTime?
11-
12-
public init(id: String = UUID().uuidString,
13-
content: String,
14-
post: Post4V2? = nil) {
15-
self.init(id: id,
16-
content: content,
17-
post: post,
18-
createdAt: nil,
19-
updatedAt: nil)
20-
}
21-
internal init(id: String = UUID().uuidString,
22-
content: String,
23-
post: Post4V2? = nil,
24-
createdAt: Temporal.DateTime? = nil,
25-
updatedAt: Temporal.DateTime? = nil) {
26-
self.id = id
27-
self.content = content
28-
self.post = post
29-
self.createdAt = createdAt
30-
self.updatedAt = updatedAt
31-
}
32-
}
6+
public let id: String
7+
public var content: String
8+
internal var _post: LazyModel<Post4V2>
9+
public var post: Post4V2? {
10+
get async throws {
11+
try await _post.get()
12+
}
13+
}
14+
public var createdAt: Temporal.DateTime?
15+
public var updatedAt: Temporal.DateTime?
16+
17+
public init(id: String = UUID().uuidString,
18+
content: String,
19+
post: Post4V2? = nil) {
20+
self.init(id: id,
21+
content: content,
22+
post: post,
23+
createdAt: nil,
24+
updatedAt: nil)
25+
}
26+
internal init(id: String = UUID().uuidString,
27+
content: String,
28+
post: Post4V2? = nil,
29+
createdAt: Temporal.DateTime? = nil,
30+
updatedAt: Temporal.DateTime? = nil) {
31+
self.id = id
32+
self.content = content
33+
self._post = LazyModel(element: post)
34+
self.createdAt = createdAt
35+
self.updatedAt = updatedAt
36+
}
37+
38+
public mutating func setPost(_ post: Post4V2) {
39+
self._post = LazyModel(element: post)
40+
}
41+
42+
public init(from decoder: Decoder) throws {
43+
let values = try decoder.container(keyedBy: CodingKeys.self)
44+
id = try values.decode(String.self, forKey: .id)
45+
content = try values.decode(String.self, forKey: .content)
46+
_post = try values.decode(LazyModel<Post4V2>.self, forKey: .post)
47+
}
48+
49+
public func encode(to encoder: Encoder) throws {
50+
var container = encoder.container(keyedBy: CodingKeys.self)
51+
try container.encode(id, forKey: .id)
52+
try container.encode(content, forKey: .content)
53+
try container.encode(_post, forKey: .post)
54+
}
55+
}

0 commit comments

Comments
 (0)