diff --git a/NotToDo/NotToDo.xcodeproj/project.pbxproj b/NotToDo/NotToDo.xcodeproj/project.pbxproj index d36eabe..1c937fd 100644 --- a/NotToDo/NotToDo.xcodeproj/project.pbxproj +++ b/NotToDo/NotToDo.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 090D3DDB297139B1000F468C /* CalendarCustomCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 090D3DDA297139B1000F468C /* CalendarCustomCell.swift */; }; 090FA2E7295F51BB00918AED /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 090FA2E6295F51BB00918AED /* GoogleService-Info.plist */; }; 090FA2F52960B70400918AED /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 090FA2F42960B70400918AED /* SnapKit */; }; 090FA2F82960B74000918AED /* Then in Frameworks */ = {isa = PBXBuildFile; productRef = 090FA2F72960B74000918AED /* Then */; }; @@ -148,7 +147,6 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 090D3DDA297139B1000F468C /* CalendarCustomCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarCustomCell.swift; sourceTree = ""; }; 090FA2E6295F51BB00918AED /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; 0951EE8C297130DF004A3B5B /* AchieveCalendarResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AchieveCalendarResponseDTO.swift; sourceTree = ""; }; 09611EE6296FD52700561CAA /* RecommendService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendService.swift; sourceTree = ""; }; @@ -350,7 +348,6 @@ 09F695DC296C52F000877EA7 /* SituationTableViewCell.swift */, 099F0727296B94790036CF55 /* StatisticsEmptyTableViewCell.swift */, 09F695DA296C52B600877EA7 /* MissionTableViewCell.swift */, - 090D3DDA297139B1000F468C /* CalendarCustomCell.swift */, ); path = Cells; sourceTree = ""; @@ -1265,7 +1262,6 @@ 3BE0700E296F43B6002CC50A /* Strings.swift in Sources */, 099F06FA2967EE9F0036CF55 /* LabelCollectionViewCell.swift in Sources */, 3BBE56F3296C4EB000771DE4 /* SecondOnboardingViewController.swift in Sources */, - 090D3DDB297139B1000F468C /* CalendarCustomCell.swift in Sources */, 096BDFD92964FEF6009ED396 /* CustomCalendarView.swift in Sources */, 099F072A296B98B90036CF55 /* SituationTitleView.swift in Sources */, 3B2748632970B570005DBD46 /* AddAnotherDayResponseDTO.swift in Sources */, diff --git a/NotToDo/NotToDo/Network/API/Achieve/AchieveAPI.swift b/NotToDo/NotToDo/Network/API/Achieve/AchieveAPI.swift index 16f1bdd..39a2735 100644 --- a/NotToDo/NotToDo/Network/API/Achieve/AchieveAPI.swift +++ b/NotToDo/NotToDo/Network/API/Achieve/AchieveAPI.swift @@ -19,7 +19,7 @@ final class AchieveAPI { public private(set) var situationStatisticsData: GeneralArrayResponse? public private(set) var missionStatisticsData: GeneralArrayResponse? - public private(set) var achieveCalendarData: GeneralArrayResponse? + public private(set) var achieveCalendarData: GeneralResponse? // MARK: - GET @@ -63,21 +63,38 @@ final class AchieveAPI { // MARK: - GET - func getAchieveCalendar(month: String, completion: @escaping (GeneralArrayResponse?) -> Void) { - achieveProvider.request(.achieveCalendar(month: month)) { result in - switch result { - case .success(let response): - do { - self.achieveCalendarData = try response.map(GeneralArrayResponse?.self) - guard let situationStatisticsData = self.achieveCalendarData else { return } - completion(self.achieveCalendarData) - } catch (let err) { - print(err.localizedDescription, 500) - } - case .failure(let err): - print(err.localizedDescription) - completion(nil) +// func getAchieveCalendar(month: String, completion: @escaping (GeneralResponse?) -> Void) { +// achieveProvider.request(.achieveCalendar(month: month)) { result in +// switch result { +// case .success(let response): +// do { +// self.achieveCalendarData = try response.map(GeneralResponse?.self) +// guard let achieveCalendarData = self.achieveCalendarData else { return } +// completion(self.achieveCalendarData) +// } catch (let err) { +// print(err.localizedDescription, 500) +// } +// case .failure(let err): +// print(err.localizedDescription) +// completion(nil) +// } +// } +// } + + + func getAchieveCalendar(month: String, completion: @escaping (NetworkResult) -> Void) { + achieveProvider.request(.achieveCalendar(month: month)) { response in + switch response { + case let .success(response): + let statusCode = response.statusCode + let data = response.data + let networkResult = NetworkBase.judgeStatus(by: statusCode, data, + [AchieveCalendarResponseDTO].self) + completion(networkResult) + case let .failure(err): + print(err) } } } + } diff --git a/NotToDo/NotToDo/Network/DataModel/Achieve/AchieveCalendarResponseDTO.swift b/NotToDo/NotToDo/Network/DataModel/Achieve/AchieveCalendarResponseDTO.swift index 34832ea..0cf833f 100644 --- a/NotToDo/NotToDo/Network/DataModel/Achieve/AchieveCalendarResponseDTO.swift +++ b/NotToDo/NotToDo/Network/DataModel/Achieve/AchieveCalendarResponseDTO.swift @@ -8,7 +8,7 @@ import Foundation // MARK: - AchieveCalendarResponse -struct AchieveCalendarResponse: Codable { +struct AchieveCalendarResponseDTO: Codable { let actionDate: String let count: Int } diff --git a/NotToDo/NotToDo/Network/Service/Achieve/AchieveService.swift b/NotToDo/NotToDo/Network/Service/Achieve/AchieveService.swift index 71d9766..c04830d 100644 --- a/NotToDo/NotToDo/Network/Service/Achieve/AchieveService.swift +++ b/NotToDo/NotToDo/Network/Service/Achieve/AchieveService.swift @@ -22,15 +22,15 @@ extension AchieveService: TargetType { var path: String { switch self { - case .achieveCalendar(month: let month): - return URLConstant.achieveCalendar+"/\(month)" + case .achieveCalendar(let month): + return URLConstant.achieveCalendar + "/\(month)" case .missionStatistics: return URLConstant.missionStatistics case .situationStatistics: return URLConstant.situationStatistics } } - + var method: Moya.Method { switch self { case .achieveCalendar, .missionStatistics, .situationStatistics: diff --git a/NotToDo/NotToDo/Presentation/AchievementScene/Cells/CalendarCustomCell.swift b/NotToDo/NotToDo/Presentation/AchievementScene/Cells/CalendarCustomCell.swift deleted file mode 100644 index 56ffe00..0000000 --- a/NotToDo/NotToDo/Presentation/AchievementScene/Cells/CalendarCustomCell.swift +++ /dev/null @@ -1,221 +0,0 @@ -// -// CalendarCustomCell.swift -// NotToDo -// -// Created by JEONGEUN KIM on 2023/01/13. -// -// -//import UIKit -// -//import FSCalendar -// -//enum FilledType: Int { -// case none -// case all -// case some -// case today -//} -// -//enum SelectedType: Int { -// case not -// case single -//} -// -//final class CalendarDayCell: FSCalendarCell { -// weak var circleImageView: UIImageView! -// weak var selectionLayer: CAShapeLayer! -// -// var width: CGFloat = 32.0 { -// didSet { -// setNeedsLayout() -// } -// } -// -// var yPosition: CGFloat = 2.0 { -// didSet { -// setNeedsLayout() -// } -// } -// -// var filledType: FilledType = .none { -// didSet { -// setNeedsLayout() -// } -// } -// -// var selectedType: SelectedType = .not { -// didSet { -// setNeedsLayout() -// } -// } -// -// override init(frame: CGRect) { -// super.init(frame: frame) -// -// let circleImageView = UIImageView(image: Image.calenderBackgroundSome) -// self.contentView.insertSubview(circleImageView, at: 0) -// self.circleImageView = circleImageView -// self.shapeLayer.isHidden = true -// } -// -// required init!(coder aDecoder: NSCoder!) { -// fatalError() -// } -// -// override func layoutSubviews() { -// super.layoutSubviews() -// let width = width -// let yPosition = yPosition -// let distance = (self.contentView.bounds.width - width) / 2 -// let frame = CGRect(x: self.contentView.bounds.minX + distance, -// y: self.contentView.bounds.minY + yPosition, -// width: width, -// height: width) -// self.circleImageView.frame = frame -// -// switch selectedType { -// case .not: -// self.titleLabel.font = .PretendardMedium(size: 14) -// case .single: -// self.titleLabel.font = UIFont.font(.pretendardBold, ofSize: 22) -// } -// -// switch filledType { -// case .all: -// self.titleLabel.textColor = Color.white -// self.circleImageView.image = Image.calenderBackgroundAll -// case .some: -// self.titleLabel.textColor = Color.black -// self.circleImageView.image = Image.calenderBackgroundSome -// case .today: -// self.titleLabel.textColor = Color.black -// self.circleImageView.image = selectedType == .not ? -// Image.calendarBackgroundTodayDefault : Image.calendarBackgroundToday -// case .none: -// self.titleLabel.textColor = Color.black -// self.circleImageView.image = nil -// } -// } -// -// func configureUI(isSelected: Bool, with type: FilledType) { -// width = isSelected ? 48 : 32 -// yPosition = isSelected ? -6 : 2 -// selectedType = isSelected ? .single : .not -// filledType = type -// } -//} -// -//enum SelectionType : Int { -// case none -// case single -// case leftBorder -// case middle -// case rightBorder -//} -// -//class DIYCalendarCell: FSCalendarCell { -// weak var selectionLayer: CAShapeLayer? -// weak var connectionLayer: CAShapeLayer? -// -// var selectionType: SelectionType = .none { -// didSet { -// if selectionType == .none { -// self.selectionLayer?.opacity = 0 -// self.connectionLayer?.opacity = 0 -// self.selectionLayer?.isHidden = true -// self.connectionLayer?.isHidden = true -// return -// } -// setNeedsLayout() -// } -// } -// -// required init!(coder aDecoder: NSCoder!) { -// fatalError("init(coder:) has not been implemented") -// } -// -// override init(frame: CGRect) { -// super.init(frame: frame) -// -// let selectionLayer = CAShapeLayer() -// selectionLayer.fillColor = UIColor(red: 228 / 255, green: 246 / 255, blue: 246 / 255, alpha: 1.0).cgColor -// selectionLayer.opacity = 0 -// self.contentView.layer.insertSublayer(selectionLayer, below: self.titleLabel.layer) -// self.selectionLayer = selectionLayer -// self.selectionLayer?.isHidden = true -// -// let connectionLayer = CAShapeLayer() -// connectionLayer.fillColor = UIColor(red: 228 / 255, green: 246 / 255, blue: 246 / 255, alpha: 1.0).cgColor -// connectionLayer.opacity = 0 -// self.contentView.layer.insertSublayer(connectionLayer, below: self.titleLabel.layer) -// self.connectionLayer = connectionLayer -// self.connectionLayer?.isHidden = true -// -// self.shapeLayer.isHidden = true -// } -// -// override func prepareForReuse() { -// super.prepareForReuse() -// self.selectionLayer?.opacity = 0 -// self.connectionLayer?.opacity = 0 -// self.contentView.layer.removeAnimation(forKey: "opacity") -// } -// -// override func layoutSubviews() { -// super.layoutSubviews() -// -// self.selectionLayer?.frame = self.contentView.bounds.insetBy(dx: 0, dy: -3) -// self.connectionLayer?.frame = self.contentView.bounds.insetBy(dx: 0, dy: -3) -// guard var connectionRect = connectionLayer?.bounds else { -// return -// } -// -// connectionRect.size.height = connectionRect.height * 5 / 6 -// if selectionType == .middle { -// self.connectionLayer?.isHidden = false -// self.connectionLayer?.opacity = 1 -// self.connectionLayer?.path = UIBezierPath(rect: connectionRect).cgPath -// self.titleLabel.textColor = UIColor.black -// } -// else if selectionType == .leftBorder { -// self.connectionLayer?.isHidden = false -// self.connectionLayer?.opacity = 1 -// var rect = connectionRect -// rect.origin.x = connectionRect.width / 2 -// rect.size.width = connectionRect.width / 2 -// self.connectionLayer?.path = UIBezierPath(rect: rect).cgPath -// } -// else if selectionType == .rightBorder { -// self.connectionLayer?.isHidden = false -// self.connectionLayer?.opacity = 1 -// var rect = connectionRect -// rect.size.width = connectionRect.width / 2 -// self.connectionLayer?.path = UIBezierPath(rect: rect).cgPath -// } -// -// if selectionType == .single || selectionType == .leftBorder || selectionType == .rightBorder { -// self.selectionLayer?.isHidden = false -// self.selectionLayer?.opacity = 1 -// let diameter: CGFloat = min(connectionRect.height, connectionRect.width) -// let rect = CGRect( -// x: self.contentView.frame.width / 2 - diameter / 2, -// y: 0, -// width: diameter, -// height: diameter) -// self.selectionLayer?.path = UIBezierPath(ovalIn: rect).cgPath -// } -// -// if selectionType == .single { -// self.titleLabel.textColor = UIColor(red: 0 / 255, green: 171 / 255, blue: 182 / 255, alpha: 1.0) -// } -// } -// -// override func configureAppearance() { -// super.configureAppearance() -// if self.isPlaceholder { -// self.eventIndicator.isHidden = true -// self.titleLabel.textColor = UIColor.lightGray -// } -// } -// -//} diff --git a/NotToDo/NotToDo/Presentation/AchievementScene/ViewControllers/AchievementViewController.swift b/NotToDo/NotToDo/Presentation/AchievementScene/ViewControllers/AchievementViewController.swift index 47ba9e4..b2d5d8c 100644 --- a/NotToDo/NotToDo/Presentation/AchievementScene/ViewControllers/AchievementViewController.swift +++ b/NotToDo/NotToDo/Presentation/AchievementScene/ViewControllers/AchievementViewController.swift @@ -32,33 +32,38 @@ final class AchievementViewController: UIViewController { private lazy var missionView = MissionStatisticsView(frame: view.bounds) private lazy var situationView = SituationStatisticsView(frame: view.bounds) private var bottomLabel = UILabel() - private lazy var dateFormatter = DateFormatter() + private var dateFormatter = DateFormatter() let calendar = Calendar(identifier: Calendar.Identifier.gregorian) private lazy var safeArea = self.view.safeAreaLayoutGuide var situationList: [SituationStatistcsResponse] = [] var missionList: [MissionStatistcsResponse] = [] - private var dayChecked: String? + private var achieveMonth: String? // MARK: - View Life Cycle + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + requestAchieveAPI() + requestMonthAPI(month: "2023-01") + } + override func viewDidLoad() { super.viewDidLoad() configSituationView() setUI() setLayout() } - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - requestAchieveAPI() - requestMonthAPI(month: "2023-01") - } } // MARK: - Methods extension AchievementViewController { + func reloadMonthData() { + requestMonthAPI(month: "2023-01") + } + func setUI() { view.backgroundColor = .BG @@ -103,26 +108,20 @@ extension AchievementViewController { } private func requestMonthAPI(month: String) { - AchieveAPI.shared.getAchieveCalendar(month: month) { [weak self] response in - guard self != nil else { return } - guard let response = response else { return } - print(response) - dump(response) + AchieveAPI.shared.getAchieveCalendar(month: month) { result in + switch result { + case let .success(data): + guard data is [AchieveCalendarResponseDTO] else { return } + case .requestErr: + print("requestErr") + case .pathErr: + print("pathErr") + case .serverErr: + print("serverErr") + case .networkFail: + print("networkFail") + } } -// AchieveAPI.shared.getAchieveCalendar(month: month) { [weak self] result in -// switch result { -// case let .success(data): -// guard data is [AchieveCalendarResponse] else { return } -// case .requestErr: -// print("requestErr") -// case .pathErr: -// print("pathErr") -// case .serverErr: -// print("serverErr") -// case .networkFail: -// print("networkFail") -// } -// } } func configMissionView() {