-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from helloItsHEssam/dev
Dev
- Loading branch information
Showing
163 changed files
with
6,473 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Data Layer | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '*' | ||
- '*/*' | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-13 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up SwiftLint | ||
run: brew install swiftlint | ||
|
||
- name: Lint code | ||
run: | | ||
cd Data/Sources/ | ||
swiftlint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Domain Layer | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '*' | ||
- '*/*' | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-13 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up SwiftLint | ||
run: brew install swiftlint | ||
|
||
- name: Lint code | ||
run: | | ||
cd Domain/Sources/ | ||
swiftlint | ||
- name: run unit test | ||
run: | | ||
cd Domain/Sources/ | ||
swift build | ||
swift test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.DS_Store | ||
*.swp | ||
*~.nib | ||
DerivedData/ | ||
build/ | ||
*.pbxuser | ||
*.mode1v3 | ||
*.mode2v3 | ||
*.perspectivev3 | ||
!default.pbxuser | ||
!default.mode1v3 | ||
!default.mode2v3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
!xcshareddata | ||
!xcschemes | ||
*.moved-aside | ||
/Pods | ||
/Carthage | ||
|
||
.swiftpm | ||
/node_modules | ||
/tmp | ||
|
||
.env | ||
.env.* | ||
|
||
**/fastlane/report.xml | ||
**/fastlane/Preview.html | ||
**/fastlane/screenshots | ||
**/fastlane/test_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// swift-tools-version: 5.8 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Data", | ||
platforms: [.iOS(.v14), .macOS(.v10_15)], | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "Data", | ||
targets: ["Data"]), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
.package(path: "../Domain"), | ||
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.8.1")) | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "Data", | ||
dependencies: ["Alamofire", "Domain"], | ||
resources: [.process("Resources")]), | ||
.testTarget( | ||
name: "DataTests", | ||
dependencies: ["Data"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Data | ||
|
||
## Description | ||
In Clean Architecture, the "Data" module plays a crucial role and is divided into two main parts: "Network" and "LocalStorage." This module allows the application to communicate with external resources and store the desired data in local files. | ||
|
||
"Network" Section: In this section, the application has the capability to communicate with external resources such as servers and web services. These communications are typically used to retrieve real-time data from external sources. | ||
"LocalStorage" Section: This section enables the application to store data in local files or local databases. This is usually done to retain data that the application may need for future use. | ||
In this way, the "Data" module provides the application with the ability to manage and access the required data in two parts, "Network" and "LocalStorage," allowing it to establish communication with external sources and store local data. | ||
|
||
## Targets | ||
In the **"Data"** module that we've created, there are the following targets: | ||
|
||
- **Common**: This section contains items that are needed across all other sections. | ||
|
||
- **Local**: In this section, the program fulfills all its requirements for storing and retrieving images from the device's memory. | ||
|
||
- **Http**: In this section, the program manages requests to the server. | ||
|
||
- **Repositories**: In this section, protocols needed by the "Domain" module are implemented. | ||
|
||
## Targets | ||
In this module, only the **"Alamofire"** library has been used for the "Network" target. | ||
|
||
## Diagrams | ||
<img alt="Data Digram" src="Diagram/1.png"> | ||
<img alt="Data Digram" src="Diagram/2.png"> | ||
<img alt="Data Digram" src="Diagram/3.png"> | ||
<img alt="Data Digram" src="Diagram/4.png"> | ||
<img alt="Data Digram" src="Diagram/5.png"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Mapper.swift | ||
// | ||
// | ||
// Created by Hessam Mahdiabadi on 11/5/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Mapper { | ||
|
||
associatedtype Entity | ||
associatedtype Dto | ||
|
||
func mapEntityToDto(input: Entity) -> Dto | ||
func mapDtoToEntity(input: Dto) -> Entity | ||
} | ||
|
||
public extension Mapper { | ||
|
||
func mapEntitiesToDtos(input: [Entity]) -> [Dto] { | ||
return input.map { mapEntityToDto(input: $0) } | ||
} | ||
|
||
func mapDtosToEntities(input: [Dto]) -> [Entity] { | ||
return input.map { mapDtoToEntity(input: $0) } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Api.swift | ||
// | ||
// | ||
// Created by Hessam Mahdiabadi on 11/5/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Api { | ||
|
||
func callApi<T: Decodable>(route: ApiRouter, decodeType type: T.Type) async throws -> T | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// ApiImpl.swift | ||
// | ||
// | ||
// Created by Hessam Mahdiabadi on 11/5/23. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
final public class ApiImpl: Api { | ||
|
||
private var sessionManager: Session | ||
private var decoder: JSONDecoder! | ||
|
||
#if DEBUG | ||
public init(configuration: URLSessionConfiguration) { | ||
sessionManager = Session(configuration: configuration) | ||
setupDecoder() | ||
} | ||
#endif | ||
|
||
public init() { | ||
sessionManager = Session() | ||
setupDecoder() | ||
} | ||
|
||
private func setupDecoder() { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" | ||
|
||
decoder = JSONDecoder() | ||
decoder.dateDecodingStrategy = .formatted(dateFormatter) | ||
} | ||
|
||
public func callApi<T: Decodable>(route: ApiRouter, decodeType type: T.Type) async throws -> T { | ||
return try await withCheckedThrowingContinuation { [weak self] continuation in | ||
guard let self else { | ||
continuation.resume(throwing: NetworkError.cannotConnectToServer) | ||
return | ||
} | ||
|
||
sessionManager.request(route) | ||
.validate(statusCode: 200 ..< 300) | ||
.responseData { [weak self] responseData in | ||
guard let self else { | ||
continuation.resume(throwing: NetworkError.cannotParseJson) | ||
return | ||
} | ||
|
||
switch responseData.result { | ||
case .success(let data): | ||
do { | ||
let retVal = try decoder.decode(type, from: data) | ||
continuation.resume(returning: retVal) | ||
} catch { | ||
continuation.resume(throwing: NetworkError.cannotParseJson) | ||
} | ||
|
||
case .failure: | ||
guard let data = responseData.data else { | ||
continuation.resume(throwing: NetworkError.cannotConnectToServer) | ||
return | ||
} | ||
|
||
guard let responseError = try? decoder.decode(ResponseError.self, from: data) else { | ||
continuation.resume(throwing: NetworkError.cannotConnectToServer) | ||
return | ||
} | ||
|
||
continuation.resume(throwing: NetworkError.serverError(message: responseError)) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// ApiRouter.swift | ||
// | ||
// | ||
// Created by Hessam Mahdiabadi on 11/5/23. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
public enum ApiRouter: URLRequestConvertible { | ||
|
||
public typealias Params = [String: Any] | ||
|
||
case transferList(offset: Int) | ||
|
||
public func asURLRequest() throws -> URLRequest { | ||
|
||
let httpMethod = getHttpMethod() | ||
let url = createURL() | ||
var urlRequest = URLRequest(url: url) | ||
urlRequest.httpMethod = httpMethod.rawValue | ||
urlRequest.timeoutInterval = 20.0 | ||
urlRequest.cachePolicy = .reloadIgnoringLocalCacheData | ||
|
||
let encoding: ParameterEncoding = { | ||
switch httpMethod { | ||
default: | ||
return URLEncoding.queryString | ||
} | ||
}() | ||
|
||
return try encoding.encode(urlRequest, with: self.getParams()) | ||
} | ||
} | ||
|
||
public extension ApiRouter { | ||
|
||
func getHttpMethod() -> HTTPMethod { | ||
switch self { | ||
case .transferList: | ||
return .get | ||
} | ||
} | ||
|
||
func getParams() -> Params? { | ||
return nil | ||
} | ||
|
||
var urlPath: String { | ||
switch self { | ||
case .transferList(let offset): | ||
return "/transfer-list/\(offset)" | ||
} | ||
} | ||
|
||
func createURL() -> URL { | ||
var component = URLComponents() | ||
component.scheme = "https" | ||
component.host = "191da1ac-768c-4c6a-80ad-b533beafec25.mock.pstmn.io" | ||
component.path = urlPath | ||
return component.url! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// CardDTO.swift | ||
// | ||
// | ||
// Created by Hessam Mahdiabadi on 11/5/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CardDTO: Decodable { | ||
|
||
var cardNumber: String? | ||
var cardType: String? | ||
|
||
init(cardNumber: String? = nil, cardType: String? = nil) { | ||
self.cardNumber = cardNumber | ||
self.cardType = cardType | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case cardNumber = "card_number" | ||
case cardType = "card_type" | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.cardNumber = try container.decodeIfPresent(String.self, forKey: .cardNumber) | ||
self.cardType = try container.decodeIfPresent(String.self, forKey: .cardType) | ||
} | ||
} |
Oops, something went wrong.