Skip to content

Commit

Permalink
fix: minor UI glitches
Browse files Browse the repository at this point in the history
Co-authored-by: eapuzzo <[email protected]>
  • Loading branch information
Fehniix and eapuzzo authored Mar 16, 2022
1 parent b90e328 commit c72bed4
Show file tree
Hide file tree
Showing 19 changed files with 762 additions and 670 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ struct BlackListValidator: DGCValidator {
return blacklist.split(separator: ";").contains("\(hcert.getUVCI())") ? .notValid : .valid
}

func validate(_ current: Date, from validityStart: Date) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
return .notValid
}

private func getBlacklist() -> String? {
return getValue(for: blacklist)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ struct ChainValidator: DGCValidator {
return failedValidations.isEmpty ? .valid : failedValidations.first!
}

func validate(_ current: Date, from validityStart: Date) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
return .notValid
}
}
41 changes: 8 additions & 33 deletions DGCAVerifier/BusinessRules/Internal/Validators/DGCValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,21 @@ protocol DGCValidator {
func validate(hcert: HCert) -> Status
}

extension DGCValidator {
class AlwaysNotValid: DGCValidator {

func validate(_ current: Date, from validityStart: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
default:
return .valid
}
func validate(hcert: HCert) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
default:
return .expired
}
func validate(_ current: Date, from validityStart: Date) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
case validityEnd...validityEndExtension:
return .verificationIsNeeded
default:
return .expired
}
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
return .notValid
}

}

class AlwaysNotValid: DGCValidator {

func validate(hcert: HCert) -> Status {
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
return .notValid
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ struct HCertValidator: DGCValidator {
return .valid
}

func validate(_ current: Date, from validityStart: Date) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
return .notValid
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
return .notValid
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,55 @@ struct RecoveryInfo {

}

class RecoveryBaseValidator: DGCValidator {

typealias Validator = RecoveryBaseValidator
class RecoveryConcreteValidator: DGCValidator {

fileprivate var recoveryInfo: RecoveryInfo!

func validate(_ current: Date, from validityStart: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
default:
return .valid
}
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
default:
return .expired
}
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
case validityEnd...validityEndExtension:
return .verificationIsNeeded
default:
return .expired
}
}

func validate(hcert: HCert) -> Status {
self.recoveryInfo = RecoveryInfo.from(hcert: hcert)

guard let validityFrom = hcert.recoveryDateFrom?.toRecoveryDate else { return .notValid }
guard let validityUntil = hcert.recoveryDateUntil?.toRecoveryDate else { return .notValid }

guard let recoveryStartDays = getStartDays(from: hcert) else { return .notValid }
guard let recoveryEndDays = getEndDays(from: hcert) else { return .notValid }

guard let validityStart = validityFrom.add(recoveryStartDays, ofType: .day) else { return .notValid }
guard let validityEnd = validityEnd(hcert, dateFrom: validityFrom, dateUntil: validityUntil, additionalDays: recoveryEndDays) else { return .notValid }

guard let currentDate = Date.startOfDay else { return .notValid }

return self.validate(currentDate, from: validityStart, to: validityEnd)
Expand Down Expand Up @@ -114,9 +145,10 @@ class RecoveryBaseValidator: DGCValidator {
public func getValue(for name: String) -> String? {
return LocalData.getSetting(from: name)
}

}

class RecoveryBaseValidator: RecoveryConcreteValidator {}

class RecoveryReinforcedValidator: RecoveryBaseValidator {

override func getStartDays(from hcert: HCert) -> Int? {
Expand Down Expand Up @@ -145,24 +177,7 @@ class RecoveryReinforcedValidator: RecoveryBaseValidator {

class RecoveryBoosterValidator: RecoveryReinforcedValidator {

override func validate(hcert: HCert) -> Status {
self.recoveryInfo = RecoveryInfo.from(hcert: hcert)

guard let validityFrom = hcert.recoveryDateFrom?.toRecoveryDate else { return .notValid }
guard let validityUntil = hcert.recoveryDateUntil?.toRecoveryDate else { return .notValid }

guard let recoveryStartDays = getStartDays(from: hcert) else { return .notValid }
guard let recoveryEndDays = getEndDays(from: hcert) else { return .notValid }

guard let validityStart = validityFrom.add(recoveryStartDays, ofType: .day) else { return .notValid }
guard let validityEnd = validityEnd(hcert, dateFrom: validityFrom, dateUntil: validityUntil, additionalDays: recoveryEndDays) else { return .notValid }

guard let currentDate = Date.startOfDay else { return .notValid }

return validate(currentDate, from: validityStart, to: validityEnd)
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
override func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
Expand Down Expand Up @@ -214,19 +229,9 @@ class RecoverySchoolValidator: RecoveryBaseValidator {

}

class RecoveryWorkValidator: RecoveryBaseValidator {

override func getStartDays(from hcert: HCert) -> Int? {
return super.getStartDays(from: hcert)
}

override func getEndDays(from hcert: HCert) -> Int? {
return super.getEndDays(from: hcert)
}

}
class RecoveryWorkValidator: RecoveryBaseValidator {}

class RecoveryItalyEntryValidator: RecoveryBaseValidator {
class RecoveryItalyEntryValidator: RecoveryConcreteValidator {
override func getStartDays(from hcert: HCert) -> Int? {
let startDaysConfig: String
if isSpecialRecovery(hcert: hcert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,40 @@
import Foundation
import SwiftDGC

class TestBaseValidator: DGCValidator {
class TestConcreteValidator: DGCValidator {

func validate(_ current: Date, from validityStart: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
default:
return .valid
}
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
default:
return .expired
}
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
case validityEnd...validityEndExtension:
return .verificationIsNeeded
default:
return .expired
}
}

fileprivate func isTestDateValid(_ hcert: HCert) -> Status {
guard hcert.isKnownTestType else { return .notValid }
Expand Down Expand Up @@ -77,9 +110,10 @@ class TestBaseValidator: DGCValidator {
let testValidityResults = [isTestNegative(hcert), isTestDateValid(hcert)]
return testValidityResults.first(where: {$0 != .valid}) ?? .valid
}

}

class TestBaseValidator: TestConcreteValidator {}

class TestReinforcedValidator: TestBaseValidator {

override func validate(hcert: HCert) -> Status {
Expand Down Expand Up @@ -117,4 +151,4 @@ class TestWorkValidator: TestBaseValidator {

}

class TestItalyEntryValidator: TestBaseValidator {}
class TestItalyEntryValidator: TestConcreteValidator {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,39 @@
import Foundation
import SwiftDGC

class VaccineExemptionBaseValidator: DGCValidator {
class VaccineExemptionConcreteValidator: DGCValidator {
func validate(_ current: Date, from validityStart: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
default:
return .valid
}
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
default:
return .expired
}
}

func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
case validityEnd...validityEndExtension:
return .verificationIsNeeded
default:
return .expired
}
}

func validate(hcert: HCert) -> Status {
guard let exemption = hcert.vaccineExemptionStatements.last else { return .notValid }
Expand All @@ -37,9 +69,10 @@ class VaccineExemptionBaseValidator: DGCValidator {
}
return self.validate(currentDate, from: dateFrom, to: dateUntil)
}

}

class VaccineExemptionBaseValidator: VaccineExemptionConcreteValidator {}

class VaccineExemptionReinforcedValidator: VaccineExemptionBaseValidator {}

class VaccineExemptionBoosterValidator: VaccineExemptionBaseValidator {
Expand All @@ -56,7 +89,7 @@ class VaccineExemptionSchoolValidator: VaccineExemptionBaseValidator {}

class VaccineExemptionWorkValidator: VaccineExemptionBaseValidator {}

class VaccineExemptionItalyEntryValidator: VaccineExemptionBaseValidator {
class VaccineExemptionItalyEntryValidator: VaccineExemptionConcreteValidator {

override func validate(hcert: HCert) -> Status {
let result = super.validate(hcert: hcert)
Expand Down
Loading

0 comments on commit c72bed4

Please sign in to comment.