Skip to content

Commit

Permalink
Merge pull request #121 from DSM-PICK/feature/#119-home_refact
Browse files Browse the repository at this point in the history
refact :: [#119] 홈 리팩토링
  • Loading branch information
cyj513 authored Nov 13, 2024
2 parents aec3c4d + ecac61f commit 6000c82
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Projects/Data/Sources/API/NoticeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Domain
import AppNetwork

public enum NoticeAPI {
case fetchTodayNoticeList
case fetchNoticeList
case fetchSimpleNoticeList
case fetchDetailNotice(id: UUID)
}

Expand All @@ -21,10 +21,10 @@ extension NoticeAPI: PiCKAPI {

public var urlPath: String {
switch self {
case .fetchTodayNoticeList:
return "/today"
case .fetchNoticeList:
return "/simple"
case .fetchSimpleNoticeList:
return "/today"
case .fetchDetailNotice(let id):
return "/\(id)"
}
Expand Down
3 changes: 3 additions & 0 deletions Projects/Data/Sources/DI/UseCaseAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public final class UseCaseAssembly: Assembly {
container.register(FetchNoticeListUseCase.self) { resolver in
FetchNoticeListUseCase(repository: resolver.resolve(NoticeRepository.self)!)
}
container.register(FetchSimpleNoticeListUseCase.self) { resolver in
FetchSimpleNoticeListUseCase(repository: resolver.resolve(NoticeRepository.self)!)
}
container.register(FetchDetailNoticeUseCase.self) { resolver in
FetchDetailNoticeUseCase(repository: resolver.resolve(NoticeRepository.self)!)
}
Expand Down
5 changes: 0 additions & 5 deletions Projects/Data/Sources/DataSource/HomeDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ class HomeDataSourceImpl: WebSocketDelegate, HomeDataSource {
connectSocket()
}

deinit {
socket?.disconnect()
socket?.delegate = nil
}

func connectSocket() {
let url = URL(string: "\(URLUtil.socketBaseURL)/main")
var request = URLRequest(url: url!)
Expand Down
6 changes: 6 additions & 0 deletions Projects/Data/Sources/DataSource/NoticeDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Domain

protocol NoticeDataSource {
func fetchNoticeList() -> Single<Response>
func fetchSimpleNoticeList() -> Single<Response>
func fetchDetailNotice(id: UUID) -> Single<Response>
}

Expand All @@ -18,6 +19,11 @@ class NoticeDataSourceImpl: BaseDataSource<NoticeAPI>, NoticeDataSource {
.filterSuccessfulStatusCodes()
}

func fetchSimpleNoticeList() -> Single<Response> {
return request(.fetchSimpleNoticeList)
.filterSuccessfulStatusCodes()
}

func fetchDetailNotice(id: UUID) -> Single<Response> {
return request(.fetchDetailNotice(id: id))
.filterSuccessfulStatusCodes()
Expand Down
6 changes: 6 additions & 0 deletions Projects/Data/Sources/Repository/NoticeRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class NoticeRepositoryImpl: NoticeRepository {
.map { $0.toDomain() }
}

func fetchSimpleNoticeList() -> Single<NoticeListEntity> {
return remoteDataSource.fetchSimpleNoticeList()
.map(NoticeListDTO.self)
.map { $0.toDomain() }
}

func fetchDetailNotice(id: UUID) -> Single<DetailNoticeEntity> {
return remoteDataSource.fetchDetailNotice(id: id)
.map(DetailNoticeDTO.self)
Expand Down
1 change: 1 addition & 0 deletions Projects/Domain/Sources/Repository/NoticeRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import RxSwift

public protocol NoticeRepository {
func fetchNoticeList() -> Single<NoticeListEntity>
func fetchSimpleNoticeList() -> Single<NoticeListEntity>
func fetchDetailNotice(id: UUID) -> Single<DetailNoticeEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

import RxSwift

public class FetchSimpleNoticeListUseCase {
let repository: NoticeRepository

public init(repository: NoticeRepository) {
self.repository = repository
}

public func execute() -> Single<NoticeListEntity> {
return repository.fetchSimpleNoticeList()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class PresentationAssembly: Assembly {
fetchWeekendMealPeriodUseCase: resolver.resolve(FetchWeekendMealPeriodUseCase.self)!,
timeTableUseCase: resolver.resolve(FetchTodayTimeTableUseCase.self)!,
schoolMealUseCase: resolver.resolve(FetchSchoolMealUseCase.self)!,
noticeListUseCase: resolver.resolve(FetchNoticeListUseCase.self)!,
noticeListUseCase: resolver.resolve(FetchSimpleNoticeListUseCase.self)!,
selfStudyUseCase: resolver.resolve(FetchSelfStudyUseCase.self)!,
fetchOutingPassUseCase: resolver.resolve(FetchOutingPassUseCase.self)!,
fetchEarlyLeavePassUseCase: resolver.resolve(FetchEarlyLeavePassUseCase.self)!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public class HomeViewController: BaseViewController<HomeViewModel> {
output.viewMode.asObservable()
.withUnretained(self)
.bind { owner, data in
owner.setupViewType(type: data)
owner.homeViewType = data
}.disposed(by: disposeBag)

Expand Down Expand Up @@ -195,6 +194,13 @@ public class HomeViewController: BaseViewController<HomeViewModel> {

output.noticeListData
.asObservable()
.do(onNext: {
if $0.isEmpty {
self.noticeStackView.isHidden = true
} else {
self.noticeStackView.isHidden = false
}
})
.bind(to: noticeCollectionView.rx.items(
cellIdentifier: NoticeCollectionViewCell.identifier,
cellType: NoticeCollectionViewCell.self
Expand Down Expand Up @@ -255,9 +261,6 @@ public class HomeViewController: BaseViewController<HomeViewModel> {
output.noticeViewHeight.asObservable()
.withUnretained(self)
.bind { owner, height in
if height == 0 {
owner.noticeStackView.isHidden = true
}
owner.noticeCollectionView.snp.remakeConstraints {
$0.height.equalTo(height)
}
Expand Down
17 changes: 8 additions & 9 deletions Projects/Presentation/Sources/Scene/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class HomeViewModel: BaseViewModel, Stepper {
private let fetchWeekendMealPeriodUseCase: FetchWeekendMealPeriodUseCase
private let timeTableUseCase: FetchTodayTimeTableUseCase
private let schoolMealUseCase: FetchSchoolMealUseCase
private let noticeListUseCase: FetchNoticeListUseCase
private let noticeListUseCase: FetchSimpleNoticeListUseCase
private let selfStudyUseCase: FetchSelfStudyUseCase
private let fetchOutingPassUseCase: FetchOutingPassUseCase
private let fetchEarlyLeavePassUseCase: FetchEarlyLeavePassUseCase
Expand All @@ -29,7 +29,7 @@ public class HomeViewModel: BaseViewModel, Stepper {
fetchWeekendMealPeriodUseCase: FetchWeekendMealPeriodUseCase,
timeTableUseCase: FetchTodayTimeTableUseCase,
schoolMealUseCase: FetchSchoolMealUseCase,
noticeListUseCase: FetchNoticeListUseCase,
noticeListUseCase: FetchSimpleNoticeListUseCase,
selfStudyUseCase: FetchSelfStudyUseCase,
fetchOutingPassUseCase: FetchOutingPassUseCase,
fetchEarlyLeavePassUseCase: FetchEarlyLeavePassUseCase,
Expand Down Expand Up @@ -63,7 +63,7 @@ public class HomeViewModel: BaseViewModel, Stepper {
let weekendMealPeriodData: Signal<WeekendMealPeriodEntity>
let timetableData: Driver<[TimeTableEntityElement]>
let schoolMealData: Driver<[(Int, String, MealEntityElement)]>
let noticeListData: Driver<NoticeListEntity>
let noticeListData: Signal<NoticeListEntity>
let selfStudyData: Driver<SelfStudyEntity>
let outingPassData: Signal<OutingPassEntity>
let timeTableHeight: Driver<CGFloat>
Expand All @@ -78,7 +78,7 @@ public class HomeViewModel: BaseViewModel, Stepper {
private let timetableData = BehaviorRelay<[TimeTableEntityElement]>(value: [])
private let schoolMealData = BehaviorRelay<[(Int, String, MealEntityElement)]>(value: [])
private let outingPassData = PublishRelay<OutingPassEntity>()
private let noticeListData = BehaviorRelay<NoticeListEntity>(value: [])
private let noticeListData = PublishRelay<NoticeListEntity>()
private let selfStudyData = BehaviorRelay<SelfStudyEntity>(value: [])
private let timeTableHeight = BehaviorRelay<CGFloat>(value: 0)
private let schoolMealHeight = BehaviorRelay<CGFloat>(value: 0)
Expand Down Expand Up @@ -171,10 +171,9 @@ public class HomeViewModel: BaseViewModel, Stepper {
return .never()
}
}
.subscribe(onNext: { [weak self] noticeData in
let value = Array(noticeData.prefix(5))
self?.noticeListData.accept(value)
let height = CGFloat(value.count)
.subscribe(onNext: { [weak self] data in
self?.noticeListData.accept(data)
let height = CGFloat(data.count)
self?.noticeViewHeight.accept(height * 86)
}).disposed(by: disposeBag)

Expand Down Expand Up @@ -246,7 +245,7 @@ public class HomeViewModel: BaseViewModel, Stepper {
weekendMealPeriodData: weekendMealPeriodData.asSignal(),
timetableData: timetableData.asDriver(),
schoolMealData: schoolMealData.asDriver(),
noticeListData: noticeListData.asDriver(),
noticeListData: noticeListData.asSignal(),
selfStudyData: selfStudyData.asDriver(),
outingPassData: outingPassData.asSignal(),
timeTableHeight: timeTableHeight.asDriver(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class PiCKHomeSelfStudyBannerView: BaseView {
selfStudyTeacherData: SelfStudyEntity
) {
if selfStudyTeacherData.isEmpty {
// self.floorStackView.isHidden = true
// self.teacherStackView.isHidden = true
self.explainLabel.isHidden = true
self.emptySelfStudyLabel.isHidden = false
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public class NoticeCollectionViewCell: BaseCollectionViewCell<NoticeListEntityEl
self.id = model.id
self.titleLabel.text = model.title
self.daysAgoLabel.text = model.createAt
// self.newNoticeIcon.isHidden = isNew
if model.createAt == Date().toString(type: .fullDate) {
self.newNoticeIcon.isHidden = false
}
}

public override func layout() {
Expand Down

0 comments on commit 6000c82

Please sign in to comment.