Skip to content

Commit

Permalink
[FEAT] #84 - 성취뷰 캘린더 API 연결
Browse files Browse the repository at this point in the history
[FEAT]  #84 - 성취뷰 캘린더 API 연결
  • Loading branch information
jeongdung-eo authored Jan 13, 2023
2 parents a18fcdf + 3d60355 commit e86bb25
Show file tree
Hide file tree
Showing 26 changed files with 270 additions and 115 deletions.
32 changes: 20 additions & 12 deletions NotToDo/NotToDo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
090FA2F52960B70400918AED /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 090FA2F42960B70400918AED /* SnapKit */; };
090FA2F82960B74000918AED /* Then in Frameworks */ = {isa = PBXBuildFile; productRef = 090FA2F72960B74000918AED /* Then */; };
090FA2FB2960B87500918AED /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 090FA2FA2960B87500918AED /* Moya */; };
0951EE8D297130DF004A3B5B /* AchieveCalendarResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0951EE8C297130DF004A3B5B /* AchieveCalendarResponseDTO.swift */; };
09611EE7296FD52700561CAA /* RecommendService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09611EE6296FD52700561CAA /* RecommendService.swift */; };
09611EEA296FDC6300561CAA /* RecommendDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09611EE9296FDC6300561CAA /* RecommendDTO.swift */; };
09611EED296FDD4200561CAA /* RecommendAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09611EEC296FDD4200561CAA /* RecommendAPI.swift */; };
Expand All @@ -33,11 +34,12 @@
099F0728296B94790036CF55 /* StatisticsEmptyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099F0727296B94790036CF55 /* StatisticsEmptyTableViewCell.swift */; };
099F072A296B98B90036CF55 /* SituationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099F0729296B98B90036CF55 /* SituationTitleView.swift */; };
099F073D296C2F770036CF55 /* CustomSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099F073C296C2F770036CF55 /* CustomSegmentedControl.swift */; };
09D3C535296FFD3500F1488D /* SituationStasticsResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C534296FFD3500F1488D /* SituationStasticsResponse.swift */; };
09AF3FD229719DD900518D52 /* String+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AF3FD129719DD900518D52 /* String+.swift */; };
09AF3FD429719E2200518D52 /* Date+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AF3FD329719E2200518D52 /* Date+.swift */; };
09D3C535296FFD3500F1488D /* SituationStasticsResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C534296FFD3500F1488D /* SituationStasticsResponseDTO.swift */; };
09D3C538296FFD7C00F1488D /* AchieveAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C537296FFD7C00F1488D /* AchieveAPI.swift */; };
09D3C53D29700DC800F1488D /* AchieveService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C53C29700DC800F1488D /* AchieveService.swift */; };
09D3C53F29700F7B00F1488D /* MissionStatisticsAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C53E29700F7B00F1488D /* MissionStatisticsAPI.swift */; };
09D3C5412970101400F1488D /* MissionStatisticsReponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C5402970101400F1488D /* MissionStatisticsReponse.swift */; };
09D3C5412970101400F1488D /* MissionStatisticsReponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C5402970101400F1488D /* MissionStatisticsReponseDTO.swift */; };
09F695D9296C332D00877EA7 /* CompositionalLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09F695D8296C332D00877EA7 /* CompositionalLayout.swift */; };
09F695DB296C52B600877EA7 /* MissionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09F695DA296C52B600877EA7 /* MissionTableViewCell.swift */; };
09F695DD296C52F000877EA7 /* SituationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09F695DC296C52F000877EA7 /* SituationTableViewCell.swift */; };
Expand Down Expand Up @@ -149,6 +151,7 @@

/* Begin PBXFileReference section */
090FA2E6295F51BB00918AED /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
0951EE8C297130DF004A3B5B /* AchieveCalendarResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AchieveCalendarResponseDTO.swift; sourceTree = "<group>"; };
09611EE6296FD52700561CAA /* RecommendService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendService.swift; sourceTree = "<group>"; };
09611EE9296FDC6300561CAA /* RecommendDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendDTO.swift; sourceTree = "<group>"; };
09611EEC296FDD4200561CAA /* RecommendAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendAPI.swift; sourceTree = "<group>"; };
Expand All @@ -170,11 +173,12 @@
099F0727296B94790036CF55 /* StatisticsEmptyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatisticsEmptyTableViewCell.swift; sourceTree = "<group>"; };
099F0729296B98B90036CF55 /* SituationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SituationTitleView.swift; sourceTree = "<group>"; };
099F073C296C2F770036CF55 /* CustomSegmentedControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSegmentedControl.swift; sourceTree = "<group>"; };
09D3C534296FFD3500F1488D /* SituationStasticsResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SituationStasticsResponse.swift; sourceTree = "<group>"; };
09AF3FD129719DD900518D52 /* String+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+.swift"; sourceTree = "<group>"; };
09AF3FD329719E2200518D52 /* Date+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+.swift"; sourceTree = "<group>"; };
09D3C534296FFD3500F1488D /* SituationStasticsResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SituationStasticsResponseDTO.swift; sourceTree = "<group>"; };
09D3C537296FFD7C00F1488D /* AchieveAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AchieveAPI.swift; sourceTree = "<group>"; };
09D3C53C29700DC800F1488D /* AchieveService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AchieveService.swift; sourceTree = "<group>"; };
09D3C53E29700F7B00F1488D /* MissionStatisticsAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissionStatisticsAPI.swift; sourceTree = "<group>"; };
09D3C5402970101400F1488D /* MissionStatisticsReponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissionStatisticsReponse.swift; sourceTree = "<group>"; };
09D3C5402970101400F1488D /* MissionStatisticsReponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissionStatisticsReponseDTO.swift; sourceTree = "<group>"; };
09F695D8296C332D00877EA7 /* CompositionalLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CompositionalLayout.swift; path = ../ViewControllers/CompositionalLayout.swift; sourceTree = "<group>"; };
09F695DA296C52B600877EA7 /* MissionTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MissionTableViewCell.swift; sourceTree = "<group>"; };
09F695DC296C52F000877EA7 /* SituationTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SituationTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -328,8 +332,9 @@
09611EEE296FFC5D00561CAA /* Achieve */ = {
isa = PBXGroup;
children = (
09D3C534296FFD3500F1488D /* SituationStasticsResponse.swift */,
09D3C5402970101400F1488D /* MissionStatisticsReponse.swift */,
09D3C534296FFD3500F1488D /* SituationStasticsResponseDTO.swift */,
0951EE8C297130DF004A3B5B /* AchieveCalendarResponseDTO.swift */,
09D3C5402970101400F1488D /* MissionStatisticsReponseDTO.swift */,
);
path = Achieve;
sourceTree = "<group>";
Expand Down Expand Up @@ -385,7 +390,6 @@
isa = PBXGroup;
children = (
09D3C537296FFD7C00F1488D /* AchieveAPI.swift */,
09D3C53E29700F7B00F1488D /* MissionStatisticsAPI.swift */,
);
path = Achieve;
sourceTree = "<group>";
Expand Down Expand Up @@ -464,6 +468,8 @@
3B3405DD295B162600D44722 /* UITabBar+.swift */,
3BED5327295C018700157A3B /* adjust+.swift */,
3B5B34AB29618441002E1161 /* UIButton+.swift */,
09AF3FD129719DD900518D52 /* String+.swift */,
09AF3FD329719E2200518D52 /* Date+.swift */,
3B576323296403CB00E03637 /* UILabel+.swift */,
3B4187CE296D342900F0FBF4 /* UIViewController+.swift */,
3B882606296DDC0E00A51B50 /* UIDevice+.swift */,
Expand Down Expand Up @@ -1220,30 +1226,32 @@
3B162874295AD7860077AE7B /* AppDelegate.swift in Sources */,
3BEF92AF29686A8E0090A290 /* HomeCalendarCollectionViewCell.swift in Sources */,
096BE0172966A142009ED396 /* CustomTabBarCell.swift in Sources */,
09AF3FD429719E2200518D52 /* Date+.swift in Sources */,
3BE07017296F44D3002CC50A /* MyInfoViewController.swift in Sources */,
3B0155872971512C00E7BBF1 /* MissionCalendarDayCell.swift in Sources */,
3BE07006296F43A2002CC50A /* UIStackView+.swift in Sources */,
3BBE56E5296C213900771DE4 /* StartOnboardingView.swift in Sources */,
3BE07005296F43A2002CC50A /* UIColor+.swift in Sources */,
3BE6CBC32969D700003A8A7B /* MissionModel.swift in Sources */,
096BE01F2966A1FA009ED396 /* NestedView.swift in Sources */,
09D3C53F29700F7B00F1488D /* MissionStatisticsAPI.swift in Sources */,
09F695DB296C52B600877EA7 /* MissionTableViewCell.swift in Sources */,
09D3C5412970101400F1488D /* MissionStatisticsReponse.swift in Sources */,
09D3C5412970101400F1488D /* MissionStatisticsReponseDTO.swift in Sources */,
0951EE8D297130DF004A3B5B /* AchieveCalendarResponseDTO.swift in Sources */,
3BE0700C296F43A2002CC50A /* UIView+.swift in Sources */,
3BE07013296F4456002CC50A /* NetworkResult.swift in Sources */,
09F695DD296C52F000877EA7 /* SituationTableViewCell.swift in Sources */,
6C600BC029693B3100421D7A /* MissionHistoryModel.swift in Sources */,
6C8826122967D85F0005E222 /* AddSituationModel.swift in Sources */,
6C600BCC2969FCBC00421D7A /* EmptyRecentViewCell.swift in Sources */,
3BE07004296F43A2002CC50A /* UIDevice+.swift in Sources */,
09D3C535296FFD3500F1488D /* SituationStasticsResponse.swift in Sources */,
09D3C535296FFD3500F1488D /* SituationStasticsResponseDTO.swift in Sources */,
6CCBCF9729707A790093C0F3 /* AddMissionReqeustDTO.swift in Sources */,
6CA2EFBE296FD28400D3E66B /* AddMissionService.swift in Sources */,
3BBE56F5296C4ED100771DE4 /* ThirdOnboardingViewController.swift in Sources */,
3BBE56E7296C214600771DE4 /* FirstOnboardingView.swift in Sources */,
09F695D9296C332D00877EA7 /* CompositionalLayout.swift in Sources */,
3B4B90C62965CB8D008C5CA8 /* myInfoUserCollectionViewCell.swift in Sources */,
09AF3FD229719DD900518D52 /* String+.swift in Sources */,
6C88260F2967D8280005E222 /* AddSituationCollectionViewCell.swift in Sources */,
3B59AFB8296346650050FF49 /* Numbers.swift in Sources */,
6CDC2D212966C86D00BFF5F4 /* AddMissionTextField.swift in Sources */,
Expand Down
17 changes: 17 additions & 0 deletions NotToDo/NotToDo/Global/Extensions/Date+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Date+.swift
// NotToDo
//
// Created by JEONGEUN KIM on 2023/01/13.
//

import Foundation

extension Date {
func toString() -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy.MM.dd"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
return dateFormatter.string(from: self)
}
}
23 changes: 23 additions & 0 deletions NotToDo/NotToDo/Global/Extensions/String+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// String+.swift
// NotToDo
//
// Created by JEONGEUN KIM on 2023/01/13.
//

import Foundation

extension String {

func toDate() -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy.MM.dd"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
if let date = dateFormatter.date(from: self) {
return date
} else {
return nil
}
}
}

58 changes: 49 additions & 9 deletions NotToDo/NotToDo/Network/API/Achieve/AchieveAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ import Foundation

import Moya

final class SituationStatisticsAPI {
final class AchieveAPI {

static let shared: SituationStatisticsAPI = SituationStatisticsAPI()

private let situationStatisticsProvider = MoyaProvider<AchieveService>(plugins: [MoyaLoggingPlugin()])
static let shared: AchieveAPI = AchieveAPI()

private let achieveProvider = MoyaProvider<AchieveService>(plugins: [MoyaLoggingPlugin()])

private init() { }

public private(set) var situationStatisticsData: GeneralArrayResponse<SituationStatistcsResponse>?

public private(set) var situationStatisticsData: GeneralArrayResponse<SituationStatistcsResponseDTO>?
public private(set) var missionStatisticsData: GeneralArrayResponse<MissionStatistcsResponseDTO>?
public private(set) var achieveCalendarData: GeneralResponse<AchieveCalendarResponseDTO>?

// MARK: - GET

func getSituationStatistics(completion: @escaping (GeneralArrayResponse<SituationStatistcsResponse>?) -> Void) {
situationStatisticsProvider.request(.situationStatistics) { result in
func getSituationStatistics(completion: @escaping (GeneralArrayResponse<SituationStatistcsResponseDTO>?) -> Void) {
achieveProvider.request(.situationStatistics) { result in
switch result {
case .success(let response):
do {
self.situationStatisticsData = try response.map(GeneralArrayResponse<SituationStatistcsResponse>?.self)
self.situationStatisticsData = try response.map(GeneralArrayResponse<SituationStatistcsResponseDTO>?.self)
guard let situationStatisticsData = self.situationStatisticsData else { return }
completion(situationStatisticsData)
} catch let err {
Expand All @@ -38,4 +40,42 @@ final class SituationStatisticsAPI {
}
}
}

// MARK: - GET

func getMissionStatistics(completion: @escaping (GeneralArrayResponse<MissionStatistcsResponseDTO>?) -> Void) {
achieveProvider.request(.missionStatistics) { result in
switch result {
case .success(let response):
do {
self.missionStatisticsData = try response.map(GeneralArrayResponse<MissionStatistcsResponseDTO>?.self)
guard let situationStatisticsData = self.missionStatisticsData else { return }
completion(self.missionStatisticsData)
} catch let err {
print(err.localizedDescription, 500)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil)
}
}
}

// MARK: - GET

func getAchieveCalendar(month: String, completion: @escaping (NetworkResult<Any>) -> 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)
}
}
}

}
6 changes: 3 additions & 3 deletions NotToDo/NotToDo/Network/API/Recommend/RecommendAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ final class RecommendAPI {

private init() { }

public private(set) var recommendData: GeneralArrayResponse<RecommendElementResponse>?
public private(set) var recommendData: GeneralArrayResponse<RecommendElementResponseDTO>?

// MARK: - GET

func getRecommend(index: Int, completion: @escaping (GeneralArrayResponse<RecommendElementResponse>?) -> Void) {
func getRecommend(index: Int, completion: @escaping (GeneralArrayResponse<RecommendElementResponseDTO>?) -> Void) {
recommendProvider.request(.recommendEnvirionment(id: index )) { result in
switch result {
case .success(let response):
do {
self.recommendData = try response.map(GeneralArrayResponse<RecommendElementResponse>?.self)
self.recommendData = try response.map(GeneralArrayResponse<RecommendElementResponseDTO>?.self)
guard let recommendData = self.recommendData else { return }
completion(recommendData)
} catch let err {
Expand Down
2 changes: 1 addition & 1 deletion NotToDo/NotToDo/Network/Base/URLConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct URLConstant {

// MARK: - Achieve

static let achieveCalendar = "/mission/month/"
static let achieveCalendar = "/mission/month"
static let situationStatistics = "/mission/stat/situation"
static let missionStatistics = "/mission/stat/notTodo"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// AchieveCalendarResponse.swift
// NotToDo
//
// Created by JEONGEUN KIM on 2023/01/13.
//

import Foundation

struct AchieveCalendarResponseDTO: Codable {
let actionDate: String
let count: Int

func toDate(dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy.MM.dd"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
if let date = dateFormatter.date(from: dateString) {
return date
} else {
return nil
}
}

func convert() -> [Date: Int] {
guard let date = self.toDate(dateString: actionDate) else { return [:]}
return [date: count]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import Foundation

// MARK: - MissionStatistcsResponse
struct MissionStatistcsResponse: Codable {
struct MissionStatistcsResponseDTO: Codable {
let count: Int
let title: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

import Foundation

// MARK: - SituationStatistcsResponseElement
struct SituationStatistcsResponse: Codable {
struct SituationStatistcsResponseDTO: Codable {
let id, count: Int
let name: String
let missions: [SituationMissions]
}

// MARK: - Mission
struct SituationMissions: Codable {
let count: Int
let title: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
//
import Foundation

// MARK: - RecommendElement
struct RecommendElementResponse: Codable, Hashable {
struct RecommendElementResponseDTO: Codable, Hashable {
let title: String
let recommendActions: [RecommendAction]
}

// MARK: - RecommendAction
struct RecommendAction: Codable, Hashable {
let name: String
}

typealias Recommend = [RecommendElementResponse]
6 changes: 3 additions & 3 deletions NotToDo/NotToDo/Network/Service/Achieve/AchieveService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension MissionTableViewCell {
}
}

func configure(_ item: MissionStatistcsResponse) {
func configure(_ item: MissionStatistcsResponseDTO) {
label.text = item.title
numberLabel.text = "\(item.count)"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import UIKit
class StatisticsEmptyTableViewCell: UITableViewCell {

// MARK: - Properties

static var identifier = "StatisticsEmptyTableViewCell"

// MARK: - UI Components

private lazy var mainTitle = UILabel()
private lazy var iconImage = UIImageView()

// MARK: - Life Cycle

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setUI()
Expand Down
Loading

0 comments on commit e86bb25

Please sign in to comment.