Skip to content

Commit

Permalink
Merge pull request #41 from SOPT-33-iOS-Team-1/Network/#37
Browse files Browse the repository at this point in the history
Network/#37
  • Loading branch information
HELLOHIDI authored Nov 25, 2023
2 parents 4876042 + 078900c commit 523fb6e
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 34 deletions.
8 changes: 8 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,8 @@
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 */; };
D26AFFF02B1291DC007B90DF /* ProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26AFFEF2B1291DC007B90DF /* ProgressView.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 +103,8 @@
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>"; };
D26AFFEF2B1291DC007B90DF /* ProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressView.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 @@ -206,6 +210,7 @@
A19A1F5A2B1255CF0077ACEC /* ActivityStackView.swift */,
A19A1F5C2B1258490077ACEC /* ActivityStackViewItem.swift */,
A13161442B12749800883CB2 /* UserInfoChipView.swift */,
D26AFFEF2B1291DC007B90DF /* ProgressView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -288,6 +293,7 @@
isa = PBXGroup;
children = (
D26AFFDF2B1275B2007B90DF /* MainModel.swift */,
D26AFFED2B128915007B90DF /* GelationModel.swift */,
);
path = Main;
sourceTree = "<group>";
Expand Down Expand Up @@ -589,8 +595,10 @@
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 */,
D26AFFF02B1291DC007B90DF /* ProgressView.swift in Sources */,
D28379CD2B0FBC5F00A1903B /* UITextField+.swift in Sources */,
D206CADC2B0FB748007ECC1B /* ViewController.swift in Sources */,
D28379C72B0FBC4100A1903B /* UIStackView+.swift in Sources */,
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 @@ -34,12 +34,12 @@ class GelationCollectionViewCell: UICollectionViewCell {
fatalError("init(coder:) has not been implemented")
}

func bindData(data: GelationData) {
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 @@ -87,7 +87,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()
}

@objc func handleListTap() {
Expand Down Expand Up @@ -48,7 +50,7 @@ final class GelationDetailView: UIViewController {
collectionView.snp.makeConstraints{
$0.bottom.leading.trailing.equalToSuperview()
$0.top.equalTo(customGelationNavigationView.snp.bottom)
}
}

}

Expand All @@ -60,34 +62,53 @@ final class GelationDetailView: UIViewController {
}()

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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ final class MainViewController: BaseViewController {
self.setHierachy()
self.setLayout()
requestMainData()
activityCardView.progressView1.progressAnimation(duration: 1, value: 0.9)
activityCardView.progressView2.progressAnimation(duration: 1, value: 0.5)
activityCardView.progressView3.progressAnimation(duration: 1, value: 0.6)

}

private func setHierachy() {
Expand All @@ -47,6 +51,15 @@ final class MainViewController: BaseViewController {
MoyaAPI.shared.getMainData { [weak self] result in
guard let result = self?.validateResult(result) as? MainModel else { return }
self?.mainData = result
self?.dataBind()
}
}

private func dataBind() {
DispatchQueue.main.async {
self.idCardView.dataBind(self.mainData)
self.activityCardView.activityStackView.dataBind(self.mainData)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
//

import UIKit
import SnapKit

final class ActivityCardView: UIView {

//MARK: - set Properties

private let ringImageView = UIImageView()
private let activityStackView = ActivityStackView()
let progressView1 = ProgressView(frame: .init(origin: .zero, size: .init(width: 187,height: 187)))

let progressView2 = ProgressView(frame: .init(origin: .zero, size: .init(width: 145,height: 145)))

let progressView3 = ProgressView(frame: .init(origin: .zero, size: .init(width: 105,height: 105)))

let activityStackView = ActivityStackView()
private let divisionLine = UIView()
private let showDetailButton = UIButton()

Expand All @@ -24,6 +30,9 @@ final class ActivityCardView: UIView {
self.setUI()
self.setHierachy()
self.setLayout()
progressView1.ringColor = .blue1
progressView2.ringColor = .blue2
progressView3.ringColor = .blue3
}

@available(*, unavailable)
Expand All @@ -39,9 +48,6 @@ final class ActivityCardView: UIView {
$0.layer.cornerRadius = 8
}

ringImageView.do {
$0.image = UIImage(named: "ring")
}

divisionLine.do {
$0.setBorder(borderWidth: 1, borderColor: UIColor(red: 0.914, green: 0.922, blue: 0.929, alpha: 1))
Expand All @@ -57,7 +63,9 @@ final class ActivityCardView: UIView {
//MARK: - set Hierachy

private func setHierachy() {
self.addSubviews(ringImageView,
self.addSubviews(progressView1,
progressView2,
progressView3,
activityStackView,
divisionLine,
showDetailButton)
Expand All @@ -71,9 +79,21 @@ final class ActivityCardView: UIView {
$0.height.equalTo(405.adjusted)
}

ringImageView.snp.makeConstraints {
$0.top.equalToSuperview().inset(34.adjusted)
$0.centerX.equalToSuperview()
progressView1.snp.makeConstraints {
$0.top.equalToSuperview().offset(34)
$0.leading.equalToSuperview().offset(74)
$0.width.height.equalTo(187)
}
progressView2.snp.makeConstraints {
$0.top.equalTo(progressView1).offset(21)
$0.leading.equalToSuperview().offset(95)
$0.width.height.equalTo(145)
}

progressView3.snp.makeConstraints {
$0.top.equalTo(progressView2).offset(21)
$0.leading.equalToSuperview().offset(115)
$0.width.height.equalTo(105)
}

activityStackView.snp.makeConstraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ final class ActivityStackView: UIStackView {
private func setUI() {
volunteerHourItem.do {
$0.titleLabel.text = "봉사시간"
$0.valueLabel.text = "5시간"
$0.valueLabel.text = ""
}
programCompletionNumberItem.do {
$0.titleLabel.text = "프로그램 이수"
$0.valueLabel.text = "3개"
$0.valueLabel.text = ""
}
licenseNumberItem.do {
$0.titleLabel.text = "자격증"
$0.valueLabel.text = "2개"
$0.valueLabel.text = ""
}
}

Expand All @@ -51,4 +51,11 @@ final class ActivityStackView: UIStackView {
self.axis = .vertical
self.spacing = 17.adjusted
}

func dataBind(_ data: MainModel?) {
guard let data else { return }
volunteerHourItem.valueLabel.text = "\(data.volunteerHours)시간"
programCompletionNumberItem.valueLabel.text = "\(data.completedProgramCount)"
licenseNumberItem.valueLabel.text = "\(data.certificateCount)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,13 @@ final class IdCardView: UIView {
$0.leading.equalToSuperview().inset(289.adjusted)
}
}

func dataBind(_ data: MainModel?) {
guard let data else { return }
userName.text = data.name
ageChipView.infoLabel.text = "\(data.age)"
genderChipView.infoLabel.text = data.gender
userCrimeHistory.text = data.criminalHistory
userCrimeYearAgo.text = data.criminalHistoryDate
}
}
Loading

0 comments on commit 523fb6e

Please sign in to comment.