Skip to content

Commit

Permalink
Merge pull request #31 from vespinola/12-add-date-filter-in-withdrawn…
Browse files Browse the repository at this point in the history
…-packages

12 add date filter in withdrawn packages
  • Loading branch information
vespinola committed Jun 27, 2024
2 parents 85c0ef4 + 5915514 commit 4054dfe
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 23 deletions.
12 changes: 7 additions & 5 deletions mobile-courier-app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
1B4047232C27DF9600101DF4 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
1B4047272C27E04600101DF4 /* AppDIContainerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDIContainerMock.swift; sourceTree = "<group>"; };
1B4047292C27E99D00101DF4 /* AppDataMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDataMock.swift; sourceTree = "<group>"; };
1B58EF732BE6BBE90066F447 /* JustACourierApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JustACourierApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
1B58EF732BE6BBE90066F447 /* mobile-courier-app.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "mobile-courier-app.app"; sourceTree = BUILT_PRODUCTS_DIR; };
1B58EF762BE6BBE90066F447 /* MobileCourierApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileCourierApp.swift; sourceTree = "<group>"; };
1B58EF782BE6BBE90066F447 /* CoordinatorRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoordinatorRootView.swift; sourceTree = "<group>"; };
1B58EF7A2BE6BBEA0066F447 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -273,7 +273,7 @@
1B58EF742BE6BBE90066F447 /* Products */ = {
isa = PBXGroup;
children = (
1B58EF732BE6BBE90066F447 /* JustACourierApp.app */,
1B58EF732BE6BBE90066F447 /* mobile-courier-app.app */,
1B58EF842BE6BBEA0066F447 /* mobile-courier-appTests.xctest */,
1B58EF8E2BE6BBEA0066F447 /* mobile-courier-appUITests.xctest */,
);
Expand Down Expand Up @@ -622,7 +622,7 @@
packageProductDependencies = (
);
productName = "mobile-courier-app";
productReference = 1B58EF732BE6BBE90066F447 /* JustACourierApp.app */;
productReference = 1B58EF732BE6BBE90066F447 /* mobile-courier-app.app */;
productType = "com.apple.product-type.application";
};
1B58EF832BE6BBEA0066F447 /* mobile-courier-appTests */ = {
Expand Down Expand Up @@ -1004,6 +1004,7 @@
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "mobile-courier-app/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = JustACourierApp;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
Expand All @@ -1021,7 +1022,7 @@
MACOSX_DEPLOYMENT_TARGET = 14.4;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.just.another.mobile-courier-app";
PRODUCT_NAME = JustACourierApp;
PRODUCT_NAME = "mobile-courier-app";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down Expand Up @@ -1049,6 +1050,7 @@
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "mobile-courier-app/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = JustACourierApp;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
Expand All @@ -1066,7 +1068,7 @@
MACOSX_DEPLOYMENT_TARGET = 14.4;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.just.another.mobile-courier-app";
PRODUCT_NAME = JustACourierApp;
PRODUCT_NAME = "mobile-courier-app";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = JustCourierAppAdHoc;
SDKROOT = auto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B58EF722BE6BBE90066F447"
BuildableName = "JustACourierApp.app"
BuildableName = "mobile-courier-app.app"
BlueprintName = "mobile-courier-app"
ReferencedContainer = "container:mobile-courier-app.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -69,7 +69,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B58EF722BE6BBE90066F447"
BuildableName = "JustACourierApp.app"
BuildableName = "mobile-courier-app.app"
BlueprintName = "mobile-courier-app"
ReferencedContainer = "container:mobile-courier-app.xcodeproj">
</BuildableReference>
Expand All @@ -86,7 +86,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B58EF722BE6BBE90066F447"
BuildableName = "JustACourierApp.app"
BuildableName = "mobile-courier-app.app"
BlueprintName = "mobile-courier-app"
ReferencedContainer = "container:mobile-courier-app.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ struct AddressRespository: AddressRepositoryProtocol {
decoder: JSONDecoder()
)

AppData.shared.setUsername(model.airShipments.client.clientFirstName)
let firstName = model.airShipments.client.clientFirstName
let lastName = model.airShipments.client.clientLastName
let fullName = firstName + " " + lastName

AppData.shared.setUsername(fullName)

return model.asEntity()
}
Expand Down
13 changes: 13 additions & 0 deletions mobile-courier-app/Domain/Entities/GroupedPackageEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ struct GroupedPackageEntity: Identifiable {
packages.first?.formattedDate ?? ""
}

var shipmentDate: Date? {
packages.first?.shipmentDate.getDateFrom(formatType: .server)
}

var formattedId: String {
NSDecimalNumber(value: shipmentCode).applyFormatForIdentifier()
}
Expand Down Expand Up @@ -65,4 +69,13 @@ extension Array where Element == GroupedPackageEntity {
func filterGroupedPackages(by shipmentStatus: ShipmentStatus) -> [Element] {
filter { $0.packageCurrentStatus == shipmentStatus }
}

func getYears() -> [String] {
let yearList: [Int] = compactMap { $0.shipmentDate }
.map { $0.getYear() }

return Set(yearList)
.sorted { $0 > $1 }
.map { String($0) }
}
}
4 changes: 4 additions & 0 deletions mobile-courier-app/Domain/Extensions/Date+Domain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ extension Date {
dateFormatter.dateFormat = formatType.rawValue
return dateFormatter.string(from: self)
}

func getYear() -> Int {
Calendar.current.component(.year, from: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,28 @@ struct PackagesForWithdrawalView: View {
List {
ForEach(ShipmentStatus.allCases) { status in
if !groupedPackages.filterGroupedPackages(by: status).isEmpty {
Section(header: Text(status.localized)) {
ForEach(groupedPackages.filter { $0.packageCurrentStatus == status }) { currentGroupedPackage in
getGroupedPackageView(for: currentGroupedPackage)
.groupedPackageRowStyle()
.onTapGesture {
coordinator.present(
sheet: .shipmentDetail(groupedPackage: currentGroupedPackage)
)
}
}
}
getSection(for: status, groupedPackages: groupedPackages)
}
}
}
.listStyle(.plain)
}

@ViewBuilder
private func getSection(for status: ShipmentStatus, groupedPackages: [GroupedPackageEntity]) -> some View {
Section(header: Text(status.localized)) {
ForEach(groupedPackages.filter { $0.packageCurrentStatus == status }) { currentGroupedPackage in
getGroupedPackageView(for: currentGroupedPackage)
.groupedPackageRowStyle()
.onTapGesture {
coordinator.present(
sheet: .shipmentDetail(groupedPackage: currentGroupedPackage)
)
}
}
}
}

@ViewBuilder
private func getGroupedPackageView(for groupedPackage: GroupedPackageEntity) -> some View {
if groupedPackage.packageCurrentStatus == .readyForPickup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct WithdrawnPackagesView: View {

var body: some View {
ZStack {
if let groupedPackagesEntity = viewModel.groupedPackagesEntity {
if let groupedPackagesEntity = viewModel.filteredGroupedPackages {
content(for: groupedPackagesEntity)
}
}
Expand All @@ -38,8 +38,26 @@ struct WithdrawnPackagesView: View {
if groupedPackages.isEmpty {
PackagePlaceholderView()
} else {
packagesList(groupedPackages)
VStack {
getYearPicker()
packagesList(groupedPackages)
}
}
}

@ViewBuilder
private func getYearPicker() -> some View {
HStack(alignment: .top) {
Text("Please select a year for filtering your shipments")
Spacer()
Picker("Select Year", selection: $viewModel.selectedYear) {
ForEach(viewModel.getYearsForFiltering, id: \.self) {
Text($0)
}
}
.pickerStyle(.menu)
}
.padding([.leading, .trailing, .top], 20)
}

@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@
import Foundation

final class WithdrawnPackagesViewModel: ObservableObject {
private enum Constants {
static var currentYear: String { "\(Date.now.getYear())" }
}

@Published var isLoading: Bool = false
@Published var toastMessage: String?
@Published var groupedPackagesEntity: [GroupedPackageEntity]?
@Published var selectedYear: String = Constants.currentYear

var filteredGroupedPackages: [GroupedPackageEntity]? {
groupedPackagesEntity?.filter { $0.formattedDate.contains(selectedYear) }
}

var getYearsForFiltering: [String] {
groupedPackagesEntity?.getYears() ?? []
}

private let packagesRepository: PackagesRepositoryProtocol

Expand All @@ -22,6 +35,10 @@ final class WithdrawnPackagesViewModel: ObservableObject {
func getPackages(forceUpdate: Bool = false) async {
guard groupedPackagesEntity == nil || forceUpdate else { return }

if forceUpdate {
selectedYear = Constants.currentYear
}

defer { isLoading = false }

do {
Expand Down
20 changes: 20 additions & 0 deletions mobile-courier-app/Utilities/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@
}
}
},
"Please select a year for filtering your shipments" : {
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Por favor, seleccione un año para filtrar sus pedidos"
}
}
}
},
"Processing" : {
"localizations" : {
"es" : {
Expand Down Expand Up @@ -262,6 +272,16 @@
}
}
},
"Select Year" : {
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Seleccione un año"
}
}
}
},
"Settings" : {
"localizations" : {
"es" : {
Expand Down
3 changes: 2 additions & 1 deletion mobile-courier-appTests/LoginViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class LoginViewModelTests: XCTestCase {
storageSpy = StorageSpy()
authRepoSpy = AuthRepositorySpy()

sut = LoginViewModel(authRepository: authRepoSpy)
sut = LoginViewModel(authRepository: authRepoSpy, storage: storageSpy)
}

override func tearDownWithError() throws {
Expand All @@ -35,5 +35,6 @@ final class LoginViewModelTests: XCTestCase {
func testLoadingState() async {
_ = await sut.doLogin()
XCTAssertTrue(authRepoSpy.performLoginCalled)
XCTAssertTrue(storageSpy.setStringCalled)
}
}

0 comments on commit 4054dfe

Please sign in to comment.