Skip to content

Commit a2e60b6

Browse files
committed
add Entity.retrieveList(), remove EntityList
1 parent 4008cfb commit a2e60b6

File tree

7 files changed

+139
-281
lines changed

7 files changed

+139
-281
lines changed

Amatino.xcodeproj/project.pbxproj

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868
1E58D58F20F2283700069961 /* AMCryptography.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E54D29B202D9C97004E8599 /* AMCryptography.m */; };
6969
1E58D59120F2283700069961 /* CustomUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EADC8792022A864005F94DF /* CustomUnit.swift */; };
7070
1E58D59220F2283700069961 /* Entity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EADC87B2022A8E2005F94DF /* Entity.swift */; };
71-
1E58D59520F2283700069961 /* EntityList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829320ECCB2B00C406FE /* EntityList.swift */; };
72-
1E58D59620F2283700069961 /* EntityListAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829120ECCB2B00C406FE /* EntityListAttributes.swift */; };
7371
1E58D59820F2283700069961 /* Entry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E0E6F3D20258654006AF115 /* Entry.swift */; };
7472
1E58D59920F2283700069961 /* GlobalUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E15CD2D2023BD4B0031CB2B /* GlobalUnit.swift */; };
7573
1E58D59B20F2283700069961 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EADC87F2022B289005F94DF /* HTTPMethod.swift */; };
@@ -103,6 +101,12 @@
103101
1E7B837B20EDA07800867B30 /* Colour.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E7B837A20EDA07800867B30 /* Colour.swift */; };
104102
1E7CB620224D3811003CA877 /* AccountRepresentative.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E7CB61E224D3810003CA877 /* AccountRepresentative.swift */; };
105103
1E7CB621224D3811003CA877 /* AccountRepresentative.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E7CB61E224D3810003CA877 /* AccountRepresentative.swift */; };
104+
1E809122246E4E2D00340427 /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E809121246E4E2D00340427 /* State.swift */; };
105+
1E809123246E4E2D00340427 /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E809121246E4E2D00340427 /* State.swift */; };
106+
1E809124246E4E2D00340427 /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E809121246E4E2D00340427 /* State.swift */; };
107+
1E809126246E528400340427 /* Disposition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E809125246E528400340427 /* Disposition.swift */; };
108+
1E809127246E528400340427 /* Disposition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E809125246E528400340427 /* Disposition.swift */; };
109+
1E809128246E528400340427 /* Disposition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E809125246E528400340427 /* Disposition.swift */; };
106110
1E84DF72210BDEE300EA399D /* LedgerPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E84DF70210BDEE300EA399D /* LedgerPage.swift */; };
107111
1E84DF73210BDEE300EA399D /* LedgerPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E84DF70210BDEE300EA399D /* LedgerPage.swift */; };
108112
1E97CDE3210096B400C149A6 /* LedgerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E97CDE1210096B400C149A6 /* LedgerRow.swift */; };
@@ -117,8 +121,6 @@
117121
1ED0974A202A9EEA005D9732 /* UrlTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ED09749202A9EEA005D9732 /* UrlTarget.swift */; };
118122
1EEA829B20ECCB2D00C406FE /* Region.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA828F20ECCB2B00C406FE /* Region.swift */; };
119123
1EEA829C20ECCB2D00C406FE /* RegionListAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829020ECCB2B00C406FE /* RegionListAttributes.swift */; };
120-
1EEA829D20ECCB2D00C406FE /* EntityListAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829120ECCB2B00C406FE /* EntityListAttributes.swift */; };
121-
1EEA829F20ECCB2D00C406FE /* EntityList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829320ECCB2B00C406FE /* EntityList.swift */; };
122124
1EEA82A220ECCB2D00C406FE /* UserAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829620ECCB2C00C406FE /* UserAttributes.swift */; };
123125
1EEA82A420ECCB2D00C406FE /* RegionList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829820ECCB2C00C406FE /* RegionList.swift */; };
124126
1EEA82A520ECCB2D00C406FE /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EEA829920ECCB2D00C406FE /* User.swift */; };
@@ -197,6 +199,8 @@
197199
1E7AC3AD21195EBE00102932 /* Price.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Price.swift; sourceTree = "<group>"; };
198200
1E7B837A20EDA07800867B30 /* Colour.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colour.swift; sourceTree = "<group>"; };
199201
1E7CB61E224D3810003CA877 /* AccountRepresentative.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountRepresentative.swift; sourceTree = "<group>"; };
202+
1E809121246E4E2D00340427 /* State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = State.swift; sourceTree = "<group>"; };
203+
1E809125246E528400340427 /* Disposition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Disposition.swift; sourceTree = "<group>"; };
200204
1E84DF70210BDEE300EA399D /* LedgerPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LedgerPage.swift; sourceTree = "<group>"; };
201205
1E97CDD92100947000C149A6 /* Ledger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ledger.swift; sourceTree = "<group>"; };
202206
1E97CDE1210096B400C149A6 /* LedgerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LedgerRow.swift; sourceTree = "<group>"; };
@@ -210,8 +214,6 @@
210214
1ED09749202A9EEA005D9732 /* UrlTarget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlTarget.swift; sourceTree = "<group>"; };
211215
1EEA828F20ECCB2B00C406FE /* Region.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Region.swift; sourceTree = "<group>"; };
212216
1EEA829020ECCB2B00C406FE /* RegionListAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegionListAttributes.swift; sourceTree = "<group>"; };
213-
1EEA829120ECCB2B00C406FE /* EntityListAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EntityListAttributes.swift; sourceTree = "<group>"; };
214-
1EEA829320ECCB2B00C406FE /* EntityList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EntityList.swift; sourceTree = "<group>"; };
215217
1EEA829620ECCB2C00C406FE /* UserAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserAttributes.swift; sourceTree = "<group>"; };
216218
1EEA829820ECCB2C00C406FE /* RegionList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegionList.swift; sourceTree = "<group>"; };
217219
1EEA829920ECCB2D00C406FE /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
@@ -338,8 +340,6 @@
338340
1E7B837A20EDA07800867B30 /* Colour.swift */,
339341
1EADC8792022A864005F94DF /* CustomUnit.swift */,
340342
1EADC87B2022A8E2005F94DF /* Entity.swift */,
341-
1EEA829320ECCB2B00C406FE /* EntityList.swift */,
342-
1EEA829120ECCB2B00C406FE /* EntityListAttributes.swift */,
343343
1E4D5E33210FFC6400303BD2 /* EntityObject.swift */,
344344
1E0E6F3D20258654006AF115 /* Entry.swift */,
345345
1E15CD2D2023BD4B0031CB2B /* GlobalUnit.swift */,
@@ -376,6 +376,8 @@
376376
1E7AC3AD21195EBE00102932 /* Price.swift */,
377377
1E2BBB6D22527A9600FB302F /* Denomination.swift */,
378378
1E2BBB7022527BA400FB302F /* Denominated.swift */,
379+
1E809121246E4E2D00340427 /* State.swift */,
380+
1E809125246E528400340427 /* Disposition.swift */,
379381
);
380382
name = Amatino;
381383
path = Sources/Amatino;
@@ -516,7 +518,6 @@
516518
1EFDC62121152ED60042EBCA /* TreeNode.swift in Sources */,
517519
1E7AC3B021195EBE00102932 /* Price.swift in Sources */,
518520
1E58D59E20F2283700069961 /* Region.swift in Sources */,
519-
1E58D59520F2283700069961 /* EntityList.swift in Sources */,
520521
1E58D5A520F2283700069961 /* Side.swift in Sources */,
521522
1E2B420720FED2F100537C17 /* GlobalUnitList.swift in Sources */,
522523
1E58D5B320F2283700069961 /* Colour.swift in Sources */,
@@ -546,8 +547,8 @@
546547
1E7CB621224D3811003CA877 /* AccountRepresentative.swift in Sources */,
547548
1E59DA02210EEECD0080C4CD /* RecursiveLedger.swift in Sources */,
548549
1E59D9FE210EEE090080C4CD /* RecursiveLedgerPage.swift in Sources */,
549-
1E58D59620F2283700069961 /* EntityListAttributes.swift in Sources */,
550550
1E58D5A620F2283700069961 /* Transaction.swift in Sources */,
551+
1E809124246E4E2D00340427 /* State.swift in Sources */,
551552
1EFDC62D21155ADC0042EBCA /* Tree.swift in Sources */,
552553
1E58D59220F2283700069961 /* Entity.swift in Sources */,
553554
1E16F5E6210AF196002F1B81 /* AmatinoDate.swift in Sources */,
@@ -564,6 +565,7 @@
564565
1E58D58620F2283700069961 /* Account.swift in Sources */,
565566
1E58D5AD20F2283700069961 /* UrlParameters.swift in Sources */,
566567
1E2B420A20FF023400537C17 /* Balance.swift in Sources */,
568+
1E809128246E528400340427 /* Disposition.swift in Sources */,
567569
);
568570
runOnlyForDeploymentPostprocessing = 0;
569571
};
@@ -576,12 +578,14 @@
576578
1E2B420F20FF11EA00537C17 /* BalanceTests.swift in Sources */,
577579
1E59D9F6210E8C010080C4CD /* PopulatedEntityTest.swift in Sources */,
578580
1E15311020FC7C3100EB8CC6 /* AmatinoAlphaTests.swift in Sources */,
581+
1E809126246E528400340427 /* Disposition.swift in Sources */,
579582
1E2BBB6C225233FE00FB302F /* UserTests.swift in Sources */,
580583
1E15311420FC801B00EB8CC6 /* AmatinoTest.swift in Sources */,
581584
1E2B421120FF124B00537C17 /* DerivedObjectTest.swift in Sources */,
582585
OBJ_27 /* AncillaryTests.swift in Sources */,
583586
1E15311A20FCB25900EB8CC6 /* TransactionTests.swift in Sources */,
584587
1E15311820FCAAA900EB8CC6 /* AccountTests.swift in Sources */,
588+
1E809122246E4E2D00340427 /* State.swift in Sources */,
585589
);
586590
runOnlyForDeploymentPostprocessing = 0;
587591
};
@@ -624,6 +628,7 @@
624628
1EEA82AB20ECDD0500C406FE /* AccountType.swift in Sources */,
625629
1EADC87A2022A864005F94DF /* CustomUnit.swift in Sources */,
626630
1E20CFD920DB259400C129D0 /* AmatinoAlpha.swift in Sources */,
631+
1E809123246E4E2D00340427 /* State.swift in Sources */,
627632
1EFDC62C21155ADC0042EBCA /* Tree.swift in Sources */,
628633
1E16F5E5210AF196002F1B81 /* AmatinoDate.swift in Sources */,
629634
1E84DF72210BDEE300EA399D /* LedgerPage.swift in Sources */,
@@ -635,11 +640,10 @@
635640
1EEA829B20ECCB2D00C406FE /* Region.swift in Sources */,
636641
1E2BBB6E22527A9600FB302F /* Denomination.swift in Sources */,
637642
1EADC8882022B402005F94DF /* UrlParameters.swift in Sources */,
638-
1EEA829D20ECCB2D00C406FE /* EntityListAttributes.swift in Sources */,
639-
1EEA829F20ECCB2D00C406FE /* EntityList.swift in Sources */,
640643
1E54D29C202D9C97004E8599 /* AMCryptography.m in Sources */,
641644
1E2B420920FF023400537C17 /* Balance.swift in Sources */,
642645
1EADC8862022B289005F94DF /* RequestData.swift in Sources */,
646+
1E809127246E528400340427 /* Disposition.swift in Sources */,
643647
);
644648
runOnlyForDeploymentPostprocessing = 0;
645649
};
@@ -858,7 +862,7 @@
858862
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
859863
COMBINE_HIDPI_IMAGES = YES;
860864
COPY_PHASE_STRIP = NO;
861-
CURRENT_PROJECT_VERSION = 0.0.12;
865+
CURRENT_PROJECT_VERSION = 0.0.13;
862866
DEBUG_INFORMATION_FORMAT = dwarf;
863867
DEFINES_MODULE = YES;
864868
DYLIB_INSTALL_NAME_BASE = "@rpath";
@@ -969,7 +973,7 @@
969973
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
970974
COMBINE_HIDPI_IMAGES = YES;
971975
COPY_PHASE_STRIP = YES;
972-
CURRENT_PROJECT_VERSION = 0.0.12;
976+
CURRENT_PROJECT_VERSION = 0.0.13;
973977
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
974978
DEFINES_MODULE = YES;
975979
DYLIB_INSTALL_NAME_BASE = "@rpath";

Sources/Amatino/Disposition.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Disposition.swift
3+
// Amatino
4+
//
5+
// Created by Hugh Jeremy on 15/5/20.
6+
//
7+
8+
import Foundation
9+
10+
11+
public struct Disposition: Decodable {
12+
13+
let count: Int
14+
let offset: Int
15+
let sequence: Int
16+
let limit: Int
17+
18+
}

Sources/Amatino/Entity.swift

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ public class Entity: Equatable {
1818
}
1919

2020
private static let path = "/entities"
21+
private static let listPath = "/entities/list"
2122

2223
public static let maxNameLength = 1024
2324
public static let maxDescriptionLength = 4096
25+
public static let minNameSearchLength = 3;
26+
public static let maxNameSearchLength = 64;
2427

2528
public let session: Session
2629

@@ -35,6 +38,9 @@ public class Entity: Equatable {
3538
public var description: String? { get { return attributes.description } }
3639
public var regionId: Int { get { return attributes.regionId } }
3740
public var active: Bool { get { return attributes.active} }
41+
public var disposition: Disposition { get {
42+
return attributes.disposition
43+
} }
3844

3945
public static func create(
4046
authenticatedBy session: Session,
@@ -145,6 +151,76 @@ public class Entity: Equatable {
145151
}
146152
}
147153

154+
public static func retrieveList(
155+
authenticatedBy session: Session,
156+
offset: Int = 0,
157+
limit: Int = 10,
158+
withName name: Optional<String> = nil,
159+
inState state: State = State.all,
160+
then callback: @escaping (_: Error?, _: Array<Entity>?) -> Void
161+
) {
162+
163+
var targets = [
164+
UrlTarget(integerValue: offset, key: "offset"),
165+
UrlTarget(integerValue: limit, key: "limit"),
166+
UrlTarget(stringValue: state.rawValue, key: "state")
167+
]
168+
169+
if let name = name {
170+
if name.count < Self.minNameSearchLength {
171+
callback(AmatinoError(.constraintViolated), nil);
172+
return;
173+
}
174+
if name.count > Self.maxNameSearchLength {
175+
callback(AmatinoError(.constraintViolated), nil);
176+
return;
177+
}
178+
targets.append(UrlTarget(stringValue: name, key: "name"))
179+
}
180+
181+
do {
182+
let _ = try AmatinoRequest(
183+
path: Self.listPath,
184+
data: nil,
185+
session: session,
186+
urlParameters: UrlParameters(targetsOnly: targets),
187+
method: .GET,
188+
callback: { (error, data) in
189+
Entity.asyncInitMany(session, error, data, callback)
190+
}
191+
)
192+
} catch { callback(error, nil); return; }
193+
194+
}
195+
196+
public static func retrieveList(
197+
authenticatedBy session: Session,
198+
offset: Int = 0,
199+
limit: Int = 10,
200+
withName name: Optional<String> = nil,
201+
inState state: State = State.all,
202+
then callback: @escaping (Result<Array<Entity>, Error>) -> Void
203+
) {
204+
205+
Entity.retrieveList(
206+
authenticatedBy: session,
207+
offset: offset,
208+
limit: limit,
209+
withName: name,
210+
inState: state
211+
) { (error, entities) in
212+
guard let entities = entities else {
213+
callback(
214+
.failure(error ?? AmatinoError(.inconsistentState))
215+
);
216+
return;
217+
}
218+
callback(.success(entities));
219+
return;
220+
}
221+
222+
}
223+
148224
public func delete(then callback: @escaping (Error?, Entity?) -> Void) {
149225
let parameters = UrlParameters(singleEntity: self)
150226
do {
@@ -229,7 +305,7 @@ public class Entity: Equatable {
229305
error: Error?,
230306
data: Data?,
231307
callback: @escaping (Error?, Entity?) -> Void
232-
) {
308+
) {
233309

234310
let _ = Entity.asyncInitMany(
235311
session, error, data, { (error, entities) in
@@ -261,6 +337,7 @@ public class Entity: Equatable {
261337
let description: String?
262338
let regionId: Int
263339
let active: Bool
340+
let disposition: Disposition
264341

265342
public init(from decoder: Decoder) throws {
266343
let container = try decoder.container(keyedBy: JSONObjectKeys.self)
@@ -277,6 +354,10 @@ public class Entity: Equatable {
277354
)
278355
regionId = try container.decode(Int.self, forKey: .regionId)
279356
active = true
357+
disposition = try container.decode(
358+
Disposition.self,
359+
forKey: .disposition
360+
)
280361
return
281362
}
282363

@@ -287,6 +368,7 @@ public class Entity: Equatable {
287368
case permissionsGraph = "permissions_graph"
288369
case description
289370
case regionId = "region_id"
371+
case disposition = "disposition"
290372
}
291373

292374
}

0 commit comments

Comments
 (0)