Skip to content

Commit

Permalink
Merge pull request #8 from helloItsHEssam/feature/modularization-pres…
Browse files Browse the repository at this point in the history
…entation

Feature/modularization presentation
  • Loading branch information
helloItsHEssam authored Nov 6, 2023
2 parents a2959e4 + 65f8cca commit 5268871
Show file tree
Hide file tree
Showing 57 changed files with 2,078 additions and 115 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/Data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,4 @@ jobs:
- name: Lint code
run: |
cd Data/Sources/
swiftlint
- name: run unit test
run: |
cd Data/
swift build
swift test
swiftlint
2 changes: 1 addition & 1 deletion Data/Sources/Data/Http/ApiImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final public class ApiImpl: Api {
continuation.resume(throwing: NetworkError.cannotConnectToServer)
return
}

sessionManager.request(route)
.validate(statusCode: 200 ..< 300)
.responseData { [weak self] responseData in
Expand Down
17 changes: 14 additions & 3 deletions Domain/Sources/Domain/Entities/PersonBankAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

import Foundation

public struct PersonBankAccount: Identifiable {
public struct PersonBankAccount: Identifiable, Hashable {

public var id: String {
card?.cardNumber ?? UUID().uuidString
guard let name = person?.name, let cardNumber = card?.cardNumber else {
return UUID().uuidString
}
return name + cardNumber
}
public var person: Person?
public var card: Card?
Expand All @@ -36,4 +39,12 @@ public struct PersonBankAccount: Identifiable {
mutating func update(indexAtList index: Int) {
self.indexAtList = index
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}

public static func == (lhs: PersonBankAccount, rhs: PersonBankAccount) -> Bool {
lhs.id == rhs.id
}
}
2 changes: 1 addition & 1 deletion Domain/Sources/Domain/Error/PersonBankAccountError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum PersonBankAccountError: Error {
case cannotFetchFavoritePersonAccounts
case unexpectedError

var errorDescription: String? {
public var errorDescription: String? {
switch self {
case .cannotSavePersonAccountToFavorites:
return "Failed to save person accounts to favorites"
Expand Down
459 changes: 430 additions & 29 deletions TransferList.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
"revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad",
"version" : "5.8.1"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"state" : {
"revision" : "277f1ab2c6664b19b4a412e32b094b201e2d5757",
"version" : "7.10.0"
}
}
],
"version" : 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand All @@ -31,6 +29,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

14 changes: 14 additions & 0 deletions TransferList/Application/DI/DIContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// DIContainer.swift
// TransferList
//
// Created by Hessam Mahdiabadi on 11/6/23.
//

import Foundation
import Domain

protocol DIContainer {

func createPresonBankAccountUseCase() -> PersonBankAccountUseCase
}
27 changes: 27 additions & 0 deletions TransferList/Application/DI/DIContainerImpl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// DIContainerImpl.swift
// TransferList
//
// Created by Hessam Mahdiabadi on 11/6/23.
//

import Foundation
import Domain
import Data

final class DIContainerImpl: DIContainer {

private func createPersonBankAccountRepository() -> PersonBankAccountRepository {
let api: Api = ApiImpl()
let database = DatabaseImpl()
let local = LocalImpl(database: database)

return PersonBankAccountRepositoryImpl(api: api, local: local)
}

func createPresonBankAccountUseCase() -> PersonBankAccountUseCase {
let repository = createPersonBankAccountRepository()
let useCase = PersonBankAccountUseCaseImpl(repository: repository)
return useCase
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
//

import UIKit
import UI

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?


func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
guard let window = (scene as? UIWindowScene) else { return }
startApp(windowScene: window)
}

func sceneDidDisconnect(_ scene: UIScene) {
Expand Down Expand Up @@ -47,6 +49,40 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// to restore the scene back to its current state.
}

private func startApp(windowScene scene: UIWindowScene) {
let window = UIWindow(windowScene: scene)

setupDIContainer()
registerFonts()

let navController = createNavigationController()
let homeViewController = createHomeViewController()

navController.pushViewController(homeViewController, animated: false)

window.rootViewController = navController
self.window = window
window.makeKeyAndVisible()
}

private func createNavigationController() -> UINavigationController {
let navigationController = UINavigationController()
navigationController.isNavigationBarHidden = true

return navigationController
}

private func createHomeViewController() -> HomeViewController {
let homeViewController = HomeViewController()
return homeViewController
}

private func registerFonts() {
Font.registerFonts()
}

private func setupDIContainer() {
let container = DIContainerImpl()
ViewModelFactory.shared.register(DIContainer: container)
}
}

24 changes: 0 additions & 24 deletions TransferList/Base.lproj/Main.storyboard

This file was deleted.

32 changes: 32 additions & 0 deletions TransferList/Extra/Core/PaginationMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// PaginationMode.swift
// TransferList
//
// Created by Hessam Mahdiabadi on 11/6/23.
//

import Foundation

struct PaginationMode {

enum Mode {
case continues
case reachedToEnd
}

var offset: Int = 0
var mode: Mode = .continues

var nextOffset: Int {
offset + 1
}

mutating func moveToNextOffset() {
self.offset += 1
}

mutating func reset() {
offset = 0
mode = .continues
}
}
26 changes: 26 additions & 0 deletions TransferList/Extra/Core/Router.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Router.swift
// TransferList
//
// Created by Hessam Mahdiabadi on 11/6/23.
//

import Foundation
import Domain

enum Router: Hashable, Equatable {

case home
case detail(account: PersonBankAccount)

func hash(into hasher: inout Hasher) {
switch self {
case .home: hasher.combine("home")
case .detail(let account): hasher.combine(account)
}
}

static func == (lhs: Router, rhs: Router) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
30 changes: 30 additions & 0 deletions TransferList/Extra/Core/ViewModelFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// ViewModelFactory.swift
// TransferList
//
// Created by Hessam Mahdiabadi on 11/6/23.
//

import Foundation

class ViewModelFactory {

private var container: DIContainer!

static let shared = ViewModelFactory()

private init() {}

func register(DIContainer container: DIContainer) {
self.container = container
}

func createMediaViewModel() -> TransferViewModel {
guard container != nil else {
fatalError("Register DIContainer to Enable ViewModel Creation")
}

let personBankAccountUseCase = container.createPresonBankAccountUseCase()
return .init(personBackAccountUseCase: personBankAccountUseCase)
}
}
35 changes: 35 additions & 0 deletions TransferList/Extra/Core/ViewState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ViewState.swift
// TransferList
//
// Created by Hessam Mahdiabadi on 11/6/23.
//

import Foundation

enum ViewState: Hashable, Equatable, CustomStringConvertible {

case loading
case result
case error(message: String)

func hash(into hasher: inout Hasher) {
switch self {
case .error: hasher.combine("error")
case .result: hasher.combine("result")
case .loading: hasher.combine("loading")
}
}

var description: String {
switch self {
case .error(let message): return message
case .result: return "result"
case .loading: return "loading"
}
}

static func == (lhs: ViewState, rhs: ViewState) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
19 changes: 19 additions & 0 deletions TransferList/Extra/Extension/UIViewController+Alert.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// UIViewController+Alert.swift
// TransferList
//
// Created by Hessam Mahdiabadi on 11/6/23.
//

import UIKit

extension UIViewController {

func showAlert(title: String, message: String) {
let dialogMessage = UIAlertController(title: title, message: message, preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default)

dialogMessage.addAction(ok)
self.present(dialogMessage, animated: true, completion: nil)
}
}
Loading

0 comments on commit 5268871

Please sign in to comment.