Skip to content

Commit

Permalink
Merge pull request #19 from vespinola/18-create-a-view-for-packages-f…
Browse files Browse the repository at this point in the history
…or-withdrawal

18 create a view for packages for withdrawal
  • Loading branch information
vespinola authored Jun 20, 2024
2 parents 3d771a2 + 4030385 commit 39596cd
Show file tree
Hide file tree
Showing 29 changed files with 460 additions and 128 deletions.
70 changes: 49 additions & 21 deletions mobile-courier-app.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct AuthRepository: AuthRepositoryProtocol {
decoder: JSONDecoder()
)

// let model = LoginEntity(username: "[email protected]", accessToken: "eyJhbGciOiJIUzI1NiJ9.eyJwcmluY2lwYWwiOiJINHNJQUFBQUFBQUFBSlZTejJzVFFSUitpU2tWaXRnV0ZFUXFIdXBOTmpZaE5DR1gybEtsc0NSaXpLV0NaYkw3c2s0N083UE96S2FiaThTTFBYZ1ExSUxneFlNbjZYXC9peVQ5QUVPODk5K3FidE0ybVhvckx3aTV2dnYxK3ZUMDZoaG1qb1JwcHhvWHhFcEZHWEhvbTBWeEdCb05VY3p2MFVvTTZSRHRHUEI0RHV6U0IwNnRRaElJUFJSNWFXUFIzMllDVkJaTlJ1ZDNieGNBMk13MFZwYU16eHI1bU1lNHJ2ZWROdUFPbDhZSkFUbDFZSzhMc05peXdJRkNwdEMwbE43T0Vhd3kzWVQ2ZitTclljNk1iQVoyZ3RKd0pNdzJkUmNsNkFrTWY1bGhxWHlwUzVXZ3NYRDgxbTFvdXloMjBUUit1SnN3WWN2ZFBrbzUxMXQyNXN5a3B3U3Q0RGFVc0tkQkYzZDF6VU1cL3hlQnRLQ0VyTmxUVExYUm1ya1BlNUV5ZiswZEtIbisrXC9qTHBGQU9ya1wvdVhmNVBOYjZ6RDY4ZUxrenJqb1FtRGg1cFQxSE5iTUVuS3prRE1cLzAraVVmMzErOHZIdytPRDVGVkoyaUVmXC92NFwvbGgyZk5EVGRVbkRETnJKcmFFZEh1bDl3N2thOWZUbjYraGFIWDRYRWlrUDRvYVRHY1NPVEVGTGVrbFRqdjI4SzFwMjFcL2M2ZlYzbkhQVG1iaGJyOGZybFRweGxWV2J6UjZyRjZyWTZOU3FmYnJxMkd0aGc4czNCNElGdktZYXc5TndxVVNiQzJLS1JtWmlTZDl1VVY3VzJRalFyMzQ1K3Uza3pjSGRkTGZncGtCRXluU3h1WnpYQ3VOZTZqZkhoMHV6WDM2XC9XNmNIOERcL1wvaGNLbEMyeFN3TUFBQT09Iiwic3ViIjoidmxhZGltaXIuZXNwaW5vbGFAZ21haWwuY29tIiwiZXhwIjoxNzI0NTQxOTQ3LCJpYXQiOjE3MTg0OTM5NDcsInJvbGVzIjpbIlJPTEVfTk9fUk9MRVMiXX0._SSqulgIqcM0GabBT7oSULFsWEgiFGQKDGDpVKdFy3U")
//
AppData.shared.updateToken(model.accessToken)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ struct PackagesRepository: PackagesRepositoryProtocol {
self.apiRequestClient = apiRequestClient
}

func getPackagesRetrieved() async throws -> [GroupedPackageEntity] {
func getWithdrawnPackages() async throws -> [GroupedPackageEntity] {
let model: PackagesModel = try await apiRequestClient.performRequest(
endpoint: PackageEndpoints.retrieved,
endpoint: PackageEndpoints.withdrawn,
decoder: JSONDecoder()
)

return model.asEntity()
}

func getPackagesForWithdrawl() async throws -> [GroupedPackageEntity] {
let model: PackagesModel = try await apiRequestClient.performRequest(
endpoint: PackageEndpoints.forWithdrawl,
decoder: JSONDecoder()
)

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

enum PackageEndpoints {
case retrieved
case withdrawn
case forWithdrawl
}

extension PackageEndpoints: Endpoint {
Expand All @@ -21,7 +22,12 @@ extension PackageEndpoints: Endpoint {
}

var path: String {
"/frontliner-middleware/api/paquetesRetirados"
switch self {
case .withdrawn:
"/frontliner-middleware/api/paquetesRetirados"
case .forWithdrawl:
"/frontliner-middleware/api/paquetesPendientes"
}
}

var body: [AnyHashable: Any]? {
Expand Down
6 changes: 3 additions & 3 deletions mobile-courier-app/Data/Networking/Models/PackagesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct PackagesModel: Codable {
struct PackageModel: Codable {
let estado: String
let embarqueEstado: String
let paqueteFechaRetiro: String
var paqueteFechaRetiro: String?
let embarqueMedio: String
let tarifaPrecioCli: Decimal
let paqueteDescripcion: String
Expand Down Expand Up @@ -48,7 +48,7 @@ extension PackageModel {
.init(
estado: estado,
embarqueEstado: embarqueEstado,
paqueteFechaRetiro: paqueteFechaRetiro,
paqueteFechaRetiro: paqueteFechaRetiro ?? "",
embarqueMedio: embarqueMedio,
tarifaPrecioCli: tarifaPrecioCli,
paqueteDescripcion: paqueteDescripcion,
Expand All @@ -72,7 +72,7 @@ extension PackagesModel {
.map {
GroupedPackageEntity(
embarqueCodigo: $0.key,
paquetes: $0.value.map { $0.asEntity() }
paquetes: Set($0.value.map { $0.asEntity() })
)
}
}
Expand Down
41 changes: 38 additions & 3 deletions mobile-courier-app/Domain/Entities/PackageEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@

import Foundation

enum ShipmentStatus: String, CaseIterable, Identifiable {
case readyForPickup = "Ready for Pickup"
case processing = "Processing"
case onTheWay = "On the Way"
case inLocker = "In Locker"
case inconsistent = "Inconsistent"
case unknown = "Unknown Status"

var id: String { self.rawValue }
}

struct GroupedPackageEntity: Identifiable {
var id: Int { embarqueCodigo }

var embarqueCodigo: Int
var paquetes: [PackageEntity]
var paquetes: Set<PackageEntity>

var totalCost: Decimal {
let thousand: Decimal = 1000
Expand Down Expand Up @@ -63,12 +74,36 @@ struct GroupedPackageEntity: Identifiable {
formatter.allowsFloats = false
formatter.groupingSeparator = ""

let formattedValue = NSDecimalNumber(integerLiteral: embarqueCodigo)
let formattedValue = NSDecimalNumber(value: embarqueCodigo)
return formatter.string(from: formattedValue) ?? "0"
}

var packageCurrentStatus: ShipmentStatus {
guard let shippingStatus = paquetes.first?.embarqueEstado,
let status = paquetes.first?.estado else {
return .unknown
}
if shippingStatus.caseInsensitiveCompare("ORIGEN") == .orderedSame {
return .inLocker
} else if shippingStatus.caseInsensitiveCompare("TRANSITO") == .orderedSame {
return .onTheWay
} else if shippingStatus.caseInsensitiveCompare("UBICANDO") == .orderedSame && status.caseInsensitiveCompare("A") == .orderedSame {
return .processing
} else if (shippingStatus.caseInsensitiveCompare("UBICANDO") == .orderedSame || shippingStatus.caseInsensitiveCompare("ASUNCION") == .orderedSame) && status.caseInsensitiveCompare("B") == .orderedSame {
return .readyForPickup
}

return status.caseInsensitiveCompare("C") == .orderedSame ? .inconsistent : .unknown
}
}

extension Array where Element == GroupedPackageEntity {
func filterGroupedPackages(by shipmentStatus: ShipmentStatus) -> [Element] {
filter { $0.packageCurrentStatus == shipmentStatus }
}
}

struct PackageEntity: Codable, Identifiable {
struct PackageEntity: Codable, Identifiable, Hashable {
let estado: String
let embarqueEstado: String
let paqueteFechaRetiro: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
import Foundation

protocol PackagesRepositoryProtocol {
func getPackagesRetrieved() async throws -> [GroupedPackageEntity]
func getWithdrawnPackages() async throws -> [GroupedPackageEntity]
func getPackagesForWithdrawl() async throws -> [GroupedPackageEntity]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// RoundedIndicatorViewModifier.swift
// mobile-courier-app
//
// Created by Vladimir Espinola on 2024-06-19.
//

import SwiftUI

struct RoundedIndicatorViewModifier: ViewModifier {
func body(content: Content) -> some View {
content
.padding(4)
.foregroundStyle(.white)
.background(
RoundedRectangle(cornerRadius: 8)
.foregroundStyle(.accent)
)
}
}

extension View {
func roundedIndicator() -> some View {
ModifiedContent(content: self, modifier: RoundedIndicatorViewModifier())
}
}
6 changes: 4 additions & 2 deletions mobile-courier-app/Presentation/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ struct HomeView: View {
HeaderView()

TabView {
coordinator.build(page: .package)
coordinator.build(page: .packagesForWithdrawl)
.tabItem {
Label("Home", systemImage: "house")
}

coordinator.build(page: .package)
coordinator.build(page: .withdrawnPackages)
.tabItem {
Label("Withdrawn", systemImage: "bag")
}
Expand All @@ -39,4 +39,6 @@ struct HomeView: View {

#Preview {
HomeView()
.environmentObject(Coordinator())
.environmentObject(AppData())
}
10 changes: 7 additions & 3 deletions mobile-courier-app/Presentation/Navigation/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ enum Page: String, Identifiable {
case login
case home
case profile
case package
case withdrawnPackages
case packagesForWithdrawl

var id: String {
self.rawValue
Expand Down Expand Up @@ -65,9 +66,12 @@ final class Coordinator: ObservableObject {
ProfileView(viewModel: .init(addressesRepository: addressRepo))
case .home:
HomeView()
case .package:
case .withdrawnPackages:
let packagesRepo = PackagesRepository(apiRequestClient: apiClient)
PackagesView(viewModel: .init(packagesRepository: packagesRepo))
WithdrawnPackagesView(viewModel: .init(packagesRepository: packagesRepo))
case .packagesForWithdrawl:
let packagesRepo = PackagesRepository(apiRequestClient: apiClient)
PackagesForWithdrawalView(viewModel: .init(packagesRepository: packagesRepo))
}
}

Expand Down
43 changes: 0 additions & 43 deletions mobile-courier-app/Presentation/Package/PackagesView.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// GroupedPackageReadyView.swift
// mobile-courier-app
//
// Created by Vladimir Espinola on 2024-06-19.
//

import SwiftUI

struct GroupedPackageReadyView: View {

var groupedPackage: GroupedPackageEntity

var body: some View {
VStack(spacing: 8) {
HStack(alignment: .center) {
Text("At the branch")
.roundedIndicator()

Spacer()

VStack(alignment: .trailing) {
Text("\(groupedPackage.totalWeight) Kg")
}
}

HStack {
Text("\(groupedPackage.paquetes.count) packages")

Spacer()

Text("Gs. \(groupedPackage.formattedTotalCost)")
.foregroundStyle(.accent)
.font(.title2)
.fontWeight(.bold)
}

}
.frame(maxWidth: .infinity)
.padding(.init(
top: 8,
leading: 16,
bottom: 8,
trailing: 16)
)
.foregroundStyle(.black)
.background(
RoundedRectangle(cornerRadius: 6)
.fill(Color.surface)
)
.clipped()
.listRowSeparator(.hidden)
.listRowSpacing(.zero)
.listRowInsets(.none)
}
}

#Preview {
GroupedPackageReadyView(
groupedPackage: .init(
embarqueCodigo: 2000,
paquetes: [
.mock
]
)
)
}
Loading

0 comments on commit 39596cd

Please sign in to comment.