diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/API/CoreAuthAPI.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/API/CoreAuthAPI.swift new file mode 100644 index 000000000..2764cd3ec --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/API/CoreAuthAPI.swift @@ -0,0 +1,77 @@ +// +// CoreAuthAPI.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Moya + +public enum CoreAuthAPI { + case sendVerifyCode(dto: SendVerificationCodeEntity) + case verfiyCode(dto: VerifyCodeEntity) + case signUp(dto: SignUpEntity) + case login(dto: LoginEntity) +} + +extension CoreAuthAPI: BaseAPI { + + public static var apiType: APIType = .coreAuth + + // MARK: - Header + public var headers: [String: String]? { + switch self { + default: + return HeaderType.json.value + } + } + + // MARK: - Path + public var path: String { + switch self { + case .sendVerifyCode: + return "/phone" + case .verfiyCode: + return "/verify/phone" + case .signUp: + return "/signup" + case .login: + return "/login/app" + } + } + + // MARK: - Method + public var method: Moya.Method { + switch self { + case .sendVerifyCode: + return .post + case .verfiyCode: + return .post + case .signUp: + return .post + case .login: + return .post + } + } + + + public var task: Task { + switch self { + case let .sendVerifyCode(dto): + return .requestJSONEncodable(dto) + case let .verfiyCode(dto): + return .requestJSONEncodable(dto) + case let .signUp(dto): + return .requestJSONEncodable(dto) + case let .login(dto): + return .requestJSONEncodable(dto) + } + } + + public var validationType: ValidationType { + return .none + } +} + + diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/API/SocialAPI.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/API/SocialAPI.swift new file mode 100644 index 000000000..a224616d3 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/API/SocialAPI.swift @@ -0,0 +1,58 @@ +// +// SocialAPI.swift +// Networks +// +// Created by 장석우 on 12/28/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Moya + +public enum SocialAPI { + case getSocialAccount(phone: String) + case changeSocialAccount(dto: ChangeSocialAccountEntity) +} + +extension SocialAPI: BaseAPI { + + public static var apiType: APIType = .social + + // MARK: - Header + public var headers: [String: String]? { + switch self { + default: + return HeaderType.json.value + } + } + + // MARK: - Path + public var path: String { + switch self { + case .getSocialAccount: + return "/accounts/platform" + case .changeSocialAccount: + return "/accounts" + } + } + + // MARK: - Method + public var method: Moya.Method { + switch self { + case .getSocialAccount: + return .get + case .changeSocialAccount: + return .patch + } + } + + + public var task: Task { + switch self { + case let .getSocialAccount(phone): + return .requestParameters(parameters: ["phone": phone], encoding: URLEncoding.queryString) + case let .changeSocialAccount(entity): + return .requestJSONEncodable(entity) + } + } +} + diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/ChangeSocialAccountEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/ChangeSocialAccountEntity.swift new file mode 100644 index 000000000..8126dacbc --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/ChangeSocialAccountEntity.swift @@ -0,0 +1,25 @@ +// +// ChangeSocialAccountEntity.swift +// Networks +// +// Created by 장석우 on 12/28/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct ChangeSocialAccountEntity: Encodable { + let phone: String + let authPlatform: PlatformType + let code: String + + public init(phone: String, authPlatform: PlatformType, code: String) { + self.phone = phone + self.authPlatform = authPlatform + self.code = code + } +} + +public extension ChangeSocialAccountEntity { + static let stub: ChangeSocialAccountEntity = .init(phone: "01011111111", authPlatform: .apple, code: "code") +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/CoreSignInEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/CoreSignInEntity.swift new file mode 100644 index 000000000..0f401d5eb --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/CoreSignInEntity.swift @@ -0,0 +1,19 @@ +// +// CoreSignInEntity.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct CoreSignInEntity: Decodable { + let accessToken: String + let refreshToken: String + + public init(accessToken: String, refreshToken: String) { + self.accessToken = accessToken + self.refreshToken = refreshToken + } +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/LoginEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/LoginEntity.swift new file mode 100644 index 000000000..6c87cbf31 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/LoginEntity.swift @@ -0,0 +1,19 @@ +// +// LoginEntity.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct LoginEntity: Encodable { + let code: String + let authPlatform: PlatformType + + public init(code: String, authPlatform: PlatformType) { + self.code = code + self.authPlatform = authPlatform + } +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/PlatformType.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/PlatformType.swift new file mode 100644 index 000000000..20956b321 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/PlatformType.swift @@ -0,0 +1,14 @@ +// +// PlatformType.swift +// Networks +// +// Created by 장석우 on 12/28/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public enum PlatformType: String, Codable { + case google = "GOOGLE" + case apple = "APPLE" +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SendVerificationCodeEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SendVerificationCodeEntity.swift new file mode 100644 index 000000000..73de1c036 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SendVerificationCodeEntity.swift @@ -0,0 +1,21 @@ +// +// SendVerificationCodeEntity.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct SendVerificationCodeEntity: Encodable { + let name: String + let phone: String + let type: VerifyType + + public init(name: String, phone: String, type: VerifyType) { + self.name = name + self.phone = phone.filter{ $0.isNumber } + self.type = type + } +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SignUpEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SignUpEntity.swift new file mode 100644 index 000000000..2145e8884 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SignUpEntity.swift @@ -0,0 +1,25 @@ +// +// SignUpEntity.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct SignUpEntity: Encodable { + let name: String + let phone: String + let type: VerifyType + let code: String + let authPlatform: PlatformType + + public init(name: String, phone: String, type: VerifyType, code: String, authPlatform: PlatformType) { + self.name = name + self.phone = phone + self.type = type + self.code = code + self.authPlatform = authPlatform + } +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SocialAccountResultEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SocialAccountResultEntity.swift new file mode 100644 index 000000000..a699f79b6 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/SocialAccountResultEntity.swift @@ -0,0 +1,13 @@ +// +// ChangeSocialResultEntity.swift +// Networks +// +// Created by 장석우 on 12/28/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct SocialAccountResultEntity: Decodable { + let platform: PlatformType +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyCodeEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyCodeEntity.swift new file mode 100644 index 000000000..bd753e4a8 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyCodeEntity.swift @@ -0,0 +1,23 @@ +// +// VerifyCodeEntity.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct VerifyCodeEntity: Encodable { + let name: String + let phone: String + let type: VerifyType + let code: String + + public init(name: String, phone: String, type: VerifyType, code: String) { + self.name = name + self.phone = phone + self.type = type + self.code = code + } +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyResultEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyResultEntity.swift new file mode 100644 index 000000000..bf3ef88b7 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyResultEntity.swift @@ -0,0 +1,21 @@ +// +// VerifyResultEntity.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct VerifyResultEntity: Decodable { + let isVerified: Bool + let name: String + let phone: String + + public init(isVerified: Bool, name: String, phone: String) { + self.isVerified = isVerified + self.name = name + self.phone = phone + } +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyType.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyType.swift new file mode 100644 index 000000000..32149cb4e --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/CoreAuth/VerifyType.swift @@ -0,0 +1,16 @@ +// +// VerifyType.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation + + +public enum VerifyType: String, Encodable { + case register = "REGISTER" + case change = "CHANGE" + case search = "SEARCH" +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Foundation/BaseAPI.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Foundation/BaseAPI.swift index 9e743bb92..c56b053ae 100644 --- a/SOPT-iOS/Projects/Modules/Networks/Sources/Foundation/BaseAPI.swift +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Foundation/BaseAPI.swift @@ -25,6 +25,8 @@ public enum APIType { case poke case s3 case fortune + case coreAuth + case social } public protocol BaseAPI: TargetType { @@ -35,7 +37,8 @@ extension BaseAPI { public var baseURL: URL { var base = Config.Network.baseURL let operationBaseURL = Config.Network.operationBaseURL - + let coreAuthBaseURL = Config.Network.coreAuthBaseURL + switch Self.apiType { case .attendance: base = operationBaseURL @@ -63,6 +66,10 @@ extension BaseAPI { base += "/s3" case .fortune: base += "/fortune" + case .coreAuth: + base = coreAuthBaseURL + "/auth" + case .social: + base = coreAuthBaseURL + "/social" } guard let url = URL(string: base) else { diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Service/CoreAuthService.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/CoreAuthService.swift new file mode 100644 index 000000000..8a1a9cf6e --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/CoreAuthService.swift @@ -0,0 +1,37 @@ +// +// CoreAuthService.swift +// Networks +// +// Created by 장석우 on 12/30/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation +import Combine + +import Core +import Moya + + +public typealias DefaultCoreAuthService = BaseService + +public protocol CoreAuthService { + func sendVerifyCode(_ dto: SendVerificationCodeEntity) -> AnyPublisher + func verifyCode(_ dto: VerifyCodeEntity) -> AnyPublisher, Error> + func login(_ dto: LoginEntity) -> AnyPublisher, Error> +} + +extension DefaultCoreAuthService: CoreAuthService { + public func sendVerifyCode(_ dto: SendVerificationCodeEntity) -> AnyPublisher { + requestObjectInCombineNoResult(.sendVerifyCode(dto: dto)) + } + + public func verifyCode(_ dto: VerifyCodeEntity) -> AnyPublisher, Error> { + requestObjectInCombine(.verfiyCode(dto: dto)) + } + + public func login(_ dto: LoginEntity) -> AnyPublisher, Error> { + requestObjectInCombine(.login(dto: dto)) + } +} + diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Service/SocialService.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/SocialService.swift new file mode 100644 index 000000000..90ab1f970 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/SocialService.swift @@ -0,0 +1,31 @@ +// +// SocialService.swift +// Networks +// +// Created by 장석우 on 12/28/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import Foundation +import Combine + +import Core +import Moya + + +public typealias DefaultSocialService = BaseService + +public protocol SocialService { + func getSocialAccount(for phoneNumber: String) -> AnyPublisher, Error> + func changeSocialAccount(with entity: ChangeSocialAccountEntity) -> AnyPublisher +} + +extension DefaultSocialService: SocialService { + public func getSocialAccount(for phoneNumber: String) -> AnyPublisher, Error> { + requestObjectInCombine(.getSocialAccount(phone: phoneNumber)) + } + + public func changeSocialAccount(with entity: ChangeSocialAccountEntity) -> AnyPublisher { + return requestObjectInCombineNoResult(.changeSocialAccount(entity: entity)) + } +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Tests/Sources/SocialEntityTests.swift b/SOPT-iOS/Projects/Modules/Networks/Tests/Sources/SocialEntityTests.swift new file mode 100644 index 000000000..77c9ac533 --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Networks/Tests/Sources/SocialEntityTests.swift @@ -0,0 +1,36 @@ +// +// SocialEntityTests.swift +// NetworksTests +// +// Created by 장석우 on 12/28/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +import XCTest +@testable import Networks + +final class SocialEntityTests: XCTestCase { + + override func setUp() { + } + + override func tearDown() { + } + + func test_changeSocialEntity의_authPlatform가_enum의_RAW값으로_encode되는가() throws { + + // given + let encoder = JSONEncoder() + let entity = ChangeSocialAccountEntity(phone: "", authPlatform: .apple, code: "") + + // when + let data = try encoder.encode(entity) + let jsonString = String(data: data, encoding: .utf8) + + //then + XCTAssertTrue(jsonString!.contains("\"authPlatform\":\"APPLE\""), "authPlatform 값이 올바르게 인코딩되지 않았습니다.") + + } + + +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Tests/Sources/UnitTest.swift b/SOPT-iOS/Projects/Modules/Networks/Tests/Sources/UnitTest.swift deleted file mode 100644 index 8b1378917..000000000 --- a/SOPT-iOS/Projects/Modules/Networks/Tests/Sources/UnitTest.swift +++ /dev/null @@ -1 +0,0 @@ -