-
Notifications
You must be signed in to change notification settings - Fork 0
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] 고민 상세보기 뷰 서버 연결 #58
Open
oy6uns
wants to merge
2
commits into
develop
Choose a base branch
from
Feat/#57-worryDetail-Server
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// WorryDetailAPI.swift | ||
// HARA | ||
// | ||
// Created by saint on 2023/01/13. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
final class WorryDetailAPI { | ||
|
||
static let shared: WorryDetailAPI = WorryDetailAPI() | ||
private let worryDetailProvider = MoyaProvider<WorryDetailService>(plugins: [MoyaLoggingPlugin()]) | ||
private init() { } | ||
|
||
public private(set) var worryAloneDetailResponse: GeneralArrayResponse<WorryAloneDetailResponse>? | ||
|
||
public private(set) var worryWithDetailResponse: GeneralArrayResponse<WorryWithDetailResponse>? | ||
|
||
// MARK: - WorryAlone | ||
func getWorryAloneList(param: Int, completion: @escaping ((GeneralArrayResponse<WorryAloneDetailResponse>?) -> ())) { | ||
worryDetailProvider.request(.alone(param: param)) { [weak self] response in | ||
switch response { | ||
case .success(let result): | ||
do { | ||
self?.worryAloneDetailResponse = try | ||
result.map(GeneralArrayResponse<WorryAloneDetailResponse>?.self) | ||
print("성공") | ||
print(result) | ||
guard let aloneData = self?.worryAloneDetailResponse else { print("빠짐") | ||
return | ||
} | ||
print(aloneData) | ||
completion(aloneData) | ||
} catch(let err) { | ||
print("데이터 실패") | ||
print(err.localizedDescription) | ||
completion(nil) | ||
} | ||
case .failure(let err): | ||
print("실패") | ||
print(err.localizedDescription) | ||
completion(nil) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - StorageWith | ||
func getWorryWithList(param: Int, completion: @escaping ((GeneralArrayResponse<WorryWithDetailResponse>?) -> ())) { | ||
worryDetailProvider.request(.with(param: param)) { [weak self] response in | ||
switch response { | ||
case .success(let result): | ||
do { | ||
self?.worryWithDetailResponse = try result.map(GeneralArrayResponse<WorryWithDetailResponse>?.self) | ||
print("성공") | ||
guard let withData = self?.worryWithDetailResponse else {print("2") | ||
return | ||
} | ||
print(withData) | ||
completion(withData) | ||
} catch(let err) { | ||
print("데이터 실패") | ||
print(err.localizedDescription) | ||
completion(nil) | ||
} | ||
case .failure(let err): | ||
print("실패") | ||
print(err.localizedDescription) | ||
completion(nil) | ||
} | ||
} | ||
} | ||
} |
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
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
HARA/HARA/Network/DataModel/Storage/WorryDetailResponse.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,58 @@ | ||
// | ||
// AloneWorryDetailResponse.swift | ||
// HARA | ||
// | ||
// Created by saint on 2023/01/13. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - WorryAloneDetailResponse | ||
struct WorryAloneDetailResponse: Codable { | ||
var finalOption: Int? | ||
var createdAt, worryTitle, worryContent: String | ||
var category: String | ||
var options: Option | ||
|
||
// MARK: - Option | ||
struct Option: Codable { | ||
var id, worryAloneId: Int | ||
var title: String | ||
var advantage, disadvantage: String? | ||
var image: String? | ||
var hasImage: Bool | ||
} | ||
} | ||
|
||
// MARK: - WorryWithDetailResponse | ||
struct WorryWithDetailResponse: Codable { | ||
var isAuthor: Bool | ||
var finalOption: Int? | ||
var isVoted: Bool | ||
var selectedOptionId: Int? | ||
var createdAt, worryTitle, worryContent, category: String | ||
var options: [Option] | ||
var commentCount: Int | ||
var comments: [Comment]? | ||
|
||
// MARK: - Option | ||
struct Option: Codable { | ||
var id, worryWithId: Int | ||
var title: String | ||
var advantage, disadvantage: String? | ||
var image: String? | ||
var hasImage: Bool | ||
var percentage: Int? | ||
} | ||
|
||
// MARK: - Comment | ||
struct Comment: Codable { | ||
var userNickName: String | ||
var userImage: String | ||
var content: String | ||
var createdAt: String | ||
} | ||
} | ||
|
||
|
||
|
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,69 @@ | ||
// | ||
// WorryDetailService.swift | ||
// HARA | ||
// | ||
// Created by saint on 2023/01/13. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
enum WorryDetailService { | ||
case alone(param: Int) | ||
case with(param: Int) | ||
} | ||
|
||
extension WorryDetailService: BaseTargetType { | ||
|
||
var path: String { | ||
switch self { | ||
case .alone(let param): | ||
return APIConstant.worryAloneDetail + "/\(param)" | ||
/// param은 int형으로 받아온다. | ||
|
||
case .with(let param): | ||
return APIConstant.worryWithDetail + "/\(param)" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .alone: | ||
return .get | ||
|
||
case .with: | ||
return .get | ||
} | ||
} | ||
|
||
// var parameters: [String: Any]? { | ||
// switch self { | ||
// case .alone(let param): | ||
// return ["worryId": param] | ||
// | ||
// case .with(let param): | ||
// return ["worryId": param] | ||
// } | ||
// } | ||
|
||
var task: Task { | ||
switch self { | ||
case .alone: | ||
return .requestPlain | ||
|
||
case .with: | ||
return .requestPlain | ||
} | ||
} | ||
|
||
var headers: [String : String]? { | ||
switch self { | ||
case .alone: | ||
return NetworkConstant.noTokenHeader | ||
|
||
case .with: | ||
return NetworkConstant.noTokenHeader | ||
} | ||
} | ||
} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왜 param은 Int 형으로 받아와야 하는지 알 수 있을까요? 다른 타입으로는 받아올 수 없는지 이유 궁금합니다~