-
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.
Browse files
Browse the repository at this point in the history
Feature/#137
- Loading branch information
Showing
21 changed files
with
479 additions
and
101 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
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,71 @@ | ||
// | ||
// ReportService.swift | ||
// Mongle | ||
// | ||
// Created by 이주혁 on 2020/11/14. | ||
// Copyright © 2020 이주혁. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
struct ReportService { | ||
static let shared = ReportService() | ||
|
||
func report(type: String, idx: Int, content: String, completion: @escaping (NetworkResult<Any>) -> ()) { | ||
|
||
let token: String = UserDefaults.standard.string(forKey: UserDefaultKeys.token.rawValue) ?? "guest" | ||
|
||
let header: HTTPHeaders = [ | ||
"Content-Type":"application/json", | ||
"token":token | ||
] | ||
|
||
let parameter: Parameters = [ | ||
"sort": type, | ||
"idx": idx, | ||
"content" : content | ||
] | ||
|
||
let url = APIConstants.detailReportURL | ||
|
||
Alamofire.request(url, | ||
method: .post, | ||
parameters: parameter, | ||
encoding: JSONEncoding.default, | ||
headers: header).responseData { response in | ||
switch response.result { | ||
case .success: | ||
guard let statusCode = response.response?.statusCode else { | ||
return | ||
} | ||
guard let data = response.value else { | ||
return | ||
} | ||
completion(self.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<String>.self, from: data) else { | ||
return .pathErr | ||
} | ||
switch status { | ||
case 200: | ||
return .success(decodedData.data) | ||
case 400..<500: | ||
return .requestErr(decodedData.message) | ||
case 600: | ||
return .serverErr | ||
default: | ||
return .networkFail | ||
} | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
Mongle/Mongle/Resource/APIService/SentenceEditService.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,124 @@ | ||
// | ||
// SentenceEditService.swift | ||
// Mongle | ||
// | ||
// Created by 이주혁 on 2020/11/15. | ||
// Copyright © 2020 이주혁. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
struct SentenceEditService { | ||
static let shared = SentenceEditService() | ||
|
||
func editSentence(idx: Int, sentence: String, completion: @escaping (NetworkResult<Any>) -> ()) { | ||
let token: String = UserDefaults.standard.string(forKey: UserDefaultKeys.token.rawValue) ?? "guest" | ||
|
||
let header: HTTPHeaders = [ | ||
"Content-Type":"application/json", | ||
"token":token | ||
] | ||
|
||
let body: Parameters = [ | ||
"sentence" : sentence | ||
] | ||
|
||
let url = APIConstants.myURL + "/\(idx)" | ||
|
||
Alamofire.request(url, | ||
method: .put, | ||
parameters: body, | ||
encoding: JSONEncoding.default, | ||
headers: header).responseData { response in | ||
switch response.result { | ||
case .success: | ||
guard let statusCode = response.response?.statusCode else { | ||
return | ||
} | ||
guard let data = response.value else { | ||
return | ||
} | ||
completion(self.judgeSenteceEdit(status: statusCode, data: data)) | ||
case .failure(let err): | ||
print(err) | ||
completion(.networkFail) | ||
} | ||
} | ||
} | ||
|
||
private func judgeSenteceEdit(status: Int, data: Data) -> NetworkResult<Any> { | ||
|
||
struct EditSentence: Codable { | ||
var sentence: String | ||
} | ||
|
||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GenericResponse<EditSentence>.self, from: data) else { | ||
return .pathErr | ||
} | ||
switch status { | ||
case 200: | ||
return .success(decodedData.data?.sentence) | ||
case 400..<500: | ||
return .requestErr(decodedData.message) | ||
case 600: | ||
return .serverErr | ||
default: | ||
return .networkFail | ||
} | ||
} | ||
|
||
func deleteSentece(idx: Int, completion: @escaping (NetworkResult<Any>) ->()) { | ||
let token: String = UserDefaults.standard.string(forKey: UserDefaultKeys.token.rawValue) ?? "guest" | ||
|
||
let header: HTTPHeaders = [ | ||
"Content-Type":"application/json", | ||
"token":token | ||
] | ||
|
||
let url = APIConstants.myURL + "/\(idx)" | ||
|
||
Alamofire.request(url, | ||
method: .delete, | ||
parameters: nil, | ||
encoding: JSONEncoding.default, | ||
headers: header).responseData { response in | ||
switch response.result { | ||
case .success: | ||
guard let statusCode = response.response?.statusCode else { | ||
return | ||
} | ||
guard let data = response.value else { | ||
return | ||
} | ||
completion(self.judgeSenteceDelete(status: statusCode, data: data)) | ||
case .failure(let err): | ||
print(err) | ||
completion(.networkFail) | ||
} | ||
} | ||
} | ||
|
||
private func judgeSenteceDelete(status: Int, data: Data) -> NetworkResult<Any> { | ||
|
||
struct DeleteSentence: Codable { | ||
var deleteSentenceIdx: String | ||
} | ||
|
||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GenericResponse<DeleteSentence>.self, from: data) else { | ||
return .pathErr | ||
} | ||
switch status { | ||
case 200: | ||
return .success(decodedData.data?.deleteSentenceIdx) | ||
case 400..<500: | ||
return .requestErr(decodedData.message) | ||
case 600: | ||
return .serverErr | ||
default: | ||
return .networkFail | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Mongle/Mongle/Resource/Assets.xcassets/themeInfoBtnMore.imageset/Contents.json
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,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"scale" : "1x", | ||
"idiom" : "universal", | ||
"filename" : "themeInfoBtnMore.png" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"scale" : "3x", | ||
"idiom" : "universal", | ||
"filename" : "[email protected]" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+205 Bytes
.../Mongle/Resource/Assets.xcassets/themeInfoBtnMore.imageset/themeInfoBtnMore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+273 Bytes
...ngle/Resource/Assets.xcassets/themeInfoBtnMore.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+345 Bytes
...ngle/Resource/Assets.xcassets/themeInfoBtnMore.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.