Skip to content

Commit

Permalink
Merge pull request #123 from DSM-PICK/feature/117-school_meal_refact
Browse files Browse the repository at this point in the history
refact :: [#117] 주말급식 리팩토링
  • Loading branch information
cyj513 authored Nov 19, 2024
2 parents df60ebf + abe5cc9 commit 1f73b94
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 55 deletions.
10 changes: 4 additions & 6 deletions Projects/Data/Sources/DTO/SchoolMeal/SchoolMealDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ extension SchoolMealDTO {
}

struct SchoolMealDTOElement: Decodable {
public let breakfast: MealDTOElement
public let lunch: MealDTOElement
public let dinner: MealDTOElement
public let breakfast, lunch, dinner: MealDTOElement
}

extension SchoolMealDTOElement {
func toDomain() -> SchoolMealEntityElement {
return .init(
mealBundle: [
(0, "조식", breakfast.toDomain()),
(1, "중식", lunch.toDomain()),
(2, "석식", dinner.toDomain())
("조식", breakfast.toDomain()),
("중식", lunch.toDomain()),
("석식", dinner.toDomain())
]
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public struct SchoolMealEntity {
}

public struct SchoolMealEntityElement {
public let mealBundle: [(Int, String, MealEntityElement)]
public let mealBundle: [(String, MealEntityElement)]

public init(mealBundle: [(Int, String, MealEntityElement)]) {
public init(mealBundle: [(String, MealEntityElement)]) {
self.mealBundle = mealBundle
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class PiCKAlert: UIViewController {
}
self.clickLogout = clickLogout
super.init(nibName: nil, bundle: nil)
self.modalTransitionStyle = .crossDissolve
self.modalPresentationStyle = .overFullScreen
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand Down
7 changes: 5 additions & 2 deletions Projects/Presentation/Sources/Base/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ open class BaseViewController<ViewModel: BaseViewModel>: UIViewController, UIGes
viewWillAppearRelay.accept(())
bindAction()
}
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
addView()
setLayout()
}
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
configureNavgationBarLayOutSubviews()
setLayoutData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ public class AllTabViewController: BaseViewController<AllTabViewModel> {
) {
owner.logoutRelay.accept(())
}
alert.modalPresentationStyle = .overFullScreen
alert.modalTransitionStyle = .crossDissolve
owner.present(alert, animated: true)
}.disposed(by: disposeBag)
}
Expand Down
36 changes: 12 additions & 24 deletions Projects/Presentation/Sources/Scene/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import Then
import RxSwift
import RxCocoa

import Starscream

import Core
import Domain
import DesignSystem
Expand All @@ -25,7 +23,7 @@ public class HomeViewController: BaseViewController<HomeViewModel> {
width: self.view.frame.width,
height: 0
)
private lazy var timeTableHeight = BehaviorRelay<CGFloat>(value: 0)
private lazy var timeTableHeight = BehaviorRelay<CGFloat>(value: 100)
private lazy var schoolMealHeight = BehaviorRelay<CGFloat>(value: 0)

private let scrollView = UIScrollView().then {
Expand Down Expand Up @@ -242,9 +240,7 @@ public class HomeViewController: BaseViewController<HomeViewModel> {
output.timeTableHeight.asObservable()
.withUnretained(self)
.bind { owner, height in
if height == 0 {
owner.timeTableHeight.accept(100)
} else {
if height != 0 {
owner.timeTableHeight.accept(height)
}

Expand Down Expand Up @@ -314,24 +310,16 @@ public class HomeViewController: BaseViewController<HomeViewModel> {
}

private func setupViewType(type: HomeViewType) {
switch type {
case .timeTable:
self.todaysLabel.text = "오늘의 시간표"
self.schoolMealView.isHidden = true
self.timeTableView.isHidden = false

mainStackView.snp.remakeConstraints {
$0.height.equalTo(self.timeTableHeight.value)
}

case .schoolMeal:
self.todaysLabel.text = "오늘의 급식"
self.timeTableView.isHidden = true
self.schoolMealView.isHidden = false

mainStackView.snp.remakeConstraints {
$0.height.equalTo(self.schoolMealHeight.value)
}
let isTimeTable = (type == .timeTable)
self.todaysLabel.text = isTimeTable ? "오늘의 시간표" : "오늘의 급식"

self.timeTableView.isHidden = !isTimeTable
self.schoolMealView.isHidden = isTimeTable

let height = isTimeTable ? self.timeTableHeight.value : self.schoolMealHeight.value

mainStackView.snp.remakeConstraints {
$0.height.equalTo(height)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Projects/Presentation/Sources/Scene/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class HomeViewModel: BaseViewModel, Stepper {
let applyStatusData: Signal<HomeApplyStatusEntity>
let weekendMealPeriodData: Signal<WeekendMealPeriodEntity>
let timetableData: Driver<[TimeTableEntityElement]>
let schoolMealData: Driver<[(Int, String, MealEntityElement)]>
let schoolMealData: Driver<[(String, MealEntityElement)]>
let noticeListData: Signal<NoticeListEntity>
let selfStudyData: Driver<SelfStudyEntity>
let outingPassData: Signal<OutingPassEntity>
Expand All @@ -76,7 +76,7 @@ public class HomeViewModel: BaseViewModel, Stepper {
private let applyStatusData = PublishRelay<HomeApplyStatusEntity>()
private let weekendMealPeriodData = PublishRelay<WeekendMealPeriodEntity>()
private let timetableData = BehaviorRelay<[TimeTableEntityElement]>(value: [])
private let schoolMealData = BehaviorRelay<[(Int, String, MealEntityElement)]>(value: [])
private let schoolMealData = BehaviorRelay<[(String, MealEntityElement)]>(value: [])
private let outingPassData = PublishRelay<OutingPassEntity>()
private let noticeListData = PublishRelay<NoticeListEntity>()
private let selfStudyData = BehaviorRelay<SelfStudyEntity>(value: [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Domain
import DesignSystem

public class HomeSchoolMealView: BaseView {
private let schoolMealData = BehaviorRelay<[(Int, String, MealEntityElement)]>(value: [])
private let schoolMealData = BehaviorRelay<[(String, MealEntityElement)]>(value: [])

private lazy var collectionViewFlowLayout = UICollectionViewFlowLayout().then {
$0.scrollDirection = .vertical
Expand All @@ -33,7 +33,7 @@ public class HomeSchoolMealView: BaseView {
}

public func setup(
schoolMealData: [(Int, String, MealEntityElement)]
schoolMealData: [(String, MealEntityElement)]
) {
self.schoolMealData.accept(schoolMealData)
}
Expand All @@ -45,9 +45,9 @@ public class HomeSchoolMealView: BaseView {
cellType: SchoolMealHomeCell.self
)) { _, item, cell in
cell.setup(
mealTime: item.1,
menu: item.2.menu,
kcal: item.2.kcal
mealTime: item.0,
menu: item.1.menu,
kcal: item.1.kcal
)
}.disposed(by: disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public class OnboardingViewController: BaseViewController<OnboardingViewModel> {
) {
print("click")
}
alert.modalTransitionStyle = .crossDissolve
alert.modalPresentationStyle = .overFullScreen

owner.present(alert, animated: true)
}.disposed(by: disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ public class SchoolMealViewController: BaseViewController<SchoolMealViewModel> {
)
let output = viewModel.transform(input: input)

output.schoolMealData.asObservable()
output.schoolMealData
.asObservable()
.bind(to: schoolMealCollectionView.rx.items(
cellIdentifier: SchoolMealCollectionViewCell.identifier,
cellType: SchoolMealCollectionViewCell.self
)) { _, item, cell in
cell.setup(
mealTime: item.1,
menu: item.2.menu,
kcal: item.2.kcal
mealTime: item.0,
menu: item.1.menu,
kcal: item.1.kcal
)
}.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class SchoolMealViewModel: BaseViewModel, Stepper {
let schoolMealDate: Observable<String>
}
public struct Output {
let schoolMealData: Driver<[(Int, String, MealEntityElement)]>
let schoolMealData: Driver<[(String, MealEntityElement)]>
}

private let schoolMealData = BehaviorRelay<[(Int, String, MealEntityElement)]>(value: [])
private let schoolMealData = BehaviorRelay<[(String, MealEntityElement)]>(value: [])

public func transform(input: Input) -> Output {
input.schoolMealDate
Expand All @@ -37,9 +37,9 @@ public class SchoolMealViewModel: BaseViewModel, Stepper {
return .never()
}
}
.subscribe(onNext: { [weak self] data in
self?.schoolMealData.accept(data.meals.mealBundle)
})
.bind { data in
self.schoolMealData.accept(data.meals.mealBundle)
}
.disposed(by: disposeBag)

return Output(schoolMealData: schoolMealData.asDriver())
Expand Down

0 comments on commit 1f73b94

Please sign in to comment.