Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add required information to DBP NA<->FE API for removal timeline support #3268

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add new fields to DBP->FE API, and associated constructors
  • Loading branch information
THISISDINOSAUR committed Sep 12, 2024
commit 1c82d0f12948e91e9fc8f434e86ddd5a77fdf9f4
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ struct DBPUIUserProfileAddress: Codable {
let zipCode: String?
}

extension DBPUIUserProfileAddress {
init(addressCityState: AddressCityState) {
self.init(street: addressCityState.fullAddress,
city: addressCityState.city,
state: addressCityState.state,
zipCode: nil)
}
}

/// Message Object representing a user profile containing one or more names and addresses
/// also contains the user profile's birth year
struct DBPUIUserProfile: Codable {
Expand Down Expand Up @@ -112,6 +121,10 @@ struct DBPUIDataBroker: Codable, Hashable {
self.date = date
}

init(dataBroker: DataBroker) {
self.init(name: dataBroker.name, url: dataBroker.url)
}

func hash(into hasher: inout Hasher) {
hasher.combine(name)
}
Expand All @@ -136,6 +149,43 @@ struct DBPUIDataBrokerProfileMatch: Codable {
let alternativeNames: [String]
let relatives: [String]
let date: Double? // Used in some methods to set the removedDate or found date
let foundDate: Double
let optOutSubmittedDate: Double?
let estimatedRemovalDate: Double?
let removedDate: Double?
}

extension DBPUIDataBrokerProfileMatch {
init(extractedProfile: ExtractedProfile, optOutJobData: OptOutJobData, dataBroker: DataBroker) {
let estimatedRemovalDate = Calendar.current.date(byAdding: .day, value: 14, to: optOutJobData.createdDate)
self.init(dataBroker: DBPUIDataBroker(dataBroker: dataBroker),
name: extractedProfile.fullName ?? "No name",
addresses: extractedProfile.addresses?.map {DBPUIUserProfileAddress(addressCityState: $0) } ?? [],
alternativeNames: extractedProfile.alternativeNames ?? [String](),
relatives: extractedProfile.relatives ?? [String](),
date: extractedProfile.removedDate?.timeIntervalSince1970,
foundDate: optOutJobData.createdDate.timeIntervalSince1970,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that this information is gained from the optOutJobData, but what you can't see from looking just at this struct is if you see further above is that all these extracted profiles are taken from the opt out jobs the first place.
So I don't think there's anything I can do about it outside of making more serious challenges to our data architecture (which I'd love to do. In making this PR I really noticed how my issues with the DB scheme trickle all the way up to cause a lot of the things I don't like in the UI mapping stuff)

optOutSubmittedDate: optOutJobData.submittedSuccessfullyDate?.timeIntervalSince1970,
estimatedRemovalDate: estimatedRemovalDate?.timeIntervalSince1970,
removedDate: extractedProfile.removedDate?.timeIntervalSince1970)
}

init(extractedProfile: ExtractedProfile,
optOutJobData: OptOutJobData,
dataBrokerName: String,
databrokerURL: String) {
let estimatedRemovalDate = Calendar.current.date(byAdding: .day, value: 14, to: optOutJobData.createdDate)
self.init(dataBroker: DBPUIDataBroker(name: dataBrokerName, url: databrokerURL),
name: extractedProfile.fullName ?? "No name",
addresses: extractedProfile.addresses?.map {DBPUIUserProfileAddress(addressCityState: $0) } ?? [],
alternativeNames: extractedProfile.alternativeNames ?? [String](),
relatives: extractedProfile.relatives ?? [String](),
date: extractedProfile.removedDate?.timeIntervalSince1970,
foundDate: optOutJobData.createdDate.timeIntervalSince1970,
optOutSubmittedDate: optOutJobData.submittedSuccessfullyDate?.timeIntervalSince1970,
estimatedRemovalDate: estimatedRemovalDate?.timeIntervalSince1970,
removedDate: extractedProfile.removedDate?.timeIntervalSince1970)
}
}

/// Protocol to represent a message that can be passed from the host to the UI
Expand All @@ -156,6 +206,27 @@ struct DBPUIOptOutMatch: DBPUISendableMessage {
let alternativeNames: [String]
let addresses: [DBPUIUserProfileAddress]
let date: Double
let foundDate: Double
let optOutSubmittedDate: Double?
let estimatedRemovalDate: Double?
let removedDate: Double?
}

extension DBPUIOptOutMatch {
init?(profileMatch: DBPUIDataBrokerProfileMatch, matches: Int) {
guard let removedDate = profileMatch.removedDate else { return nil }
let dataBroker = profileMatch.dataBroker
self.init(dataBroker: dataBroker,
matches: matches,
name: profileMatch.name,
alternativeNames: profileMatch.alternativeNames,
addresses: profileMatch.addresses,
date: removedDate,
foundDate: profileMatch.foundDate,
optOutSubmittedDate: profileMatch.optOutSubmittedDate,
estimatedRemovalDate: nil,
removedDate: removedDate)
}
}

/// Data representing the initial scan progress
Expand Down