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

[Bus] Create bus screen #79

Merged
merged 15 commits into from
Apr 2, 2024
1 change: 1 addition & 0 deletions data/bus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
20 changes: 20 additions & 0 deletions data/bus/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import com.b1nd.dodam.dsl.android

plugins {
alias(libs.plugins.dodam.android)
alias(libs.plugins.dodam.android.kotlin)
alias(libs.plugins.dodam.android.hilt)
}

android {
namespace = "com.b1nd.dodam.data.bus"

defaultConfig {
consumerProguardFiles("consumer-rules.pro")
}
}

dependencies {
implementation(projects.common)
implementation(projects.network.bus)
}
18 changes: 18 additions & 0 deletions data/bus/src/main/java/com/b1nd/dodam/bus/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.b1nd.dodam.bus.di

import com.b1nd.dodam.bus.repository.BusRepository
import com.b1nd.dodam.bus.repositoryimpl.BusRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface RepositoryModule {

@Binds
@Singleton
fun bindsBusRepository(busRepositoryImpl: BusRepositoryImpl): BusRepository
}
21 changes: 21 additions & 0 deletions data/bus/src/main/java/com/b1nd/dodam/bus/model/Bus.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.b1nd.dodam.bus.model

data class Bus(
val applyCount: Int,
val busName: String,
val description: String,
val id: Int,
val leaveTime: String,
val peopleLimit: Int,
val timeRequired: String,
)

fun BusResponse.toModel() = Bus(
applyCount = this.applyCount,
busName = this.busName,
description = this.description,
id = this.id,
leaveTime = this.leaveTime,
peopleLimit = this.peopleLimit,
timeRequired = this.timeRequired,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.b1nd.dodam.bus.repository

import com.b1nd.dodam.bus.model.Bus
import com.b1nd.dodam.common.result.Result
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.flow.Flow

interface BusRepository {
fun getBusList(): Flow<Result<ImmutableList<Bus>>>
fun applyBus(id: Int): Flow<Result<Unit>>
fun deleteBus(id: Int): Flow<Result<Unit>>
fun updateBus(id: Int): Flow<Result<Unit>>
fun getMyBus(): Flow<Result<Bus>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.b1nd.dodam.bus.repositoryimpl

import com.b1nd.dodam.bus.datasource.BusDataSource
import com.b1nd.dodam.bus.model.Bus
import com.b1nd.dodam.bus.model.toModel
import com.b1nd.dodam.bus.repository.BusRepository
import com.b1nd.dodam.common.Dispatcher
import com.b1nd.dodam.common.DispatcherType
import com.b1nd.dodam.common.result.Result
import com.b1nd.dodam.common.result.asResult
import javax.inject.Inject
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class BusRepositoryImpl @Inject constructor(
private val busDataSource: BusDataSource,
@Dispatcher(DispatcherType.IO) private val dispatcher: CoroutineDispatcher,
) : BusRepository {
override fun getBusList(): Flow<Result<ImmutableList<Bus>>> {
return flow {
emit(
busDataSource.getBusList().map { it.toModel() }.toImmutableList(),
)
}.asResult().flowOn(dispatcher)
}

override fun applyBus(id: Int): Flow<Result<Unit>> {
return flow {
emit(
busDataSource.applyBus(id),
)
}.asResult().flowOn(dispatcher)
}

override fun deleteBus(id: Int): Flow<Result<Unit>> {
return flow {
emit(
busDataSource.deleteBus(id),
)
}.asResult().flowOn(dispatcher)
}

override fun updateBus(id: Int): Flow<Result<Unit>> {
return flow {
emit(
busDataSource.updateBus(id),
)
}.asResult().flowOn(dispatcher)
}

override fun getMyBus(): Flow<Result<Bus>> {
return flow {
emit(
busDataSource.getMyBus().toModel(),
)
}.asResult().flowOn(dispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.datetime.LocalDate

data class WakeupSong(
val id: Long,
val thumbnailUrl: String,
val thumbnail: String,
val videoTitle: String,
val videoId: String,
val videoUrl: String,
Expand All @@ -17,7 +17,7 @@ data class WakeupSong(

internal fun WakeupSongResponse.toModel(): WakeupSong = WakeupSong(
id = id,
thumbnailUrl = thumbnailUrl,
thumbnail = thumbnail,
videoTitle = videoTitle,
videoId = videoId,
videoUrl = videoUrl,
Expand Down
1 change: 1 addition & 0 deletions dodam-student/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
implementation(projects.featureStudent.main)
implementation(projects.feature.register)
implementation(projects.feature.login)
implementation(projects.featureStudent.bus)
implementation(projects.featureStudent.nightstudy)
implementation(projects.featureStudent.outing)
implementation(projects.featureStudent.askOut)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.b1nd.dodam.asknightstudy.navigation.askNightStudyScreen
import com.b1nd.dodam.asknightstudy.navigation.navigateToAskNightStudy
import com.b1nd.dodam.askout.navigation.askOutScreen
import com.b1nd.dodam.askout.navigation.navigateToAskOut
import com.b1nd.dodam.bus.navigation.busScreen
import com.b1nd.dodam.bus.navigation.navigateToBus
import com.b1nd.dodam.login.navigation.loginScreen
import com.b1nd.dodam.login.navigation.navigationToLogin
import com.b1nd.dodam.nightstudy.navigation.nightStudyScreen
Expand Down Expand Up @@ -56,7 +58,7 @@ fun DodamApp(isLogin: Boolean, deleteToken: () -> Unit, navController: NavHostCo
TODO("navigate to add my point screen")
},
navigateToAddBus = {
TODO("navigate to add add bus screen")
navController.navigateToBus()
},
navigateToSchedule = {
TODO("navigate to schedule screen")
Expand Down Expand Up @@ -113,6 +115,9 @@ fun DodamApp(isLogin: Boolean, deleteToken: () -> Unit, navController: NavHostCo
askNightStudyScreen(
popBackStack = navController::popBackStack,
)
busScreen(
popBackStack = navController::popBackStack,
)
settingScreen(
popBackStack = navController::popBackStack,
logout = {
Expand Down
1 change: 1 addition & 0 deletions feature-student/bus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
19 changes: 19 additions & 0 deletions feature-student/bus/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
alias(libs.plugins.dodam.android.feature)
}

android {
namespace = "com.b1nd.dodam.bus"

defaultConfig {
consumerProguardFiles("consumer-rules.pro")
}
}

dependencies {
implementation(projects.common)
implementation(libs.dodam.design.system)
implementation(projects.ui)
implementation(projects.data.bus)
implementation(libs.kotlinx.datetime)
}
Empty file.
21 changes: 21 additions & 0 deletions feature-student/bus/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions feature-student/bus/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading
Loading