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] 고민 상세보기 뷰 서버 연결 #58

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 16 additions & 4 deletions HARA/HARA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
6713491B296F24190093DDAA /* StorageAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C69C19295AD72F00848B72 /* StorageAPI.swift */; };
673315EF2965C1E500398AA5 /* UnderlineSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 673315EE2965C1E500398AA5 /* UnderlineSegmentedControl.swift */; };
673315F12966D1AC00398AA5 /* StorageVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 673315F02966D1AC00398AA5 /* StorageVC.swift */; };
6779C7F0296F1F3D0026BE10 /* StorageAloneResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6779C7EF296F1F3D0026BE10 /* StorageAloneResponse.swift */; };
6779C7F0296F1F3D0026BE10 /* StorageResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6779C7EF296F1F3D0026BE10 /* StorageResponse.swift */; };
67DA6D22296C9242006F4C5C /* AloneWorriedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D21296C9242006F4C5C /* AloneWorriedVC.swift */; };
67DA6D24296C924C006F4C5C /* TogetherWorriedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D23296C924C006F4C5C /* TogetherWorriedVC.swift */; };
67DA6D26296C9259006F4C5C /* AloneWorriedCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D25296C9259006F4C5C /* AloneWorriedCVC.swift */; };
67DA6D28296C925F006F4C5C /* TogetherWorriedCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D27296C925F006F4C5C /* TogetherWorriedCVC.swift */; };
67DA6D2D296C92B9006F4C5C /* WorriedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D2B296C92B9006F4C5C /* WorriedModel.swift */; };
852B6B3D2971826E00BA2276 /* StorageNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B3C2971826E00BA2276 /* StorageNavigationView.swift */; };
852B6B3F29719CF000BA2276 /* WorryDetailResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B3E29719CF000BA2276 /* WorryDetailResponse.swift */; };
852B6B432971A27200BA2276 /* WorryDetailService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B422971A27200BA2276 /* WorryDetailService.swift */; };
852B6B452971A39E00BA2276 /* WorryDetailAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B442971A39E00BA2276 /* WorryDetailAPI.swift */; };
8532A77A296BE14D00402E91 /* BaseOptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8532A779296BE14D00402E91 /* BaseOptionView.swift */; };
8532A77C296BE15300402E91 /* AddOptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8532A77B296BE15300402E91 /* AddOptionView.swift */; };
8532A77F296BEFEF00402E91 /* AddOptionBtnView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8532A77E296BEFEF00402E91 /* AddOptionBtnView.swift */; };
Expand Down Expand Up @@ -98,13 +101,16 @@
/* Begin PBXFileReference section */
673315EE2965C1E500398AA5 /* UnderlineSegmentedControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnderlineSegmentedControl.swift; sourceTree = "<group>"; };
673315F02966D1AC00398AA5 /* StorageVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageVC.swift; sourceTree = "<group>"; };
6779C7EF296F1F3D0026BE10 /* StorageAloneResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageAloneResponse.swift; sourceTree = "<group>"; };
6779C7EF296F1F3D0026BE10 /* StorageResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageResponse.swift; sourceTree = "<group>"; };
67DA6D21296C9242006F4C5C /* AloneWorriedVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AloneWorriedVC.swift; sourceTree = "<group>"; };
67DA6D23296C924C006F4C5C /* TogetherWorriedVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TogetherWorriedVC.swift; sourceTree = "<group>"; };
67DA6D25296C9259006F4C5C /* AloneWorriedCVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AloneWorriedCVC.swift; sourceTree = "<group>"; };
67DA6D27296C925F006F4C5C /* TogetherWorriedCVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TogetherWorriedCVC.swift; sourceTree = "<group>"; };
67DA6D2B296C92B9006F4C5C /* WorriedModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WorriedModel.swift; sourceTree = "<group>"; };
852B6B3C2971826E00BA2276 /* StorageNavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageNavigationView.swift; sourceTree = "<group>"; };
852B6B3E29719CF000BA2276 /* WorryDetailResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorryDetailResponse.swift; sourceTree = "<group>"; };
852B6B422971A27200BA2276 /* WorryDetailService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorryDetailService.swift; sourceTree = "<group>"; };
852B6B442971A39E00BA2276 /* WorryDetailAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorryDetailAPI.swift; sourceTree = "<group>"; };
8532A779296BE14D00402E91 /* BaseOptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseOptionView.swift; sourceTree = "<group>"; };
8532A77B296BE15300402E91 /* AddOptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOptionView.swift; sourceTree = "<group>"; };
8532A77E296BEFEF00402E91 /* AddOptionBtnView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOptionBtnView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -336,7 +342,8 @@
E7B47C2D296F0E69009987E1 /* Storage */ = {
isa = PBXGroup;
children = (
6779C7EF296F1F3D0026BE10 /* StorageAloneResponse.swift */,
6779C7EF296F1F3D0026BE10 /* StorageResponse.swift */,
852B6B3E29719CF000BA2276 /* WorryDetailResponse.swift */,
);
path = Storage;
sourceTree = "<group>";
Expand Down Expand Up @@ -467,6 +474,7 @@
E7C69C15295AD70F00848B72 /* TogetherAPI.swift */,
E7C69C17295AD71C00848B72 /* WriteAPI.swift */,
E7C69C19295AD72F00848B72 /* StorageAPI.swift */,
852B6B442971A39E00BA2276 /* WorryDetailAPI.swift */,
);
path = APIs;
sourceTree = "<group>";
Expand All @@ -477,6 +485,7 @@
E7C69CDB2965552700848B72 /* TogetherService.swift */,
E7C69CDD296555A600848B72 /* WriteService.swift */,
E7C69CDF296555B400848B72 /* StorageService.swift */,
852B6B422971A27200BA2276 /* WorryDetailService.swift */,
);
path = Services;
sourceTree = "<group>";
Expand Down Expand Up @@ -674,6 +683,7 @@
E7C69C09295AD68100848B72 /* ToastMessageColorType.swift in Sources */,
E7C69CDE296555A600848B72 /* WriteService.swift in Sources */,
E7C69CD2296554D700848B72 /* NetworkConstant.swift in Sources */,
852B6B3F29719CF000BA2276 /* WorryDetailResponse.swift in Sources */,
E7C69CEB29658BF900848B72 /* VoteOptionCVC.swift in Sources */,
E74585CB296DEE5800597168 /* WorryDetailFooterView.swift in Sources */,
8532A77F296BEFEF00402E91 /* AddOptionBtnView.swift in Sources */,
Expand All @@ -697,10 +707,11 @@
85E0A44B29646E300007C3CA /* SecondWriteStepVC.swift in Sources */,
8532A78C296DCE9300402E91 /* OneSecGameVC.swift in Sources */,
E7C69C9D29613F2700848B72 /* UIStackView+.swift in Sources */,
6779C7F0296F1F3D0026BE10 /* StorageAloneResponse.swift in Sources */,
6779C7F0296F1F3D0026BE10 /* StorageResponse.swift in Sources */,
673315EF2965C1E500398AA5 /* UnderlineSegmentedControl.swift in Sources */,
8532A77A296BE14D00402E91 /* BaseOptionView.swift in Sources */,
E74585D5296EA2B500597168 /* FinalChoiceVC.swift in Sources */,
852B6B452971A39E00BA2276 /* WorryDetailAPI.swift in Sources */,
E74585CD296E01E100597168 /* DetailWorryCommentCVC.swift in Sources */,
8532A786296C251200402E91 /* ProsConsCVC.swift in Sources */,
E7C69C9929613A4300848B72 /* UIButton+.swift in Sources */,
Expand All @@ -709,6 +720,7 @@
E74C8751296ABB2300BFAD31 /* DetailWorryCardVC.swift in Sources */,
E7C69CD6296554F800848B72 /* GeneralResponse.swift in Sources */,
E74C8753296C128F00BFAD31 /* DetailWorryCVC.swift in Sources */,
852B6B432971A27200BA2276 /* WorryDetailService.swift in Sources */,
E7C69BE9295AC8A900848B72 /* AppDelegate.swift in Sources */,
85E0A44929646E280007C3CA /* FirstWriteStepVC.swift in Sources */,
E74C874F296A97AF00BFAD31 /* VotedCVC.swift in Sources */,
Expand Down
74 changes: 74 additions & 0 deletions HARA/HARA/Network/APIs/WorryDetailAPI.swift
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)
}
}
}
}
2 changes: 1 addition & 1 deletion HARA/HARA/Network/Base/APIConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct APIConstant {
/// 파라미터 :worryId
static let worryAloneDetail = "/worry/alone"

static let worryWidthDetail = "/worry/with"
static let worryWithDetail = "/worry/with"

//MARK: - Write
static let worryAlone = "/worry/alone"
Expand Down
58 changes: 58 additions & 0 deletions HARA/HARA/Network/DataModel/Storage/WorryDetailResponse.swift
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
}
}



69 changes: 69 additions & 0 deletions HARA/HARA/Network/Services/WorryDetailService.swift
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)"
}
}
Comment on lines +19 to +27
Copy link
Contributor

Choose a reason for hiding this comment

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

왜 param은 Int 형으로 받아와야 하는지 알 수 있을까요? 다른 타입으로는 받아올 수 없는지 이유 궁금합니다~


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

2 changes: 1 addition & 1 deletion HARA/HARA/Sources/Scenes/Together/WorryCardCVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension WorryCardCVC: UICollectionViewDelegate {
// MARK: - Layout
extension WorryCardCVC {
private func setLayout() {
contentView.addSubviews([worryCategoryLabel, worryDateLabel, worryTitleLabel, worryContentLabel,voteOptionCV, voteButton, chatButton])
contentView.addSubviews([worryCategoryLabel, worryDateLabel, worryTitleLabel, worryContentLabel, voteOptionCV, voteButton, chatButton])

worryCategoryLabel.snp.makeConstraints {
$0.leading.equalToSuperview().offset(14)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ final class DetailWorryCardVC: UIViewController {
setLayout()
setPressAction()
setVoteOptionCV()
getWorryAloneList(worryId: 3)
}

override func viewWillLayoutSubviews() {
Expand Down Expand Up @@ -301,3 +302,24 @@ extension DetailWorryCardVC: SendButtonAction {
self.voteOptionCV.reloadData()
}
}

// MARK: - Network
extension DetailWorryCardVC{
func getWorryAloneList(worryId: Int){
WorryDetailAPI.shared.getWorryAloneList(param: worryId){ result in
guard let res = result else {return}
print("값: \(res)")
guard let dataModel = res.data else {return}
print(dataModel)
}
}

func getWorryWithList(worryId: Int){
WorryDetailAPI.shared.getWorryWithList(param: worryId){ result in
guard let res = result else {return}
print("값\(res)")
guard let dataModel = res.data else {return}
print(dataModel)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,15 @@ final class WorryDetailFooterView: UICollectionReusableView {

private func setPressAction() {
voteButton.press {
// self.isOptionSelected = true
// self.isOptionSelected = true
self.voteButton.backgroundColor = .hOrange3
self.voteButton.layer.borderWidth = 0
self.voteButton.setTitle("투표완료!", for: .normal)
self.voteButton.setTitleColor(.hWhite, for: .normal)
self.voteButton.setBackgroundColor(.hGray3, for: .normal)
self.voteButton.isUserInteractionEnabled = false
// self.voteOptionCV.reloadData()
// self.voteOptionCV.reloadData()
self.buttonDelegate?.sendData(isSelected: true)
}



}



}