Skip to content

Commit

Permalink
[Feat] sopt-makers#153- 오늘의 일정 부분 뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
devxsby committed Apr 15, 2023
1 parent a58ff01 commit e748f2e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Combine

import Core
import Domain
import Foundation

public final class ShowAttendanceViewModel: ViewModelType {

Expand All @@ -31,7 +32,6 @@ public final class ShowAttendanceViewModel: ViewModelType {
public class Output {
@Published var scheduleModel: AttendanceScheduleModel?
@Published var scoreModel: AttendanceScoreModel?

}

// MARK: - init
Expand All @@ -51,11 +51,6 @@ extension ShowAttendanceViewModel {
input.viewDidLoad.merge(with: input.refreshButtonTapped)
.withUnretained(self)
.sink { owner, _ in
// if owner.sceneType == .unscheduledDay {
// owner.useCase.
// } else {
//
// }
owner.useCase.fetchAttendanceSchedule()
owner.useCase.fetchAttendanceScore()
}.store(in: cancelBag)
Expand All @@ -69,7 +64,17 @@ extension ShowAttendanceViewModel {

fetchedSchedule.asDriver()
.sink(receiveValue: { model in
output.scheduleModel = model
guard let convertedStartDate = self.convertDateString(model.startDate),
let convertedEndDate = self.convertDateString(model.endDate) else { return }

let newModel = AttendanceScheduleModel(type: model.type,
location: model.location,
name: model.name,
startDate: convertedStartDate,
endDate: convertedEndDate,
message: model.message,
attendances: model.attendances)
output.scheduleModel = newModel
})
.store(in: cancelBag)

Expand All @@ -79,4 +84,30 @@ extension ShowAttendanceViewModel {
})
.store(in: cancelBag)
}

private func convertDateString(_ dateString: String) -> String? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
guard let date = dateFormatter.date(from: dateString) else { return nil }

dateFormatter.dateFormat = "M월 d일 EEEE H:mm"
dateFormatter.locale = Locale(identifier: "ko_KR")
dateFormatter.timeZone = TimeZone(identifier: "Asia/Seoul")
return dateFormatter.string(from: date)
}

func formatTimeInterval(startDate: String, endDate: String) -> String? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "M월 d일 EEEE HH:mm"

guard let startDateObject = dateFormatter.date(from: startDate),
let endDateObject = dateFormatter.date(from: endDate) else { return nil }

let formattedStartDate = dateFormatter.string(from: startDateObject)

dateFormatter.dateFormat = "HH:mm"
let formattedEndDate = dateFormatter.string(from: endDateObject)

return "\(formattedStartDate) ~ \(formattedEndDate)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import UIKit
import Combine

import Core
import Domain
import DSKit

import SnapKit
import AttendanceFeatureInterface

private enum SessionType: String, CaseIterable {
case noSession = "NO_SESSION"
case hasAttendance = "HAS_ATTENDANCE"
case noAttendance = "NO_ATTENDANCE"
}

public final class ShowAttendanceVC: UIViewController, ShowAttendanceViewControllable {

// MARK: - Properties
Expand All @@ -25,7 +32,7 @@ public final class ShowAttendanceVC: UIViewController, ShowAttendanceViewControl
private var cancelBag = CancelBag()

public var sceneType: AttendanceScheduleType {
return self.viewModel.sceneType ?? .unscheduledDay
return self.viewModel.sceneType ?? .scheduledDay
}
private var viewdidload = PassthroughSubject<Void, Never>()

Expand Down Expand Up @@ -73,7 +80,6 @@ public final class ShowAttendanceVC: UIViewController, ShowAttendanceViewControl
self.setUI()
self.setLayout()
self.viewdidload.send(())
// self.dummy()
}
}

Expand Down Expand Up @@ -116,13 +122,6 @@ extension ShowAttendanceVC {
$0.bottom.equalToSuperview()
}
}

private func dummy() {
headerScheduleView.setData(date: "3월 23일 토요일 14:00 - 18:00",
place: "건국대학교 꽥꽥오리관",
todaySchedule: "1차 행사",
description: "행사도 참여하고, 출석점수도 받고, 일석이조!")
}
}

// MARK: - Methods
Expand All @@ -146,18 +145,37 @@ extension ShowAttendanceVC {
let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag)

output.$scheduleModel
.compactMap { $0 }
.sink { model in
print("스케쥴 데이터가 잘 넘어왓을까요?", model)
if model.type == "NO_SESSION" {
self.viewModel.sceneType = .unscheduledDay
} else {
self.viewModel.sceneType = .scheduledDay
self.setData(model)
}
// print("스케쥴 데이터가 잘 넘어왓을까요?", model)
}.store(in: self.cancelBag)

output.$scoreModel
.sink { model in
print("스코어 데이터가 잘 넘어왔을까여?]", model)
// print("스코어 데이터가 잘 넘어왔을까여?]", model)
}.store(in: self.cancelBag)
}

@objc
private func refreshButtonDidTap() {
print("refresh button did tap")
}

private func setData(_ model: AttendanceScheduleModel) {
if self.sceneType == .scheduledDay {
guard let date = viewModel.formatTimeInterval(startDate: model.startDate, endDate: model.endDate) else { return }
headerScheduleView.setData(date: date,
place: model.location,
todaySchedule: model.name,
description: model.message)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ extension TodayScheduleView {
titleLabel.partFontChange(targetString: todaySchedule,
font: DSKitFontFamily.Suit.bold.font(size: 18))
subtitleLabel.text = description
subtitleLabel.isHidden = ((description?.isEmpty) == nil)
subtitleLabel.isHidden = ((description?.isEmpty) == nil || description == "")
}
}

0 comments on commit e748f2e

Please sign in to comment.