Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

자습실 이용 시간 목록 API 연동 #227

Merged
merged 11 commits into from
Mar 19, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public extension AppComponent {
var fetchMyStudyRoomAppItemsUseCase: any FetchMyStudyRoomAppItemsUseCase {
FetchMyStudyRoomAppItemsUseCaseImpl(studyRoomsRepository: studyRoomsRepository)
}

var fetchStudyroomTimeListUseCase: any FetchStudyroomTimeListUseCase {
shared {
FetchStudyroomTimeListUseCaseImpl(studyRoomsRepository: studyRoomsRepository)
}
}
}
5 changes: 5 additions & 0 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ private class StudyRoomListDependencyef56e26c25d5de596604Provider: StudyRoomList
var fetchStudyAvailableTimeUseCase: any FetchStudyAvailableTimeUseCase {
return appComponent.fetchStudyAvailableTimeUseCase
}
var fetchStudyroomTimeListUseCase: any FetchStudyroomTimeListUseCase {
return appComponent.fetchStudyroomTimeListUseCase
}
var studyRoomDetailComponent: StudyRoomDetailComponent {
return appComponent.studyRoomDetailComponent
}
Expand Down Expand Up @@ -541,6 +544,7 @@ extension AppComponent: Registration {
localTable["applyStudyRoomSeatUseCase-any ApplyStudyRoomSeatUseCase"] = { [unowned self] in self.applyStudyRoomSeatUseCase as Any }
localTable["cancelStudyRoomSeatUseCase-any CancelStudyRoomSeatUseCase"] = { [unowned self] in self.cancelStudyRoomSeatUseCase as Any }
localTable["fetchMyStudyRoomAppItemsUseCase-any FetchMyStudyRoomAppItemsUseCase"] = { [unowned self] in self.fetchMyStudyRoomAppItemsUseCase as Any }
localTable["fetchStudyroomTimeListUseCase-any FetchStudyroomTimeListUseCase"] = { [unowned self] in self.fetchStudyroomTimeListUseCase as Any }
localTable["localAuthDataSource-any LocalAuthDataSource"] = { [unowned self] in self.localAuthDataSource as Any }
localTable["remoteAuthDataSource-any RemoteAuthDataSource"] = { [unowned self] in self.remoteAuthDataSource as Any }
localTable["authRepository-any AuthRepository"] = { [unowned self] in self.authRepository as Any }
Expand Down Expand Up @@ -728,6 +732,7 @@ extension StudyRoomListComponent: Registration {
public func registerItems() {
keyPathToName[\StudyRoomListDependency.fetchStudyRoomListUseCase] = "fetchStudyRoomListUseCase-any FetchStudyRoomListUseCase"
keyPathToName[\StudyRoomListDependency.fetchStudyAvailableTimeUseCase] = "fetchStudyAvailableTimeUseCase-any FetchStudyAvailableTimeUseCase"
keyPathToName[\StudyRoomListDependency.fetchStudyroomTimeListUseCase] = "fetchStudyroomTimeListUseCase-any FetchStudyroomTimeListUseCase"
keyPathToName[\StudyRoomListDependency.studyRoomDetailComponent] = "studyRoomDetailComponent-StudyRoomDetailComponent"
}
}
Expand Down
4 changes: 2 additions & 2 deletions Projects/App/WatchApp/Support/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1</string>
<key>WKWatchKitApp</key>
<true/>
<key>CFBundleVersion</key>
<string>1</string>
<key>UISupportedInterfaceOrientations</key>
Expand All @@ -29,5 +27,7 @@
</array>
<key>WKCompanionAppBundleIdentifier</key>
<string>com.team.aliens.DMS-Aliens</string>
<key>WKWatchKitApp</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NeedleFoundation
public protocol StudyRoomListDependency: Dependency {
var fetchStudyRoomListUseCase: any FetchStudyRoomListUseCase { get }
var fetchStudyAvailableTimeUseCase: any FetchStudyAvailableTimeUseCase { get }
var fetchStudyroomTimeListUseCase: any FetchStudyroomTimeListUseCase { get }
var studyRoomDetailComponent: StudyRoomDetailComponent { get }
}

Expand All @@ -14,7 +15,8 @@ public final class StudyRoomListComponent: Component<StudyRoomListDependency> {
StudyRoomListView(
viewModel: .init(
fetchStudyRoomListUseCase: dependency.fetchStudyRoomListUseCase,
fetchStudyAvailableTimeUseCase: dependency.fetchStudyAvailableTimeUseCase
fetchStudyAvailableTimeUseCase: dependency.fetchStudyAvailableTimeUseCase,
fetchStudyroomTimeListUseCase: dependency.fetchStudyroomTimeListUseCase
),
studyRoomDetailComponent: dependency.studyRoomDetailComponent
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ struct StudyRoomListView: View {
sheetCornerRadiusValue: 8
) {
DeferView {
StudyroomTimeListView(
isClicked: false,
okButtonAction: {
withAnimation {
viewModel.isStudyTimeBottomSheet = false
}
}
)
StudyroomTimeListView(viewModel: viewModel)
}
}
.dmsToast(isShowing: $viewModel.isErrorOcuured, message: viewModel.errorMessage, style: .error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ final class StudyRoomListViewModel: BaseViewModel {
@Published var isStudyRoomTime = true
@Published var isShowingToast = false
@Published var toastMessage = ""
@Published var studyAvailableTime: StudyAvailableTimeEntity?

@Published var isNavigateDetail: Bool = false
@Published var isStudyTimeBottomSheet: Bool = false

@Published var studyroomTimeList = StudyroomTimeListEntity(timeSlots: [])
@Published var selectedTimeEntity: TimeSlotsEntity?
@Published var studyAvailableTime: StudyAvailableTimeEntity?
@Published var studyRoomDetail: StudyRoomEntity = .init(
id: "",
floor: 0,
Expand All @@ -36,13 +40,16 @@ final class StudyRoomListViewModel: BaseViewModel {

private let fetchStudyRoomListUseCase: any FetchStudyRoomListUseCase
private let fetchStudyAvailableTimeUseCase: any FetchStudyAvailableTimeUseCase
private let fetchStudyroomTimeListUseCase: any FetchStudyroomTimeListUseCase

public init(
fetchStudyRoomListUseCase: any FetchStudyRoomListUseCase,
fetchStudyAvailableTimeUseCase: any FetchStudyAvailableTimeUseCase
fetchStudyAvailableTimeUseCase: any FetchStudyAvailableTimeUseCase,
fetchStudyroomTimeListUseCase: any FetchStudyroomTimeListUseCase
) {
self.fetchStudyRoomListUseCase = fetchStudyRoomListUseCase
self.fetchStudyAvailableTimeUseCase = fetchStudyAvailableTimeUseCase
self.fetchStudyroomTimeListUseCase = fetchStudyroomTimeListUseCase
super.init()
}

Expand All @@ -62,6 +69,14 @@ final class StudyRoomListViewModel: BaseViewModel {
}
}

func fetchStudyroomTimeList() {
addCancellable(
fetchStudyroomTimeListUseCase.execute()
) { [weak self] studyroomTimeList in
self?.studyroomTimeList = studyroomTimeList
}
}

func onAppear() {
fetchStudyRoomList()
fetchStudyAvailableTime()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import DomainModule
import DesignSystem
import SwiftUI

struct StudyroomTimeListCellView: View {
@State var isClicked: Bool = false
DSMInhyeKang marked this conversation as resolved.
Show resolved Hide resolved
var timeSlots: TimeSlotsEntity
let buttonAction: () -> Void

public init(
isClicked: Bool,
timeSlots: TimeSlotsEntity,
buttonAction: @escaping () -> Void
) {
self.isClicked = isClicked
self.timeSlots = timeSlots
self.buttonAction = buttonAction
}

var body: some View {
HStack {
Button {
if !isClicked {
buttonAction()
}
} label: {
Text("\(timeSlots.startTime) ~ \(timeSlots.endTime)")
.padding(.horizontal, 16)
.padding(.vertical, 14)
.dmsFont(
.etc(.button),
color: isClicked ? .GrayScale.gray1 : .GrayScale.gray4
)
.background(
isClicked ? Color.PrimaryVariant.primary : Color.GrayScale.gray1
)
}
.overlay(
RoundedRectangle(cornerRadius: 5)
.inset(by: 1)
.stroke(
isClicked ? Color.System.primary : Color.GrayScale.gray4,
lineWidth: 2
)
)
.cornerRadius(5)
.padding(.horizontal, 5)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import DesignSystem
import DomainModule
import SwiftUI

struct StudyroomTimeListView: View {
@StateObject var viewModel: StudyRoomListViewModel
baekteun marked this conversation as resolved.
Show resolved Hide resolved

var body: some View {
VStack(alignment: .leading, spacing: 37) {
Text("시간")
.dmsFont(.title(.subTitle1), color: .GrayScale.gray10)
.frame(height: 28)
.padding(.top, 40)
.padding(.leading, 24)

ScrollView(.horizontal, showsIndicators: false) {
LazyHStack {
ForEach(viewModel.studyroomTimeList.timeSlots, id: \.self) { timeSlots in
StudyroomTimeListCellView(
isClicked: timeSlots.id == viewModel.selectedTimeEntity?.id,
timeSlots: timeSlots,
buttonAction: {
viewModel.selectedTimeEntity = timeSlots
}
)
}
}
.padding(.horizontal, 19)
.padding(.bottom, 10)
}

DMSWideButton(text: "확인", style: .contained, color: .PrimaryVariant.primary) {
viewModel.isStudyTimeBottomSheet = false
}
.padding(.horizontal, 24)
.padding(.bottom)
}
.onAppear {
viewModel.fetchStudyroomTimeList()
}
}
}

This file was deleted.

9 changes: 7 additions & 2 deletions Projects/Services/APIKit/Sources/StudyRoomsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum StudyRoomsAPI {
case fetchMyStudyRoomApplicationItems
case applyStudyRoomSeat(seatID: String)
case cancelStudyRoomSeat
case fetchStudyroomTimeList
}

extension StudyRoomsAPI: DmsAPI {
Expand Down Expand Up @@ -39,13 +40,17 @@ extension StudyRoomsAPI: DmsAPI {

case .fetchMyStudyRoomApplicationItems:
return "/my"

case .fetchStudyroomTimeList:
return "/time-slots"
}
}

public var method: Moya.Method {
switch self {
case .fetchStudyAvailableTime, .fetchSeatTypes,
.fetchStudyRoomList, .fetchDetailStudyRoom, .fetchMyStudyRoomApplicationItems:
case .fetchStudyAvailableTime, .fetchSeatTypes, .fetchStudyRoomList,
.fetchDetailStudyRoom, .fetchMyStudyRoomApplicationItems,
.fetchStudyroomTimeList:
return .get

case .applyStudyRoomSeat:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public struct FetchStudyRoomTimeListResponseDTO: Decodable {
public init(timeSlots: [TimeSlotsResponseDTO]) {
self.timeSlots = timeSlots
}

public let timeSlots: [TimeSlotsResponseDTO]

enum CodingKeys: String, CodingKey {
case timeSlots = "time_slots"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation

public struct TimeSlotsResponseDTO: Decodable {
public init(
id: String,
startTime: String,
endTime: String
) {
self.id = id
self.startTime = startTime
self.endTime = endTime
}

public let id: String
public let startTime: String
public let endTime: String

enum CodingKeys: String, CodingKey {
case id
case startTime = "start_time"
case endTime = "end_time"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public struct StudyRoomsRepositoryImpl: StudyRoomsRepository {
public func fetchMyStudyRoomApplicationItems() -> AnyPublisher<MyStudyRoomAppItemsEntity, DmsError> {
remoteStudyRoomsDataSource.fetchMyRemainApplicationItems()
}

public func fetchStudyroomTimeList() -> AnyPublisher<StudyroomTimeListEntity, DmsError> {
remoteStudyRoomsDataSource.fetchStudyroomTimeList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Combine
import DataMappingModule
import DomainModule
import ErrorModule

public struct FetchStudyroomTimeListUseCaseImpl: FetchStudyroomTimeListUseCase {
private let studyRoomsRepository: any StudyRoomsRepository

public init(studyRoomsRepository: any StudyRoomsRepository) {
self.studyRoomsRepository = studyRoomsRepository
}

public func execute() -> AnyPublisher<StudyroomTimeListEntity, DmsError> {
studyRoomsRepository.fetchStudyroomTimeList()
}
}
Loading