Skip to content

Commit

Permalink
[Network] 서버 통신 구현 완료 #37
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Nov 25, 2023
1 parent 3c3cbf9 commit 1fc201f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 24 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 @@ -31,6 +31,7 @@
D26AFFE82B127673007B90DF /* MoyaService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFE72B127673007B90DF /* MoyaService.swift */; };
D26AFFEA2B12767B007B90DF /* MoyaAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFE92B12767B007B90DF /* MoyaAPI.swift */; };
D26AFFEC2B127B0F007B90DF /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFEB2B127B0F007B90DF /* BaseViewController.swift */; };
D26AFFEE2B128915007B90DF /* GelationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFED2B128915007B90DF /* GelationModel.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 @@ -101,6 +102,7 @@
D26AFFE72B127673007B90DF /* MoyaService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaService.swift; sourceTree = "<group>"; };
D26AFFE92B12767B007B90DF /* MoyaAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaAPI.swift; sourceTree = "<group>"; };
D26AFFEB2B127B0F007B90DF /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
D26AFFED2B128915007B90DF /* GelationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GelationModel.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 @@ -288,6 +290,7 @@
isa = PBXGroup;
children = (
D26AFFDF2B1275B2007B90DF /* MainModel.swift */,
D26AFFED2B128915007B90DF /* GelationModel.swift */,
);
path = Main;
sourceTree = "<group>";
Expand Down Expand Up @@ -589,6 +592,7 @@
E5CD4BF72B12637800CF9D17 /* CustomNavigationBarView.swift in Sources */,
D28379D52B0FBDB300A1903B /* APIConstant.swift in Sources */,
D28379DD2B0FBE9C00A1903B /* BaseAPI.swift in Sources */,
D26AFFEE2B128915007B90DF /* GelationModel.swift in Sources */,
D28379BF2B0FBC0F00A1903B /* UICollectionViewCell++.swift in Sources */,
D28379D12B0FBC7600A1903B /* UIViewController+.swift in Sources */,
D28379CD2B0FBC5F00A1903B /* UITextField+.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
self.window = UIWindow(windowScene: windowScene)
window?.overrideUserInterfaceStyle = .light

let mainViewController = TabBarController()
let mainViewController = GelationDetailView()
let navigationController = UINavigationController(rootViewController: mainViewController)

navigationController.isNavigationBarHidden = true
Expand Down
12 changes: 12 additions & 0 deletions SOPKATHON_33-iOS/SOPKATHON_33-iOS/Data/Main/GelationModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// GelationModel.swift
// SOPKATHON_33-iOS
//
// Created by 류희재 on 2023/11/26.
//

import Foundation

struct GelationModel: Codable {
let volunteers, programs, certifications: [String]
}
9 changes: 9 additions & 0 deletions SOPKATHON_33-iOS/SOPKATHON_33-iOS/Network/MoyaAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ extension MoyaAPI {
completion: completion)
}
}

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

7 changes: 7 additions & 0 deletions SOPKATHON_33-iOS/SOPKATHON_33-iOS/Network/MoyaService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ import UIKit

enum MoyaService {
case getMainData
case getGelationData
}

extension MoyaService: BaseTargetType {
var path: String {
switch self {
case .getMainData:
return "/api/v1/user/info/\(1)"
case .getGelationData:
return "/api/v1/user/info/detail/\(1)"
}
}

var method: Moya.Method {
switch self {
case .getMainData:
return .get
case .getGelationData:
return .get
}
}

Expand All @@ -34,6 +39,8 @@ extension MoyaService: BaseTargetType {
switch self {
case .getMainData:
return .requestPlain
case .getGelationData:
return .requestPlain
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ class GelationCollectionViewCell: UICollectionViewCell {
fatalError("init(coder:) has not been implemented")
}

func bindData(data: GelationData) {
self.backgroundImage = data.backgroundImage
self.cardTitle.text = data.cardTitle
self.list1.text = data.list1
self.list2.text = data.list2
self.list3.text = data.list3
self.list4.text = data.list4
func bindData(title: String, data: [String]) {
self.cardTitle.text = title
self.list1.text = data[0]
self.list2.text = data[1]
self.list3.text = data[2]
self.list4.text = data[3]
}


Expand Down Expand Up @@ -86,7 +85,7 @@ class GelationCollectionViewCell: UICollectionViewCell {

cardTitle.do {
$0.font = UIFont(name: "Pretendard-SemiBold", size: 14.adjusted)
$0.textColor = .white
$0.textColor = .black
$0.numberOfLines = 0
}

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

final class GelationDetailView: UIViewController {
final class GelationDetailView: BaseViewController {

let customGelationNavigationView = CustomGelationNavigationView()
var gelationData: GelationModel? = nil

override func viewDidLoad() {
super.viewDidLoad()
setStyle()
setLayout()
setCollectionView()
setCollectionViewLayout()
requestGelationAPI()
}

private func setStyle() {
Expand All @@ -37,38 +39,57 @@ final class GelationDetailView: UIViewController {
collectionView.snp.makeConstraints{
$0.bottom.leading.trailing.equalToSuperview()
$0.top.equalTo(customGelationNavigationView.snp.bottom)
}
}

}

private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()).then {
$0.backgroundColor = .black
}
$0.backgroundColor = .black
}

private func setCollectionView() {
self.collectionView.register(GelationCollectionViewCell.self,
forCellWithReuseIdentifier: GelationCollectionViewCell.identifier)
self.collectionView.dataSource = self
}
self.collectionView.register(GelationCollectionViewCell.self,
forCellWithReuseIdentifier: GelationCollectionViewCell.identifier)

self.collectionView.dataSource = self
}

private func setCollectionViewLayout() {
let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSize(width: 335, height: 205)
flowLayout.minimumLineSpacing = 15
self.collectionView.setCollectionViewLayout(flowLayout, animated: false)
let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSize(width: 335, height: 205)
flowLayout.minimumLineSpacing = 15
self.collectionView.setCollectionViewLayout(flowLayout, animated: false)
}

private func requestGelationAPI() {
MoyaAPI.shared.getGelationData { [weak self] result in
guard let result = self?.validateResult(result) as? GelationModel else { return }
self?.gelationData = result
self?.collectionView.reloadData()
}
}
}

extension GelationDetailView: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return gelationData.count
return 3
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let item = collectionView.dequeueReusableCell(withReuseIdentifier: GelationCollectionViewCell.identifier,for: indexPath) as? GelationCollectionViewCell
else {return UICollectionViewCell()}
item.bindData(data: gelationData[indexPath.row])
if !(gelationData?.volunteers.isEmpty ?? true) {
switch indexPath.item {
case 0:
item.bindData(title: "봉사 내역", data: gelationData!.volunteers)
case 1:
item.bindData(title: "이수 프로그램 내역",data: gelationData!.programs)
case 2:
item.bindData(title: "자격증 목록",data: gelationData!.certifications)
default:
break
}
}
return item
}
}

0 comments on commit 1fc201f

Please sign in to comment.