Skip to content

Commit

Permalink
[Feat] #392 - pull develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwogus0128 committed Sep 28, 2024
2 parents 17223ed + 9bb7102 commit 58d6cea
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 48 deletions.
38 changes: 22 additions & 16 deletions SOPT-iOS/Projects/Core/Sources/Utils/setDateFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,33 @@

import Foundation

extension String {

/**

- Description:
"yyyy-MM-dd'T'HH:mm:ss" 형태로 주어진 날짜를 원하는 format으로 변경하는 메서드
/**

- parameters:
- dateString: 변경하고자 하는 dateformat을 입력합니다. ex. "HH:mm"

*/
- Description:
주어진 날짜를 원하는 format으로 변경하는 메서드
주어진 날짜가 없는 경우 오늘 날짜 반환

public func setDateFormat(dateString: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
dateFormatter.locale = Locale(identifier: "ko_KR")
dateFormatter.timeZone = TimeZone(identifier: "Asia/Seoul")
- parameters:
- dateString: 변경하고자 하는 dateformat을 입력합니다. ex. "HH:mm"

*/

public func setDateFormat(date: String? = nil, from before: String? = nil, to after: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ko_KR")
dateFormatter.timeZone = TimeZone(identifier: "Asia/Seoul")

if let dateString = date,
let before = before {

guard let date = dateFormatter.date(from: self) else { return "00:00" }
dateFormatter.dateFormat = before
guard let date = dateFormatter.date(from: dateString) else { return "00:00" }
dateFormatter.dateFormat = after

dateFormatter.dateFormat = dateString
return dateFormatter.string(from: date)
} else {
dateFormatter.dateFormat = after
return dateFormatter.string(from: Date())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ extension TodayAttendance {

public func toDomain() -> TodayAttendanceModel {
return .init(status: self.status,
attendedAt: self.attendedAt.setDateFormat(dateString: "HH:mm"))
attendedAt: setDateFormat(
date: self.attendedAt,
from: "yyyy-MM-dd'T'HH:mm:ss",
to: "HH:mm"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import Domain
@_exported import PokeFeatureInterface

public protocol DailySoptuneFeatureBuildable {
func makeDailySoptuneResultVC() -> DailySoptuneResultPresentable
func makeDailySoptuneResultVC(resultModel: DailySoptuneResultModel) -> DailySoptuneResultPresentable
func makePokeMessageTemplateBottomSheet(messageType: PokeMessageType) -> PokeMessageTemplatesPresentable
func makeDailySoptuneMainVC() -> DailySoptuneMainPresentable
func makeDailySoptuneCardVC(cardModel: DailySoptuneCardModel) -> DailySoptuneCardPresentable
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

import BaseFeatureDependency
import Core
import Domain

public protocol DailySoptuneMainViewControllable: ViewControllable {}

public protocol DailySoptuneMainCoordinatable {}
public protocol DailySoptuneMainCoordinatable {
var onNaviBackTap: (() -> Void)? { get set }
var onReciveTodayFortuneButtonTap: ((DailySoptuneResultModel) -> Void)? { get set }
}

public typealias DailySoptuneMainViewModelType = ViewModelType & DailySoptuneMainCoordinatable
public typealias DailySoptuneMainPresentable = (vc: DailySoptuneMainViewControllable, vm: any DailySoptuneMainViewModelType)
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public final class DailySoptuneBuilder {

extension DailySoptuneBuilder: DailySoptuneFeatureBuildable {

public func makeDailySoptuneResultVC() -> DailySoptuneFeatureInterface.DailySoptuneResultPresentable {
public func makeDailySoptuneResultVC(resultModel: DailySoptuneResultModel) -> DailySoptuneFeatureInterface.DailySoptuneResultPresentable {
let useCase = DefaultDailySoptuneUseCase(repository: dailySoptuneRepository)
let viewModel = DailySoptuneResultViewModel(useCase: useCase)
let dailySoptuneResultVC = DailySoptuneResultVC(viewModel: viewModel)
let dailySoptuneResultVC = DailySoptuneResultVC(
viewModel: viewModel,
resultModel: resultModel)
return (dailySoptuneResultVC, viewModel)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,28 @@ public final class DailySoptuneResultCoordinator: DefaultCoordinator {
}

public override func start() {
showDailySoptuneResult()
showDailySoptuneMain()
}

private func showDailySoptuneResult() {
var dailySoptuneResult = factory.makeDailySoptuneResultVC()
private func showDailySoptuneMain() {
var dailySoptuneMain = factory.makeDailySoptuneMainVC()

dailySoptuneMain.vm.onNaviBackTap = {
self.router.popModule()
self.finishFlow?()
}

dailySoptuneMain.vm.onReciveTodayFortuneButtonTap = { [weak self] result in
guard let self else { return }
let resultVC = self.factory.makeDailySoptuneResultVC(resultModel: result)
self.router.push(resultVC.vc)
}

router.push(dailySoptuneMain.vc)
}

private func showDailySoptuneResult(resultModel: DailySoptuneResultModel) {
var dailySoptuneResult = factory.makeDailySoptuneResultVC(resultModel: resultModel)

dailySoptuneResult.vm.onNaviBackButtonTapped = { [weak self] in
self?.router.dismissModule(animated: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// DailySoptuneWordDeepLink.swift
// DailySoptuneFeatureDemo
//
// Created by 강윤서 on 9/28/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import Foundation
import BaseFeatureDependency

public struct DailySoptuneWordDeepLink: DeepLinkExecutable {
public var name = "word"
public var children: [DeepLinkExecutable] = []
public var isDestination = true

public init() {}

public func execute(with coordinator: Coordinator, queryItems: [URLQueryItem]?) -> Coordinator? {
guard let coordinator = coordinator as? DailySoptuneCoordinator else { return nil }

if self.isDestination == true {
coordinator.start()
}

return nil
}








}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class DailySoptuneMainVC: UIViewController, DailySoptuneMainViewCon
private let dateLabel = UILabel().then {
$0.textColor = DSKitAsset.Colors.gray100.color
$0.font = DSKitFontFamily.Suit.medium.font(size: 16)
$0.text = "9월 17일 화요일"
$0.text = setDateFormat(to: "M월 d일 EEEE")
}

private let recieveFortune = UILabel().then {
Expand Down Expand Up @@ -127,7 +127,7 @@ private extension DailySoptuneMainVC {
func bindViewModels() {
let input = DailySoptuneMainViewModel
.Input(
viewDidLoad: viewDidLoaded,
viewDidLoad: viewDidLoaded.asDriver(),
naviBackButtonTap: backButtonTapped,
receiveTodayFortuneButtonTap: todayFortuneButtonTapped
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class DailySoptuneResultVC: UIViewController, DailySoptuneResultVie

public var viewModel: DailySoptuneResultViewModel
private var cancelBag = CancelBag()
private let resultModel: DailySoptuneResultModel

private lazy var receiveTodaysFortuneButtonTap: Driver<Void> = receiveTodaysFortuneCardButton.publisher(for: .touchUpInside).mapVoid().asDriver()
private let viewWillAppear = PassthroughSubject<Void, Never>()
Expand Down Expand Up @@ -51,7 +52,7 @@ public final class DailySoptuneResultVC: UIViewController, DailySoptuneResultVie

// 오늘의 솝마디 부분

private lazy var dailySoptuneResultContentView = DailySoptuneResultContentView(name: "이재현", description: "단순하게 생각하면\n일이 술술 풀리겠솝!", date: viewModel.setCurrentDateString())
private lazy var dailySoptuneResultContentView = DailySoptuneResultContentView()

// 콕 찌르기 부분

Expand All @@ -65,8 +66,9 @@ public final class DailySoptuneResultVC: UIViewController, DailySoptuneResultVie

// MARK: - Initialization

public init(viewModel: DailySoptuneResultViewModel) {
public init(viewModel: DailySoptuneResultViewModel, resultModel: DailySoptuneResultModel) {
self.viewModel = viewModel
self.resultModel = resultModel
super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -95,6 +97,7 @@ public final class DailySoptuneResultVC: UIViewController, DailySoptuneResultVie
extension DailySoptuneResultVC {
private func setUI() {
view.backgroundColor = DSKitAsset.Colors.semanticBackground.color
dailySoptuneResultContentView.setData(model: resultModel)
}

private func setStackView() {
Expand Down Expand Up @@ -143,8 +146,8 @@ extension DailySoptuneResultVC {

// MARK: - Methods

extension DailySoptuneResultVC {
private func bindViewModels() {
private extension DailySoptuneResultVC {
func bindViewModels() {
let input = DailySoptuneResultViewModel
.Input(
viewWillAppear: viewWillAppear.asDriver(),
Expand All @@ -164,3 +167,4 @@ extension DailySoptuneResultVC {
}.store(in: self.cancelBag)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import DailySoptuneFeatureInterface

public final class DailySoptuneMainViewModel: DailySoptuneMainViewModelType {

public var onNavibackTap: (() -> Void)?
public var onReciveTodayFortuneButtonTap: (() -> Void)?
public var onNaviBackTap: (() -> Void)?
public var onReciveTodayFortuneButtonTap: ((DailySoptuneResultModel) -> Void)?

// MARK: - Properties

Expand All @@ -35,7 +35,6 @@ public final class DailySoptuneMainViewModel: DailySoptuneMainViewModelType {
// MARK: - Outputs

public struct Output {
let todayFortuneResult = PassthroughSubject<DailySoptuneResultModel, Never>()
}

// MARK: - Initialization
Expand All @@ -53,23 +52,24 @@ extension DailySoptuneMainViewModel {
input.viewDidLoad
.withUnretained(self)
.sink {_ in
self.onNavibackTap?()
self.onNaviBackTap?()
}.store(in: cancelBag)

input.receiveTodayFortuneButtonTap
.withUnretained(self)
.sink { _ in
self.onReciveTodayFortuneButtonTap?()
self.useCase.getDailySoptuneResult(date: "2024-09-19")
self.useCase.getDailySoptuneResult(date: setDateFormat(to: "yyyy-MM-dd"))
}.store(in: cancelBag)

return output
}

private func bindOutput(output: Output, cancelBag: CancelBag) {
useCase.dailySoptuneResult
.asDriver()
.subscribe(output.todayFortuneResult)
.withUnretained(self)
.sink { _, resultModel in
self.onReciveTodayFortuneButtonTap?(resultModel)
}
.store(in: cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Combine

import DSKit
import Core
import Domain

public final class DailySoptuneResultContentView: UIView {

Expand All @@ -28,19 +29,19 @@ public final class DailySoptuneResultContentView: UIView {
private lazy var contentLabel = UILabel().then {
$0.font = UIFont.MDS.title3.font
$0.textColor = DSKitAsset.Colors.gray30.color
$0.numberOfLines = 3
$0.numberOfLines = 0
}

// MARK: - initialization

init(name: String, description: String, date: String) {
super.init(frame: .zero)
self.contentLabel.text = "\(name)님,\n\(description)"
self.dateLabel.text = date
public override init(frame: CGRect) {
super.init(frame: frame)

self.setUI()
self.setLayout()
}


required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down Expand Up @@ -70,24 +71,32 @@ extension DailySoptuneResultContentView {
self.addSubviews(soptuneLogoImage, dateLabel, contentLabel)

soptuneLogoImage.snp.makeConstraints { make in
make.top.equalToSuperview().inset(32)
make.top.equalToSuperview().inset(32.adjustedH)
make.width.equalTo(Metric.soptuneLogoWidth)
make.height.equalTo(Metric.soptuneLogoWidth * Metric.soptuneLogoRatio)
make.centerX.equalToSuperview()
}

dateLabel.snp.makeConstraints { make in
make.top.equalTo(soptuneLogoImage.snp.bottom).offset(12)
make.top.equalTo(soptuneLogoImage.snp.bottom).offset(12.adjusted)
make.centerX.equalToSuperview()
}

contentLabel.snp.makeConstraints { make in
make.top.equalTo(dateLabel.snp.bottom).offset(20)
make.top.equalTo(dateLabel.snp.bottom).offset(20.adjustedH)
make.centerX.equalToSuperview()
make.leading.trailing.equalToSuperview().inset(76.adjusted)
}

self.snp.makeConstraints { make in
make.bottom.equalTo(contentLabel.snp.bottom).offset(34)
make.bottom.equalTo(contentLabel.snp.bottom).offset(34.adjustedH)
}
}
}

extension DailySoptuneResultContentView {
public func setData(model: DailySoptuneResultModel) {
self.dateLabel.text = setDateFormat(to: "MM월 dd일 EEEE")
self.contentLabel.text = "\(model.userName)님,\n\(model.title)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import DailySoptuneFeature
public
final class ApplicationCoordinator: BaseCoordinator {

// private let coordinatorFactory: CoordinatorFactory
private let router: Router
private var cancelBag = CancelBag()
private let notificationHandler: NotificationHandler
Expand Down Expand Up @@ -373,4 +372,24 @@ extension ApplicationCoordinator {

return coordinator
}

@discardableResult
internal func runDailySoptuneFlow() -> DailySoptuneCoordinator {
let coordinator = DailySoptuneCoordinator(
router: Router(
rootController: UIWindow.getRootNavigationController
),
factory: DailySoptuneBuilder(),
pokeFactory: PokeBuilder()
)
coordinator.finishFlow = { [weak self, weak coordinator] in
coordinator?.childCoordinators = []
self?.removeDependency(coordinator)
}

addDependency(coordinator)
coordinator.start()

return coordinator
}
}
Loading

0 comments on commit 58d6cea

Please sign in to comment.