Skip to content

Commit

Permalink
add isProduction and partnerId attributes to Job model.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobitech committed Jul 11, 2024
1 parent 0d706e5 commit 5458480
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
12 changes: 9 additions & 3 deletions Example/SmileID/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class HomeViewModel: ObservableObject,
timestamp: date,
userId: apiResponse.userId,
jobId: apiResponse.jobId,
partnerId: partnerId,
jobComplete: true,
jobSuccess: apiResponse.status == .approved,
code: apiResponse.code,
Expand Down Expand Up @@ -121,6 +122,7 @@ class HomeViewModel: ObservableObject,
timestamp: date,
userId: apiResponse.userId,
jobId: apiResponse.jobId,
partnerId: partnerId,
jobComplete: true,
jobSuccess: apiResponse.status == .approved,
code: apiResponse.code,
Expand Down Expand Up @@ -153,7 +155,8 @@ class HomeViewModel: ObservableObject,
jobType: .biometricKyc,
timestamp: Date(),
userId: newUserId,
jobId: newJobId
jobId: newJobId,
partnerId: partnerId
)
)
} catch {
Expand All @@ -177,6 +180,7 @@ class HomeViewModel: ObservableObject,
timestamp: Date(),
userId: enhancedKycResponse.partnerParams.userId,
jobId: enhancedKycResponse.partnerParams.jobId,
partnerId: partnerId,
jobComplete: true,
jobSuccess: true,
resultCode: enhancedKycResponse.resultCode,
Expand Down Expand Up @@ -207,7 +211,8 @@ class HomeViewModel: ObservableObject,
jobType: .documentVerification,
timestamp: Date(),
userId: newUserId,
jobId: newJobId
jobId: newJobId,
partnerId: partnerId
)
)
} catch {
Expand All @@ -233,7 +238,8 @@ class HomeViewModel: ObservableObject,
jobType: .enhancedDocumentVerification,
timestamp: Date(),
userId: newUserId,
jobId: newJobId
jobId: newJobId,
partnerId: partnerId
)
)
} catch {
Expand Down
10 changes: 9 additions & 1 deletion Example/SmileID/Models/DataStoreClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ class DataStoreClient {

let viewContext = CoreDataManager.shared.container.viewContext

func fetchJobs() throws -> [JobData] {
func fetchJobs(
partnerId: String,
isProduction: Bool
) throws -> [JobData] {
do {
let predicate = NSPredicate(
format: "partnerId == %@ AND isProduction == %@",
partnerId, NSNumber(value: isProduction)
)
let timestampSortDescriptor = NSSortDescriptor(key: "timestamp", ascending: false)
let objects = try Job.fetchJobs(
predicate: predicate,
sortDescriptors: [timestampSortDescriptor],
using: viewContext
)
Expand Down
4 changes: 4 additions & 0 deletions Example/SmileID/Models/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Job: NSManagedObject {
@NSManaged var userId: String
@NSManaged var jobType: Int16
@NSManaged var timestamp: Date
@NSManaged var partnerId: String
@NSManaged var isProduction: Bool
@NSManaged var jobComplete: Bool
@NSManaged var jobSuccess: Bool
@NSManaged var code: String?
Expand Down Expand Up @@ -46,6 +48,8 @@ extension Job {
job.userId = data.userId
job.jobType = Int16(data.jobType.rawValue)
job.timestamp = data.timestamp
job.partnerId = data.partnerId
job.isProduction = data.isProduction
job.jobComplete = data.jobComplete
job.jobSuccess = data.jobSuccess
job.code = data.code
Expand Down
44 changes: 40 additions & 4 deletions Example/SmileID/Models/JobData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,45 @@ struct JobData: Identifiable {
var timestamp: Date
var userId: String
var jobId: String
var jobComplete: Bool = false
var jobSuccess: Bool = false
var partnerId: String
var isProduction: Bool
var jobComplete: Bool
var jobSuccess: Bool
var code: String?
var resultCode: String?
var smileJobId: String?
var resultText: String?
var selfieImageUrl: String?

init(
jobType: JobType,
timestamp: Date,
userId: String,
jobId: String,
partnerId: String,
isProduction: Bool = !SmileID.useSandbox,
jobComplete: Bool = false,
jobSuccess: Bool = false,
code: String? = nil,
resultCode: String? = nil,
smileJobId: String? = nil,
resultText: String? = nil,
selfieImageUrl: String? = nil
) {
self.jobType = jobType
self.timestamp = timestamp
self.userId = userId
self.jobId = jobId
self.partnerId = partnerId
self.isProduction = isProduction
self.jobComplete = jobComplete
self.jobSuccess = jobSuccess
self.code = code
self.resultCode = resultCode
self.smileJobId = smileJobId
self.resultText = resultText
self.selfieImageUrl = selfieImageUrl
}
}

extension JobType {
Expand Down Expand Up @@ -66,7 +98,9 @@ extension JobData {
jobType: jobType,
timestamp: managedObject.timestamp,
userId: managedObject.userId,
jobId: managedObject.jobId,
jobId: managedObject.jobId,
partnerId: managedObject.partnerId,
isProduction: managedObject.isProduction,
jobComplete: managedObject.jobComplete,
jobSuccess: managedObject.jobSuccess,
code: managedObject.code,
Expand All @@ -85,7 +119,9 @@ extension JobData {
jobType: .documentVerification,
timestamp: Date(),
userId: "6a811664-ba17-460a-b8c6-54b8f8dda0c0_742418bf-d7dd-450b-9785-420d3773496a",
jobId: "742418bf-d7dd-450b-9785-420d3773496a",
jobId: "742418bf-d7dd-450b-9785-420d3773496a",
partnerId: "002",
isProduction: true,
jobComplete: false,
jobSuccess: false,
code: "2340",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22758" systemVersion="23F79" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<entity name="Job" representedClassName=".Job" syncable="YES">
<attribute name="code" optional="YES" attributeType="String"/>
<attribute name="isProduction" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="jobComplete" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="jobId" attributeType="String"/>
<attribute name="jobSuccess" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="jobType" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="partnerId" attributeType="String"/>
<attribute name="resultCode" optional="YES" attributeType="String"/>
<attribute name="resultText" optional="YES" attributeType="String"/>
<attribute name="selfieImageUrl" optional="YES" attributeType="String"/>
Expand Down

0 comments on commit 5458480

Please sign in to comment.