Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Centauryal committed Dec 14, 2021
0 parents commit c7355e3
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
29 changes: 29 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Core",
platforms: [.iOS(.v15), .macOS(.v12)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Core",
targets: ["Core"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
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: "Core",
dependencies: []),
.testTarget(
name: "CoreTests",
dependencies: ["Core"]),
]
)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Core

A description of this package.
25 changes: 25 additions & 0 deletions Sources/Core/Data/LocaleDataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 03/12/21.
//

import Combine

public protocol LocaleDataSource {
associatedtype Request
associatedtype Response

func getAllList(request: Request?) -> AnyPublisher<[Response], Error>

func getById(_ id: Int) -> AnyPublisher<Response, Error>

func set(_ entity: Response) -> AnyPublisher<Bool, Error>

func deleteAll(request: Request?) -> AnyPublisher<Bool, Error>

func deleteById(_ id: Int) -> AnyPublisher<Bool, Error>

func loadUserDefault() -> AnyPublisher<Response, Error>
}
16 changes: 16 additions & 0 deletions Sources/Core/Data/Mapper/LocaleMapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 09/12/21.
//

import Foundation

public protocol LocaleMapper {
associatedtype Entity
associatedtype Domain

func transformEntityToDomain(entity: Entity) -> Domain
func transfomDomainToEntity(domain: Domain) -> Entity
}
15 changes: 15 additions & 0 deletions Sources/Core/Data/Mapper/Mapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 06/12/21.
//

import Foundation

public protocol Mapper {
associatedtype Response
associatedtype Domain

func transfomResponseToDomain(response: Response) -> Domain
}
15 changes: 15 additions & 0 deletions Sources/Core/Data/RemoteDataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 03/12/21.
//

import Combine

public protocol RemoteDataSource {
associatedtype Request
associatedtype Response

func execute(request: Request?) -> AnyPublisher<Response, Error>
}
15 changes: 15 additions & 0 deletions Sources/Core/Data/Repository/Repository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 03/12/21.
//

import Combine

public protocol Repository {
associatedtype Request
associatedtype Response

func execute(request: Request?) -> AnyPublisher<Response, Error>
}
23 changes: 23 additions & 0 deletions Sources/Core/Domain/UseCase/Interactor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 03/12/21.
//

import Foundation
import Combine

public struct Interactor<Request, Response, R: Repository>: UseCase
where R.Request == Request, R.Response == Response {

private let _repository: R

public init(repository: R) {
_repository = repository
}

public func execute(request: Request?) -> AnyPublisher<Response, Error> {
_repository.execute(request: request)
}
}
15 changes: 15 additions & 0 deletions Sources/Core/Domain/UseCase/UseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 03/12/21.
//

import Combine

public protocol UseCase {
associatedtype Request
associatedtype Response

func execute(request: Request?) -> AnyPublisher<Response, Error>
}
34 changes: 34 additions & 0 deletions Sources/Core/Presentation/GetPresenter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// File.swift
//
//
// Created by Alfa Centaury on 08/12/21.
//

import Combine
import Foundation

public class GetPresenter<Request, Response, Interactor: UseCase>
where Interactor.Request == Request, Interactor.Response == Response {

private var cancellables: Set<AnyCancellable> = []
private let _useCase: Interactor

public init(useCase: Interactor) {
_useCase = useCase
}

public func getPresenter(request: Request?,
receiveCompletion: @escaping (Subscribers.Completion<Error>) -> Void,
receiveValue: @escaping (Response) -> Void) {
_useCase.execute(request: request)
.receive(on: RunLoop.main)
.sink(receiveCompletion: { completion in
receiveCompletion(completion)
},
receiveValue: { result in
receiveValue(result)
})
.store(in: &cancellables)
}
}
11 changes: 11 additions & 0 deletions Tests/CoreTests/CoreTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import XCTest
@testable import Core

final class CoreTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(Core().text, "Hello, World!")
}
}

0 comments on commit c7355e3

Please sign in to comment.