-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/TeamBeMe/BeMeiOS into fe…
…ature/#107
- Loading branch information
Showing
68 changed files
with
1,632 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
BeMe/BeMe/APIService/Following/FollowingNewAnswerService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// LogInService.swift | ||
// BeMe | ||
// | ||
// Created by Yunjae Kim on 2021/01/06. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
struct FollowingNewAnswerService{ | ||
static let shared = FollowingNewAnswerService() | ||
|
||
func getNewData(questionID: Int, completion : @escaping (NetworkResult<Any>) -> (Void) ){ | ||
let url = APIConstants.followingNewAnswerURL | ||
|
||
let header : HTTPHeaders = [ | ||
"Content-Type":"application/json", | ||
"token":UserDefaults.standard.string(forKey: "token")! | ||
] | ||
|
||
let body : Parameters = [ | ||
"question_id": questionID | ||
] | ||
|
||
let dataRequest = AF.request(url, | ||
method: .post, | ||
parameters: body, | ||
encoding: JSONEncoding.default, | ||
headers: header) | ||
|
||
|
||
dataRequest.responseData{ response in | ||
switch response.result { | ||
case .success: | ||
guard let statusCode = response.response?.statusCode else{ | ||
return | ||
} | ||
guard let data = response.value else{ | ||
return | ||
|
||
} | ||
|
||
completion(judge(status: statusCode, data: data)) | ||
|
||
|
||
|
||
|
||
|
||
case .failure(let err): | ||
print(err) | ||
completion(.networkFail) | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
private func judge(status : Int, data : Data) -> NetworkResult<Any> { | ||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GenericResponse<FollowingNewAnswerData>.self, from : data) else{ | ||
|
||
|
||
return .pathErr | ||
|
||
} | ||
|
||
switch status{ | ||
case 200..<300: | ||
|
||
print("성공성공") | ||
|
||
return .success(decodedData.data) | ||
case 400..<500 : | ||
return .requestErr(decodedData.message) | ||
case 500 : | ||
return .serverErr | ||
|
||
default : | ||
return .networkFail | ||
|
||
|
||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.