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

186 [Bus] Apply API Changes #190

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let project = Project(
infoPlist: .extendingDefault(
with: [
"CFBundleDisplayName": "도담도담",
"CFBundleShortVersionString": "3.3.1",
"CFBundleShortVersionString": "3.3.4",
"CFBundleVersion": "1",
"UISupportedInterfaceOrientations": ["UIInterfaceOrientationPortrait"],
"UIMainStoryboardFile": "",
Expand Down
12 changes: 2 additions & 10 deletions Projects/Data/DataSource/Source/Bus/BusDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@ public struct BusDataSource: DataSourceProtocol {
return response.data
}

public func postApplyBus(id: Int) async throws {
_ = try await remote.postApplyBus(id: id)
}

public func patchAppliedBus(id: Int) async throws {
_ = try await remote.patchAppliedBus(id: id)
}

public func deleteAppliedBus(id: Int) async throws {
_ = try await remote.deleteAppliedBus(id: id)
public func applyBus(id: Int) async throws {
_ = try await remote.applyBus(id: id)
}
}
12 changes: 2 additions & 10 deletions Projects/Data/Network/Source/Remote/Bus/BusRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ public struct BusRemote: RemoteProtocol {
try await self.request(target: .fetchAppliedBus, res: BusResponse?.self)
}

public func postApplyBus(id: Int) async throws -> DefaultResponse {
try await self.request(target: .postApplyBus(id: id))
}

public func patchAppliedBus(id: Int) async throws -> DefaultResponse {
try await self.request(target: .patchAppliedBus(id: id))
}

public func deleteAppliedBus(id: Int) async throws -> DefaultResponse {
try await self.request(target: .deleteAppliedBus(id: id))
public func applyBus(id: Int) async throws -> DefaultResponse {
try await self.request(target: .applyBus(id: id))
}
}
18 changes: 4 additions & 14 deletions Projects/Data/Network/Source/Service/Bus/BusService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ enum BusService: ServiceProtocol {

case fetchAllBus
case fetchAppliedBus
case postApplyBus(id: Int)
case patchAppliedBus(id: Int)
case deleteAppliedBus(id: Int)
case applyBus(id: Int)
}

extension BusService {
Expand All @@ -26,19 +24,15 @@ extension BusService {
switch self {
case .fetchAllBus: ""
case .fetchAppliedBus: "/apply"
case let .postApplyBus(id): "/apply/\(id)"
case let .patchAppliedBus(id): "/apply/\(id)"
case let .deleteAppliedBus(id): "/apply/\(id)"
case let .applyBus(id): "/apply/status/\(id)"
}
}

var method: Moya.Method {
switch self {
case .fetchAllBus: .get
case .fetchAppliedBus: .get
case .postApplyBus: .post
case .patchAppliedBus: .patch
case .deleteAppliedBus: .delete
case .applyBus: .patch
}
}

Expand All @@ -48,11 +42,7 @@ extension BusService {
.requestPlain
case .fetchAppliedBus:
.requestPlain
case .postApplyBus:
.requestPlain
case .patchAppliedBus:
.requestPlain
case .deleteAppliedBus:
case .applyBus:
.requestPlain
}
}
Expand Down
12 changes: 2 additions & 10 deletions Projects/Data/Repository/Source/Bus/BusRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@ public struct BusRepositoryImpl: BusRepository {
try await dataSource.fetchAppliedBus()
}

public func postApplyBus(id: Int) async throws {
try await dataSource.postApplyBus(id: id)
}

public func patchAppliedBus(id: Int) async throws {
try await dataSource.patchAppliedBus(id: id)
}

public func deleteAppliedBus(id: Int) async throws {
try await dataSource.deleteAppliedBus(id: id)
public func applyBus(id: Int) async throws {
try await dataSource.applyBus(id: id)
}
}
6 changes: 1 addition & 5 deletions Projects/Domain/Source/Repository/Bus/BusRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,5 @@ public protocol BusRepository: RepositoryProtocol {

func fetchAppliedBus() async throws -> BusResponse?

func postApplyBus(id: Int) async throws

func patchAppliedBus(id: Int) async throws

func deleteAppliedBus(id: Int) async throws
func applyBus(id: Int) async throws
}
15 changes: 8 additions & 7 deletions Projects/Feature/Source/Bus/Apply/BusApplyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ struct BusApplyView: View {
id: \.self
) { bus in
Button {
guard viewModel.selectedBus?.id ?? 0 != bus.id else {
if viewModel.selectedBus?.id == bus.id {
viewModel.selectedBus = nil
return
}
withAnimation(.spring(duration: 0.25)) {
} else {
viewModel.selectedBus = bus
}
} label: {
Expand All @@ -52,8 +50,9 @@ struct BusApplyView: View {
.padding([.bottom, .horizontal], 16)
}
.task {
await viewModel.fetchBuses()
await viewModel.fetchAppledBus()
async let fetchBuses: () = viewModel.fetchBuses()
async let fetchAppledBus: () = viewModel.fetchAppledBus()
_ = await [fetchBuses, fetchAppledBus]
}
.onChange(of: viewModel.showNotFoundBus) {
if $0 {
Expand All @@ -66,7 +65,9 @@ struct BusApplyView: View {
}
.onChange(of: viewModel.dialogMessage) {
let dialog = Dialog(title: $0)
.primaryButton("확인")
.primaryButton("확인") {
flow.pop()
}
self.dialog.present(dialog)
}
}
Expand Down
69 changes: 16 additions & 53 deletions Projects/Feature/Source/Bus/Apply/BusApplyViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BusApplyViewModel: ObservableObject {
showNotFoundBus = true
}
} catch {
print("\(#function)")
print(#function)
print(error)
}
}
Expand All @@ -41,72 +41,35 @@ class BusApplyViewModel: ObservableObject {
appliedBus = try await busRepository.fetchAppliedBus()
self.selectedBus = appliedBus
} catch {
print("\(#function)")
print(#function)
print(error)
}
}

@MainActor
func completeBus() async {
print("\(#function)")
defer {
Task {
await fetchBuses()
await fetchAppledBus()
}
}
guard let selectedBus else {
await deleteBus(id: appliedBus?.id ?? 0)
return
}
guard let appliedBus else {
await postBus(id: selectedBus.id)
return
}
guard selectedBus != appliedBus else {
await deleteBus(id: selectedBus.id)
return
}
guard selectedBus.applyCount < selectedBus.peopleLimit else {
dialogMessage = "버스가 만석이에요"
return
print(#function)

if let selectedBus {
await self.applyBus(id: selectedBus.id)
} else if let appliedBus {
await self.applyBus(id: appliedBus.id)
}
await patchBus(id: selectedBus.id)

dialogMessage = "버스 신청에 성공했어요"

async let fetchBuses: () = fetchBuses()
async let fetchAppledBus: () = fetchAppledBus()
_ = await [fetchBuses, fetchAppledBus]
}

@MainActor
private func postBus(id: Int) async {
private func applyBus(id: Int) async {
do {
try await busRepository.postApplyBus(id: id)
self.appliedBus = selectedBus
dialogMessage = "버스 신청에 성공했어요"
try await busRepository.applyBus(id: id)
} catch {
dialogMessage = "버스 신청에 실패했어요"
print(error)
}
}

@MainActor
private func deleteBus(id: Int) async {
do {
try await busRepository.deleteAppliedBus(id: id)
self.appliedBus = nil
dialogMessage = "버스 삭제에 성공했어요"
} catch {
dialogMessage = "버스 삭제에 실패했어요"
print(error)
}
}

@MainActor
private func patchBus(id: Int) async {
do {
try await busRepository.patchAppliedBus(id: id)
dialogMessage = "버스 변경에 성공했어요"
self.appliedBus = selectedBus
} catch {
dialogMessage = "버스 변경에 실패했어요"
print(error)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ struct BusApplyCell: View {
if bus.id == selectedBus?.id ?? 0 {
Image(icon: .checkmark)
.resizable()
.frame(width: 32, height: 32)
.frame(width: 20, height: 20)
.foreground(DodamColor.Primary.normal)
}
}
.frame(height: 40)
.padding(.horizontal, 8)
.animation(.spring(duration: 0.2), value: selectedBus)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct CategoryButton: View {
.foreground(isSelected ? DodamColor.Static.white : DodamColor.Label.alternative)
.background(isSelected ? DodamColor.Primary.normal : DodamColor.Background.normal)
.cornerRadius(30)
.overlay{
.overlay {
if !isSelected {
RoundedRectangle(cornerRadius: 30)
.dodamStroke(DodamColor.Line.alternative, lineWidth: 1)
Expand Down
3 changes: 0 additions & 3 deletions Projects/Feature/Source/Out/OutApply/OutApplyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,5 @@ struct OutApplyView: View {
.padding(.bottom, 8)
.padding(.horizontal, 16)
}
.task {
await viewModel.onAppear()
}
}
}
20 changes: 12 additions & 8 deletions Projects/Feature/Source/Out/OutApply/OutApplyViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ class OutApplyViewModel: ObservableObject {
// MARK: - State
@Published var reasonText: String = ""
@Published var dateAt: Date = Date()
@Published var startAt: Date = Date()
@Published var endAt: Date = Date()
@Published var startAt: Date = {
var components = DateComponents()
components.hour = 15
components.minute = 50
return Calendar.current.date(from: components)!
}()
@Published var endAt: Date = {
var components = DateComponents()
components.hour = 18
components.minute = 20
return Calendar.current.date(from: components)!
}()

// MARK: - Repository
@Inject var outGoingRepository: any OutGoingRepository
@Inject var outSleepingRepository: any OutSleepingRepository

// MARK: - Method
@MainActor
func onAppear() async {
startAt = Date()
endAt = startAt
}

@MainActor
func postOutGoing(dinnerOrNot: Bool) async {
do {
Expand Down
4 changes: 2 additions & 2 deletions Tuist/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Team-B1ND/dds-ios",
"state" : {
"revision" : "a81902aa7680f1ed2392bee0999f588d3d1d4a8b",
"version" : "0.2.22"
"revision" : "fd07c7763938d95d03228d1ccb6a7cfc4cbe7c66",
"version" : "0.2.27"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import PackageDescription
let package = Package(
name: "PackageName",
dependencies: [
.package(url: "https://github.com/Team-B1ND/dds-ios", exact: "0.2.22"),
.package(url: "https://github.com/Team-B1ND/dds-ios", exact: "0.2.27"),
.package(url: "https://github.com/Moya/Moya", from: "15.0.0"),
.package(url: "https://github.com/Swinject/Swinject.git", from: "2.8.0"),
.package(url: "https://github.com/Mercen-Lee/FlowKit", branch: "main"),
Expand Down