Skip to content

Commit

Permalink
[Fix] #243 - confilict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Mar 20, 2024
2 parents d12321c + 90d1412 commit 56058c0
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 292 deletions.
78 changes: 40 additions & 38 deletions iOS-NOTTODO/iOS-NOTTODO.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

81 changes: 0 additions & 81 deletions iOS-NOTTODO/iOS-NOTTODO/Network/API/Auth/AuthAPI.swift

This file was deleted.

78 changes: 78 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Network/API/AuthAPI/AuthAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// AuthAPI.swift
// iOS-NOTTODO
//
// Created by 김민서 on 2023/05/21.
//

import Foundation

import Moya

struct AuthRequest: Codable {
let socialToken: String
let fcmToken: String
var name: String?
}

enum AuthAPI {
case kakaoAuth(social: LoginType, request: AuthRequest)
case appleAuth(social: LoginType, request: AuthRequest)
case logout
case withdrawal
}

extension AuthAPI: BaseAPI {
var domain: BaseDomain {
return .auth
}

var urlPath: String {
switch self {
case .kakaoAuth(let social, _), .appleAuth(let social, _):
return URLConstant.auth + "/\(social.rawValue)"
case .logout:
return URLConstant.authLogout
case .withdrawal:
return URLConstant.authWithdrawal
}
}

var headerType: HeaderType {

switch self {
case .kakaoAuth, .appleAuth:
return .json
case .logout, .withdrawal:
return .jsonWithToken
}
}

var method: Moya.Method {
switch self {
case .kakaoAuth, .appleAuth:
return .post
case .logout, .withdrawal:
return .delete
}
}

var task: Moya.Task {
switch self {
case .kakaoAuth(_, let data):
return .requestJSONEncodable(data)
case .appleAuth(_, let data):
return .requestJSONEncodable(data)
case .logout, .withdrawal:
return .requestPlain
}
}
}

extension Encodable {
var toDictionary: [String: Any] {
guard let object = try? JSONEncoder().encode(self) else { fatalError() }
guard let dictionary = try? JSONSerialization.jsonObject(with: object, options: []) as? [String: Any] else { fatalError() }
return dictionary
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MissionService.swift
// MissionAPI.swift
// iOS-NOTTODO
//
// Created by 강윤서 on 2023/06/07.
Expand All @@ -25,7 +25,7 @@ struct UpdateMissionRequest: Codable {
let goal: String?
}

enum MissionService {
enum MissionAPI {
case addMission(request: AddMissionRequest)
case updateMission(request: UpdateMissionRequest)
case recentMission
Expand All @@ -39,7 +39,7 @@ enum MissionService {
case achieveCalendar(month: String)
}

extension MissionService: BaseService {
extension MissionAPI: BaseAPI {
var domain: BaseDomain {
return .mission
}
Expand Down
88 changes: 27 additions & 61 deletions iOS-NOTTODO/iOS-NOTTODO/Network/API/Recommend/RecommendAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,41 @@ import Foundation

import Moya

typealias RecommendData = GeneralArrayResponse<RecommendResponseDTO>
typealias ActionData = GeneralResponse<RecommendActionResponseDTO>
typealias SituationData = GeneralArrayResponse<RecommendSituationResponseDTO>

protocol RecommendAPIType {
func getRecommend(completion: @escaping (RecommendData?) -> Void)
func getRecommendAction(index: Int, completion: @escaping (ActionData?) -> Void)
func getRecommendSituation(completion: @escaping (SituationData?) -> Void)
enum RecommendAPI {
case recommend
case action(id: Int)
case situdation
}

final class RecommendAPI: RecommendAPIType {

static let shared: RecommendAPI = RecommendAPI()
extension RecommendAPI: BaseAPI {
var domain: BaseDomain {
return .recommend
}

private let provider = MoyaProvider<RecommendService>(session: Session(interceptor: AuthInterceptor.shared), plugins: [MoyaLoggingPlugin()])
var urlPath: String {
switch self {
case .recommend:
return URLConstant.recommend
case .action(id: let id):
return URLConstant.recommendAction + "/\(id)" + "/action"
case .situdation:
return URLConstant.recommendSituation
}
}

private init() {}

// MARK: - GET
var headerType: HeaderType {
return .jsonWithToken
}

func getRecommend(completion: @escaping (RecommendData?) -> Void) {
provider.request(.recommend) { result in
switch result {
case .success(let response):
do {
let response = try response.map(RecommendData?.self)
completion(response)
} catch let err {
print(err.localizedDescription, 500)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil)
}
}
var method: Moya.Method {
return .get
}

func getRecommendAction(index: Int, completion: @escaping (GeneralResponse<RecommendActionResponseDTO>?) -> Void) {
provider.request(.action(id: index)) { result in
switch result {
case .success(let response):
do {
let reponse = try response.map(ActionData?.self)
completion(reponse)
} catch let err {
print(err.localizedDescription, 500)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil)
}
}
var validationType: ValidationType {
return .successCodes
}

func getRecommendSituation(completion: @escaping (SituationData?) -> Void) {
provider.request(.situdation) { result in
switch result {
case .success(let response):
do {
let response = try
response.map(SituationData?.self)
completion(response)
} catch let err {
print(err.localizedDescription, 500)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil)
}
}
var task: Moya.Task {
.requestPlain
}
}
Loading

0 comments on commit 56058c0

Please sign in to comment.