Skip to content

Commit

Permalink
[Network] 서버통신 완료 #51
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Nov 25, 2023
1 parent dba7015 commit c705686
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 16 deletions.
4 changes: 4 additions & 0 deletions SOPKATHON_33-iOS/SOPKATHON_33-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
D26AFFEE2B128915007B90DF /* GelationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFED2B128915007B90DF /* GelationModel.swift */; };
D26AFFF02B1291DC007B90DF /* ProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFEF2B1291DC007B90DF /* ProgressView.swift */; };
D26AFFF22B129A8F007B90DF /* ProgramModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFF12B129A8F007B90DF /* ProgramModel.swift */; };
D26AFFF42B12AA8A007B90DF /* DetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFF32B12AA8A007B90DF /* DetailModel.swift */; };
D28379A12B0FB83A00A1903B /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = D28379A02B0FB83A00A1903B /* SnapKit */; };
D28379A42B0FB84300A1903B /* Then in Frameworks */ = {isa = PBXBuildFile; productRef = D28379A32B0FB84300A1903B /* Then */; };
D28379A72B0FB86500A1903B /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = D28379A62B0FB86500A1903B /* Moya */; };
Expand Down Expand Up @@ -108,6 +109,7 @@
D26AFFED2B128915007B90DF /* GelationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GelationModel.swift; sourceTree = "<group>"; };
D26AFFEF2B1291DC007B90DF /* ProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressView.swift; sourceTree = "<group>"; };
D26AFFF12B129A8F007B90DF /* ProgramModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramModel.swift; sourceTree = "<group>"; };
D26AFFF32B12AA8A007B90DF /* DetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailModel.swift; sourceTree = "<group>"; };
D28379B82B0FBBEA00A1903B /* UIApplication+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+.swift"; sourceTree = "<group>"; };
D28379BA2B0FBBF500A1903B /* UIButton+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+.swift"; sourceTree = "<group>"; };
D28379BC2B0FBC0400A1903B /* UICollectionReuseableView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UICollectionReuseableView+.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -299,6 +301,7 @@
D26AFFDF2B1275B2007B90DF /* MainModel.swift */,
D26AFFED2B128915007B90DF /* GelationModel.swift */,
D26AFFF12B129A8F007B90DF /* ProgramModel.swift */,
D26AFFF32B12AA8A007B90DF /* DetailModel.swift */,
);
path = Main;
sourceTree = "<group>";
Expand Down Expand Up @@ -618,6 +621,7 @@
D206CADC2B0FB748007ECC1B /* ViewController.swift in Sources */,
D28379C72B0FBC4100A1903B /* UIStackView+.swift in Sources */,
A19A1F572B12514E0077ACEC /* ActivityCardView.swift in Sources */,
D26AFFF42B12AA8A007B90DF /* DetailModel.swift in Sources */,
0083D6FE2B1280C30084766E /* Image.swift in Sources */,
D26AFFD42B125470007B90DF /* ProgramViewController.swift in Sources */,
D28379D32B0FBC8900A1903B /* String+.swift in Sources */,
Expand Down
25 changes: 25 additions & 0 deletions SOPKATHON_33-iOS/SOPKATHON_33-iOS/Data/Main/DetailModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// DetailModel.swift
// SOPKATHON_33-iOS
//
// Created by 류희재 on 2023/11/26.
//

struct DetailModel: Codable {
let imageURL, content, organizationName, registerAt: String
let salary: Int?
let hour: Int?
let isApply: Bool
let programType: String

enum CodingKeys: String, CodingKey {
case imageURL = "imageUrl"
case content
case organizationName
case registerAt
case salary
case hour
case isApply
case programType
}
}
17 changes: 9 additions & 8 deletions SOPKATHON_33-iOS/SOPKATHON_33-iOS/Network/MoyaAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ extension MoyaAPI {
completion: completion)
}
}
//
// public func getProgramDetailData(id: Int, completion: @escaping (NetworkResult<Any>) -> Void) {
// provider.request(.getProgramDetailData(id: id)) { (result) in
// self.disposeNetwork(
// result,
// dataModel: [ProgramModel].self,
// completion: completion)
// }

public func getProgramDetailData(id: Int, completion: @escaping (NetworkResult<Any>) -> Void) {
provider.request(.getProgramDetailData(id: id)) { (result) in
self.disposeNetwork(
result,
dataModel: DetailModel.self,
completion: completion)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import UIKit
import SnapKit
import Then

final class DetailViewController: UIViewController {
final class DetailViewController: BaseViewController {

// MARK: - Properties

private var detailData: DetailModel? {
didSet {
self.dataBind()
}
}
var id: Int?

private lazy var backButton = UIButton()
Expand Down Expand Up @@ -42,13 +46,22 @@ final class DetailViewController: UIViewController {
view.backgroundColor = .gray700
setNavigation()
setUI()
requestDetailAPI()
}

@objc func backButtonDidTap() {
print(#function)
self.navigationController?.popViewController(animated: true)
}

func requestDetailAPI() {
guard let id else { return }
MoyaAPI.shared.getProgramDetailData(id: id) { [weak self] result in
guard let result = self?.validateResult(result) as? DetailModel else { return }
self?.detailData = result
}
}

}

// MARK: - Extensions
Expand All @@ -69,8 +82,6 @@ extension DetailViewController {
$0.addTarget(self, action: #selector(backButtonDidTap), for: .touchUpInside)
}



backgroundImageView.do {
$0.image = Image.dummy1
}
Expand Down Expand Up @@ -278,9 +289,37 @@ extension DetailViewController {
self.navigationController?.navigationBar.topItem?.backButtonTitle = ""
}

// func bindData(data: ProgramData) {
// self.titleLabel.text = data.title
// self.bodyLabel.text = data.body
// }
func dataBind() {
guard let data = detailData else { return }
self.agencyValueLabel.text = data.organizationName
self.dateValueLabel.text = data.registerAt
if let salary = data.salary {
self.salaryValueLabel.text = "\(salary)"
}
if let time = data.hour {
self.timeValueLabel.text = "\(time)시간"
}

self.backgroundImageView.kfSetImage(url: data.imageURL)
self.bodyLabel.text = data.content

if data.programType == "VOLUNTEERING" {
[salaryKeyLabel, salaryValueLabel].forEach {
$0.isHidden = true
}

[timeKeyLabel, timeValueLabel].forEach {
$0.isHidden = false
}
} else {
[salaryKeyLabel, salaryValueLabel].forEach {
$0.isHidden = false
}

[timeKeyLabel, timeValueLabel].forEach {
$0.isHidden = true
}
}
}

}

0 comments on commit c705686

Please sign in to comment.