Skip to content

Commit

Permalink
Merge pull request #369 from School-of-Company/368-company-domain-set…
Browse files Browse the repository at this point in the history
…ting

🔀 :: [#368] Company 도메인 세팅
  • Loading branch information
uuuunseo authored Jul 18, 2024
2 parents fe12f4e + 4024389 commit b849b76
Show file tree
Hide file tree
Showing 21 changed files with 402 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
excluded:
- fastlane
- Dependencies
- Carthage

disabled_rules:
- void_function_in_ternary

identifier_name:
min_length: 1
max_length: 60
allowed_symbols: [_]

large_tuple:
warning: 3
error: 4

line_length:
warning: 120
error: 120
ignores_urls: true
ignores_comments: true

type_name:
min_length: 2
max_length: 60
allowed_symbols: [_]

28 changes: 28 additions & 0 deletions App/Sources/Application/DI/Company/AppComponent+Company.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import NeedleFoundation
import Service

public extension AppComponent {
var remoteCompanyDataSource: any RemoteCompanyDataSource {
shared {
RemoteCompanyDataSourceImpl(keychain: keychain)
}
}

var companyRepository: any CompanyRepository {
shared {
CompanyRepositoryImpl(remoteCompanyDataSource: remoteCompanyDataSource)
}
}

var fetchCompanyListUseCase: any FetchCompanyListUseCase {
FetchCompanyListUseCaseImpl(companyRepository: companyRepository)
}

var createdCompanyUseCase: any CreatedCompanyUseCase {
CreatedCompanyUseCaseImpl(companyRepository: companyRepository)
}

var deleteCompanyUseCase: any DeleteCompanyUseCase {
DeleteCompanyUseCaseImpl(companyRepository: companyRepository)
}
}
9 changes: 9 additions & 0 deletions App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,10 @@ extension AppComponent: Registration {
localTable["remoteSchoolDataSource-any RemoteSchoolDataSource"] = { [unowned self] in self.remoteSchoolDataSource as Any }
localTable["schoolRepository-any SchoolRepository"] = { [unowned self] in self.schoolRepository as Any }
localTable["fetchSchoolListUseCase-any FetchSchoolListUseCase"] = { [unowned self] in self.fetchSchoolListUseCase as Any }
localTable["fetchAllSchoolNameUseCase-any FetchAllSchoolNameUseCase"] = { [unowned self] in self.fetchAllSchoolNameUseCase as Any }
localTable["createdSchoolUseCase-any CreatedSchoolUseCase"] = { [unowned self] in self.createdSchoolUseCase as Any }
localTable["modifySchoolUseCase-any ModifySchoolUseCase"] = { [unowned self] in self.modifySchoolUseCase as Any }
localTable["deleteSchoolUseCase-any DeleteSchoolUseCase"] = { [unowned self] in self.deleteSchoolUseCase as Any }
localTable["remoteEmailDataSource-any RemoteEmailDataSource"] = { [unowned self] in self.remoteEmailDataSource as Any }
localTable["emailRepository-any EmailRepository"] = { [unowned self] in self.emailRepository as Any }
localTable["sendEmailCertificationLinkUseCase-any SendEmailCertificationLinkUseCase"] = { [unowned self] in self.sendEmailCertificationLinkUseCase as Any }
Expand All @@ -1381,6 +1385,11 @@ extension AppComponent: Registration {
localTable["fetchCertificationListByStudentUseCase-any FetchCertificationListByStudentUseCase"] = { [unowned self] in self.fetchCertificationListByStudentUseCase as Any }
localTable["inputCertificationUseCase-any InputCertificationUseCase"] = { [unowned self] in self.inputCertificationUseCase as Any }
localTable["updateCertificationUseCase-any UpdateCertificationUseCase"] = { [unowned self] in self.updateCertificationUseCase as Any }
localTable["remoteCompanyDataSource-any RemoteCompanyDataSource"] = { [unowned self] in self.remoteCompanyDataSource as Any }
localTable["companyRepository-any CompanyRepository"] = { [unowned self] in self.companyRepository as Any }
localTable["fetchCompanyListUseCase-any FetchCompanyListUseCase"] = { [unowned self] in self.fetchCompanyListUseCase as Any }
localTable["createdCompanyUseCase-any CreatedCompanyUseCase"] = { [unowned self] in self.createdCompanyUseCase as Any }
localTable["deleteCompanyUseCase-any DeleteCompanyUseCase"] = { [unowned self] in self.deleteCompanyUseCase as Any }
}
}

Expand Down
67 changes: 67 additions & 0 deletions Scripts/.swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

--exclude fastlane,Dependencies,Carthage
--swiftversion 5.8

# options
--maxwidth 120
--indent 4 # indent
--ifdef no-indent # indent
--trimwhitespace always # trailingSpace
--lineaftermarks false # fileHeader
--wraparguments before-first # wrapArguments
--wrapparameters before-first # wrapArguments
--wrapcollections before-first # wrapArguments
--someAny disabled # opaqueGenericParameters

# rules
--rules anyObjectProtocol
--rules blankLineAfterImports
--rules blankLinesAroundMark
--rules blankLinesAtEndOfScope
--rules blankLinesAtStartOfScope
--rules blankLinesBetweenImports
--rules blankLinesBetweenScopes
--rules braces
--rules consecutiveBlankLines
--rules consecutiveSpaces
--rules docComments
--rules duplicateImports
--rules elseOnSameLine
--rules emptyBraces
--rules enumNamespaces
--rules extensionAccessControl
--rules fileHeader
--rules hoistAwait
--rules hoistPatternLet
--rules hoistTry
--rules initCoderUnavailable
--rules indent
--rules isEmpty
--rules leadingDelimiters
--rules linebreakAtEndOfFile
--rules modifierOrder
--rules numberFormatting
--rules opaqueGenericParameters
--rules preferKeyPath
--rules redundantExtensionACL
--rules redundantOptionalBinding
--rules redundantParens
--rules redundantVoidReturnType
--rules semicolons
--rules sortedImports
--rules spaceAroundBraces
--rules spaceAroundBrackets
--rules spaceAroundComments
--rules spaceAroundGenerics
--rules spaceInsideBraces
--rules spaceInsideBrackets
--rules spaceInsideComments
--rules spaceInsideGenerics
--rules spaceInsideParens
--rules todos
--rules trailingClosures
--rules trailingSpace
--rules typeSugar
--rules void
--rules wrap
--rules wrapArguments
27 changes: 27 additions & 0 deletions Scripts/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
excluded:
- fastlane
- Dependencies

disabled_rules:
- void_function_in_ternary

identifier_name:
min_length: 1
max_length: 60
allowed_symbols: [_]

large_tuple:
warning: 3
error: 4

line_length:
warning: 120
error: 120
ignores_urls: true
ignores_comments: true

type_name:
min_length: 2
max_length: 60
allowed_symbols: [_]

1 change: 1 addition & 0 deletions Service/Sources/Base/BitgouelAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum BitgouelDomain: String {
case club
case email
case school
case company
}

extension BitgouelDomain {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

public final class RemoteCompanyDataSourceImpl: BaseRemoteDataSource<CompanyAPI>, RemoteCompanyDataSource {
public func fetchCompanyList() async throws -> [CompanyInfoEntity] {
try await request(.fetchCompanyList, dto: CompanyListResponseDTO.self).toDomain()
}

public func createdCompany(req: CreatedCompanyRequestDTO) async throws {
try await request(.createdCompany(req: req))
}

public func deleteCompany(companyID: String) async throws {
try await request(.deleteCompany(companyID: companyID))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

public struct CompanyRepositoryImpl: CompanyRepository {
private let remoteCompanyDataSource: any RemoteCompanyDataSource

public init(remoteCompanyDataSource: any RemoteCompanyDataSource) {
self.remoteCompanyDataSource = remoteCompanyDataSource
}

public func fetchCompanyList() async throws -> [CompanyInfoEntity] {
try await remoteCompanyDataSource.fetchCompanyList()
}

public func createdCompany(req: CreatedCompanyRequestDTO) async throws {
try await remoteCompanyDataSource.createdCompany(req: req)
}

public func deleteCompany(companyID: String) async throws {
try await remoteCompanyDataSource.deleteCompany(companyID: companyID)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public struct CreatedCompanyUseCaseImpl: CreatedCompanyUseCase {
private let companyRepository: any CompanyRepository

public init(companyRepository: any CompanyRepository) {
self.companyRepository = companyRepository
}

public func callAsFunction(req: CreatedCompanyRequestDTO) async throws {
try await companyRepository.createdCompany(req: req)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public struct DeleteCompanyUseCaseImpl: DeleteCompanyUseCase {
private let companyRepository: any CompanyRepository

public init(companyRepository: any CompanyRepository) {
self.companyRepository = companyRepository
}

public func callAsFunction(companyID: String) async throws {
try await companyRepository.deleteCompany(companyID: companyID)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public struct FetchCompanyListUseCaseImpl: FetchCompanyListUseCase {
private let companyRepository: any CompanyRepository

public init(companyRepository: any CompanyRepository) {
self.companyRepository = companyRepository
}

public func callAsFunction() async throws -> [CompanyInfoEntity] {
try await companyRepository.fetchCompanyList()
}
}
74 changes: 74 additions & 0 deletions Service/Sources/Domain/CompanyDomain/API/CompanyAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Foundation
import Moya

public enum CompanyAPI {
case fetchCompanyList
case createdCompany(req: CreatedCompanyRequestDTO)
case deleteCompany(companyID: String)
}

extension CompanyAPI: BitgouelAPI {
public typealias ErrorType = CompanyDomainError

public var domain: BitgouelDomain {
.company
}

public var urlPath: String {
switch self {
case .fetchCompanyList,
.createdCompany:
return ""

case let .deleteCompany(companyID):
return "/\(companyID)"
}
}

public var method: Moya.Method {
switch self {
case .fetchCompanyList:
return .get

case .createdCompany:
return .post

case .deleteCompany:
return .delete
}
}

public var task: Moya.Task {
switch self {
case .fetchCompanyList,
.deleteCompany:
return .requestPlain

case let .createdCompany(req):
return .requestJSONEncodable(req)
}
}

public var jwtTokenType: JwtTokenType {
switch self {
case .fetchCompanyList:
return .none

case .createdCompany,
.deleteCompany:
return .accessToken
}
}

public var errorMap: [Int: CompanyDomainError] {
switch self {
case .fetchCompanyList,
.createdCompany,
.deleteCompany:
return [
404: .notFound,
409: .conflict
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

public struct CreatedCompanyRequestDTO: Encodable {
public let companyName: String
public let field: FieldType
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation

public struct CompanyListResponseDTO: Decodable {
public let companies: [CompanyInfoResponseDTO]
}

public struct CompanyInfoResponseDTO: Decodable {
public let companyID: String
public let companyName: String
public let field: FieldType

enum CodingKeys: String, CodingKey {
case companyID = "id"
case companyName
case field
}
}

extension CompanyListResponseDTO {
func toDomain() -> [CompanyInfoEntity] {
companies.map { $0.toDomain() }
}
}

extension CompanyInfoResponseDTO {
func toDomain() -> CompanyInfoEntity {
CompanyInfoEntity(
companyID: companyID,
companyName: companyName,
field: field
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

public protocol RemoteCompanyDataSource: BaseRemoteDataSource<CompanyAPI> {
func fetchCompanyList() async throws -> [CompanyInfoEntity]
func createdCompany(req: CreatedCompanyRequestDTO) async throws
func deleteCompany(companyID: String) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

public struct CompanyInfoEntity: Equatable {
public let companyID: String
public let companyName: String
public let field: FieldType
}
Loading

0 comments on commit b849b76

Please sign in to comment.