Skip to content
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
7 changes: 7 additions & 0 deletions app/src/main/java/com/ftw/hometerview/di/api/APIModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ftw.hometerview.di.api

import com.ftw.data.remote.api.BuildingReviewsAPI
import com.ftw.data.remote.api.LoginAPI
import com.ftw.data.remote.api.review.ReviewAPI
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -19,6 +20,12 @@ class APIModule {
return retrofit.create(LoginAPI::class.java)
}

@Provides
@Singleton
fun provideReviewApi(retrofit: Retrofit): ReviewAPI {
return retrofit.create(ReviewAPI::class.java)
}

@Provides
@Singleton
fun provideBuildingReviewsApi(retrofit: Retrofit): BuildingReviewsAPI {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ftw.hometerview.di.datasource

import com.ftw.data.datasource.review.ReviewDataSource
import com.ftw.data.remote.api.review.ReviewAPI
import com.ftw.data.remote.datasource.review.ReviewRemoteDataSource
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class ReviewDataSourceModule {

@Provides
@Singleton
fun provideReviewDataSource(api: ReviewAPI): ReviewDataSource {
return ReviewRemoteDataSource(api)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ftw.hometerview.di.repository

import com.ftw.data.datasource.review.ReviewDataSource
import com.ftw.data.repository.review.ReviewRepositoryImpl
import com.ftw.domain.repository.review.ReviewRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class ReviewRepositoryModule {

@Provides
@Singleton
fun provideReviewRepository(reviewDataSource: ReviewDataSource): ReviewRepository {
return ReviewRepositoryImpl(reviewDataSource)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.ftw.domain.usecase.login.LoginUseCase
import com.ftw.domain.usecase.review.GetLocationReviewsUseCase
import com.ftw.domain.usecase.searchaddressbuilding.GetSearchAddressBuildingUseCase
import com.ftw.domain.usecase.myreviews.GetMyReviewsUseCase
import com.ftw.domain.usecase.review.CreateReviewUseCase
import com.ftw.hometerview.dispatcher.Dispatcher
import com.ftw.hometerview.ui.buildingreview.BuildingReviewViewModel
import com.ftw.hometerview.ui.main.MainViewModel
Expand All @@ -16,6 +17,7 @@ import com.ftw.hometerview.ui.searchcompanyresult.SearchCompanyResultViewModel
import com.ftw.hometerview.ui.splash.SplashViewModel
import com.ftw.hometerview.ui.updatenickname.UpdateNicknameViewModel
import com.ftw.hometerview.ui.myreviews.MyReviewsViewModel
import com.ftw.hometerview.ui.review.CreateReviewViewModel
import com.ftw.hometerview.ui.withdrawal.WithdrawalViewModel
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -127,4 +129,16 @@ class ActivityViewModelModule {
dispatcher
)
}

@Provides
@ActivityScoped
fun provideCreateReviewViewModel(
dispatcher: Dispatcher,
createReviewUseCase: CreateReviewUseCase
): CreateReviewViewModel {
return CreateReviewViewModel(
dispatcher,
createReviewUseCase
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ftw.hometerview.di.usecase

import com.ftw.domain.usecase.review.GetLocationReviewsUseCase
import com.ftw.domain.usecase.review.GetLocationReviewsUseCaseImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class LocationReviewUseCaseModule {
@Provides
@Singleton
fun provideGetLocationReviewsUseCase(): GetLocationReviewsUseCase {
return GetLocationReviewsUseCaseImpl()
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.ftw.hometerview.di.usecase

import com.ftw.domain.usecase.review.GetLocationReviewsUseCase
import com.ftw.domain.usecase.review.GetLocationReviewsUseCaseImpl
import com.ftw.domain.repository.review.ReviewRepository
import com.ftw.domain.usecase.review.CreateReviewUseCase
import com.ftw.domain.usecase.review.CreateReviewUseCaseImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class ReviewUseCaseModule {
@Provides
@Singleton
fun provideGetLocationReviewsUseCase(): GetLocationReviewsUseCase {
return GetLocationReviewsUseCaseImpl()
fun provideCreateReviewUseCase(repository: ReviewRepository): CreateReviewUseCase {
return CreateReviewUseCaseImpl(repository)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.ftw.hometerview.ui.review.second.CreateReviewSecondStepReviewFragment
import com.ftw.hometerview.ui.review.third.CreateReviewThirdStepSearchCompanyFragment
import dagger.hilt.android.AndroidEntryPoint
import java.util.Date
import javax.inject.Inject

@AndroidEntryPoint
class CreateReviewActivity :
Expand All @@ -32,6 +33,9 @@ class CreateReviewActivity :
fun newIntent(context: Context): Intent = Intent(context, CreateReviewActivity::class.java)
}

@Inject
lateinit var viewModel: CreateReviewViewModel

private var review = Review.NONE

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -48,7 +52,7 @@ class CreateReviewActivity :
}

override fun onClickAddressFromFirstStepAddress(address: String) {
review = review.copy(buildingAddress = address)
viewModel.setAddress(buildingId = "test")
addFragment(
R.id.fragment_container_view,
CreateReviewFirstStepSelectFloorFragment.newInstance(address),
Expand All @@ -57,7 +61,7 @@ class CreateReviewActivity :
}

override fun onClickNextFromFirstStepResidentialFloor(address: String, floor: String) {
review = review.copy(buildingAddress = address)
viewModel.setFloor(floor)
addFragment(
R.id.fragment_container_view,
CreateReviewSecondStepReviewFragment.newInstance(),
Expand All @@ -71,12 +75,7 @@ class CreateReviewActivity :
advantage: String,
disadvantage: String
) {
review = review.copy(
rating = rating,
leftAt = leftAt,
advantage = advantage,
disadvantage = disadvantage
)
viewModel.setInfo(rating, leftAt.toString(), advantage, disadvantage)
addFragment(
R.id.fragment_container_view,
CreateReviewThirdStepSearchCompanyFragment.newInstance(),
Expand All @@ -85,7 +84,9 @@ class CreateReviewActivity :
}

override fun onClickNextFromThirdStepSearchCompany(company: String) {
review = review.copy(officeLocation = company)
viewModel.setCompanyId("companyId")
viewModel.create()

setResult(
Activity.RESULT_OK,
Intent().putExtra(CREATE_REVIEW_RESULT_KEY, review.toParcelable())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.ftw.hometerview.ui.review

import android.util.Log
import com.ftw.domain.usecase.review.CreateReviewUseCase
import com.ftw.hometerview.dispatcher.Dispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch

class CreateReviewViewModel(
private val dispatcher: Dispatcher,
private val createReviewUseCase: CreateReviewUseCase
) {
private var buildingId: String? = null
private var companyId: String? = null
private var period: String? = null
private var rating: Int? = null
private var advantage: String? = null
private var disadvantage: String? = null
private var floor: String? = null

fun setAddress(buildingId: String) {
this.buildingId = buildingId
}

fun setFloor(floor: String) {
this.floor = floor
}

fun setInfo(rating: Int, period: String, advantage: String, disadvantage: String) {
this.rating = rating
this.period = period
this.advantage = advantage
this.disadvantage = disadvantage
}

fun setCompanyId(companyId: String) {
this.companyId = companyId
}

fun create() {
CoroutineScope(dispatcher.ui()).launch {
flow {
emit(
createReviewUseCase(
buildingId = buildingId ?: "",
companyId = companyId ?: "",
period = period ?: "",
rating = rating ?: 0,
advantage = advantage ?: "",
disadvantage = disadvantage ?: "",
floor = floor ?: ""
)
)
}.collect {
Log.d("CreateReviewViewModel", "completed")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CreateReviewFirstStepInputAddressViewModel(
address
.debounce(500)
.transformLatest { address ->
flow<Result<List<String>>> {
flow {
if (address.isNotBlank()) emit(getAddressUseCase(address))
else emit(Result.success(emptyList()))
}.collect { result ->
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_building_review.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
android:layout_marginHorizontal="@dimen/dp_size_14"
android:drawablePadding="@dimen/dp_size_6"
android:fontFamily="@font/pretendard_regular"
android:text="@{viewModel.building.address.addressWithLoadName}"
android:text="@{viewModel.building.buildingAddress.addressWithLoadName}"
android:textColor="@color/gray_800"
android:textSize="@dimen/sp_size_14"
app:drawableStartCompat="@drawable/icon_discovery"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/list_item_favorite_building.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
android:ellipsize="end"
android:fontFamily="@font/pretendard_regular"
android:maxLines="1"
android:text="@{item.favoriteBuildings.address.component3()}"
android:text="@{item.favoriteBuildings.buildingAddress.component3()}"
android:textColor="@color/gray_600"
android:textSize="@dimen/sp_size_12"
app:drawableTint="@color/gray_400"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ftw.data.datasource.review

interface ReviewDataSource {
suspend fun create(
buildingId: String,
companyId: String,
period: String,
rating: Int,
advantage: String,
disadvantage: String,
floor: String
)
}
14 changes: 14 additions & 0 deletions data/src/main/java/com/ftw/data/remote/api/review/ReviewAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ftw.data.remote.api.review

import com.ftw.data.remote.request.CreateReviewRequest
import com.ftw.data.remote.response.RemoteResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST

interface ReviewAPI {
@POST("/api/v1/review")
fun create(
@Body review: CreateReviewRequest
): Response<RemoteResponse<Nothing>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ftw.data.remote.datasource.review

import com.ftw.data.datasource.review.ReviewDataSource
import com.ftw.data.remote.api.review.ReviewAPI
import com.ftw.data.remote.exception.ResponseException
import com.ftw.data.remote.request.CreateReviewRequest

class ReviewRemoteDataSource(
private val api: ReviewAPI
) : ReviewDataSource {
override suspend fun create(
buildingId: String,
companyId: String,
period: String,
rating: Int,
advantage: String,
disadvantage: String,
floor: String
) {
try {
val response = api.create(
CreateReviewRequest(
buildingId,
companyId,
period,
rating,
advantage,
disadvantage,
floor
)
)

if (!response.isSuccessful) {
throw ResponseException()
}
} catch (e: Exception) {
throw e
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.ftw.data.remote.exception

class ResponseException(message: String) : RuntimeException(message)
class ResponseException(message: String = "Network Exception") : RuntimeException(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ftw.data.remote.request

data class CreateReviewRequest(
val buildingId: String,
val companyId: String,
val period: String,
val rating: Int,
val advantage: String,
val disadvantage: String,
val floor: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ftw.data.repository.review

import com.ftw.data.datasource.review.ReviewDataSource
import com.ftw.domain.repository.review.ReviewRepository

class ReviewRepositoryImpl(
private val dataSource: ReviewDataSource
) : ReviewRepository {
override suspend fun create(
buildingId: String,
companyId: String,
period: String,
rating: Int,
advantage: String,
disadvantage: String,
floor: String
) {
dataSource.create(buildingId, companyId, period, rating, advantage, disadvantage, floor)
}
}
Loading