Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #466 -회원가입 API 연동 #469

Merged
merged 8 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions SOPT-iOS/Projects/Modules/Networks/Sources/API/CoreAuthAPI.swift
Original file line number Diff line number Diff line change
@@ -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
}
}


62 changes: 62 additions & 0 deletions SOPT-iOS/Projects/Modules/Networks/Sources/API/SocialAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// 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(entity: ChangeSocialAccountEntity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoreAuthAPI에는 dto로 명명되어 있던데 명칭 통일하시는 거 어떠실지요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity 와 dto중에 무엇으로 통일할까요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어느 쪽이든 상관 없을 것 같아용

}

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)
}
}

public var validationType: ValidationType {
return .none
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 없어도 validationType 기본값은 .none 아닌가용?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지울게욥!

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// 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
}

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공백 한 개만 지워주세용. . ㅎ.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네네!


public extension ChangeSocialAccountEntity {
static let stub: ChangeSocialAccountEntity = .init(phone: "01011111111", authPlatform: .apple, code: "code")
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public enum APIType {
case poke
case s3
case fortune
case coreAuth
case social
}

public protocol BaseAPI: TargetType {
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오옹 baseURL이 다른가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네네 맞아용
새로운 서버를 만든거라 baseURL이 달라졌습니다


switch Self.apiType {
case .attendance:
base = operationBaseURL
Expand Down Expand Up @@ -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 {
Expand Down
Loading