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

[FEAT/#77] 초대 코드 검증 API #82

Merged
merged 13 commits into from
Jan 12, 2024
Merged
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
android:exported="false"
android:screenOrientation="portrait" />


<activity
android:name="com.going.presentation.tendencytest.TendencyTestSplashActivity"
android:exported="false"
Expand Down Expand Up @@ -130,7 +129,7 @@
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.profile.ProfileActivity"
android:name="com.going.presentation.tripdashboard.profile.ProfileActivity"
android:exported="false"
android:screenOrientation="portrait" />

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/going/doorip/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.going.doorip.di

import com.going.data.datasource.AuthDataSource
import com.going.data.datasource.EnterTripDataSource
import com.going.data.datasource.MockDataSource
import com.going.data.datasource.SettingDataSource
import com.going.data.datasource.TendencyDataSource
import com.going.data.datasource.TodoDataSource
import com.going.data.datasourceImpl.AuthDataSourceImpl
import com.going.data.datasourceImpl.EnterTripDataSourceImpl
import com.going.data.datasourceImpl.MockDataSourceImpl
import com.going.data.datasourceImpl.SettingDataSourceImpl
import com.going.data.datasourceImpl.TendencyDataSourceImpl
Expand Down Expand Up @@ -44,4 +46,10 @@ object DataSourceModule {
@Singleton
fun provideTendencyDataSource(tendencyDataSourceImpl: TendencyDataSourceImpl): TendencyDataSource =
tendencyDataSourceImpl

@Provides
@Singleton
fun provideEnterTripDataSource(entertripDataSourceImpl: EnterTripDataSourceImpl): EnterTripDataSource =
entertripDataSourceImpl

}
7 changes: 7 additions & 0 deletions app/src/main/java/com/going/doorip/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.going.doorip.di

import com.going.data.repositoryImpl.AuthRepositoryImpl
import com.going.data.repositoryImpl.EnterTripRepositoryImpl
import com.going.data.repositoryImpl.MockRepositoryImpl
import com.going.data.repositoryImpl.SettingRepositoryImpl
import com.going.data.repositoryImpl.TendencyRepositoryImpl
import com.going.data.repositoryImpl.TodoRepositoryImpl
import com.going.data.repositoryImpl.TokenRepositoryImpl
import com.going.domain.repository.AuthRepository
import com.going.domain.repository.EnterTripRepository
import com.going.domain.repository.MockRepository
import com.going.domain.repository.SettingRepository
import com.going.domain.repository.TendencyRepository
Expand Down Expand Up @@ -47,6 +49,11 @@ object RepositoryModule {
fun provideTodoRepository(todoRepositoryImpl: TodoRepositoryImpl): TodoRepository =
todoRepositoryImpl

@Provides
@Singleton
fun provideEnterTripRepository(entertripRepositoryImpl: EnterTripRepositoryImpl): EnterTripRepository =
entertripRepositoryImpl

@Provides
@Singleton
fun provideTendencyRepository(tendencyRepositoryImpl: TendencyRepositoryImpl): TendencyRepository =
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/going/doorip/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.going.doorip.di

import com.going.data.service.AuthService
import com.going.data.service.EnterTripService
import com.going.data.service.MockService
import com.going.data.service.SettingService
import com.going.data.service.TendencyService
Expand Down Expand Up @@ -36,8 +37,14 @@ object ServiceModule {
fun provideTodoService(retrofit: Retrofit): TodoService =
retrofit.create(TodoService::class.java)

@Provides
@Singleton
fun provideEnterTripService(retrofit: Retrofit): EnterTripService =
retrofit.create(EnterTripService::class.java)

@Provides
@Singleton
fun provideTendencyService(retrofit: Retrofit): TendencyService =
retrofit.create(TendencyService::class.java)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.going.data.datasource;

import com.going.data.dto.BaseResponse
import com.going.data.dto.request.EnterTripRequestDto
import com.going.data.dto.response.EnterTripResponseDto
import retrofit2.http.Body

interface EnterTripDataSource {
suspend fun postEnterTrip(
@Body request: EnterTripRequestDto,
): BaseResponse<EnterTripResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ interface TodoDataSource {
suspend fun postToCreateTodoData(
tripId: Long,
request: TodoCreateRequestDto
): NonDataBaseResponse<Unit>
): NonDataBaseResponse

suspend fun deleteTodoData(
todoId: Long
): NonDataBaseResponse<Unit>
): NonDataBaseResponse

suspend fun getTodoDetailData(
todoId: Long
): BaseResponse<TodoDetailResponseDto>

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.going.data.datasourceImpl

import com.going.data.datasource.EnterTripDataSource
import com.going.data.dto.BaseResponse
import com.going.data.dto.request.EnterTripRequestDto
import com.going.data.dto.response.EnterTripResponseDto
import com.going.data.service.EnterTripService
import javax.inject.Inject

class EnterTripDataSourceImpl @Inject constructor(
private val enterTripService: EnterTripService,
) : EnterTripDataSource {
override suspend fun postEnterTrip(
code: EnterTripRequestDto
): BaseResponse<EnterTripResponseDto> =
enterTripService.postEnterTrip(code)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class TodoDataSourceImpl @Inject constructor(
override suspend fun postToCreateTodoData(
tripId: Long,
request: TodoCreateRequestDto
): NonDataBaseResponse<Unit> =
): NonDataBaseResponse =
todoService.postToCreateTodo(tripId, request)

override suspend fun deleteTodoData(
todoId: Long
): NonDataBaseResponse<Unit> =
): NonDataBaseResponse =
todoService.deleteTodo(todoId)

override suspend fun getTodoDetailData(
todoId: Long
): BaseResponse<TodoDetailResponseDto> =
todoService.getTodoDetail(todoId)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.going.data.dto.request

import com.going.domain.entity.request.EnterTripRequestModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class EnterTripRequestDto(
@SerialName("code")
val code: String,
)

fun EnterTripRequestModel.toEnterTripRequestDto(): EnterTripRequestDto =
EnterTripRequestDto(code)

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.going.data.dto.response

import com.going.domain.entity.response.EnterTripModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class EnterTripResponseDto(
@SerialName("tripId")
val tripId: Long,
@SerialName("title")
val title: String,
@SerialName("startDate")
val startDate: String,
@SerialName("endDate")
val endDate: String,
@SerialName("day")
val day: Int,
) {
fun toEnterTripModel() =
EnterTripModel(tripId, title, startDate, endDate, day)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AuthInterceptor @Inject constructor(
originalRequest
}


val response = chain.proceed(authRequest)

when (response.code) {
Expand Down Expand Up @@ -84,8 +85,9 @@ class AuthInterceptor @Inject constructor(
return response
}

private fun Request.newAuthBuilder() =
this.newBuilder().addHeader(AUTHORIZATION, "$BEARER ${dataStore.accessToken}")
private fun Request.newAuthBuilder() =
this.newBuilder().addHeader(AUTHORIZATION, "$BEARER ${dataStore.accessToken}")


companion object {
private const val CODE_TOKEN_EXPIRED = 401
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.going.data.repositoryImpl

import com.going.data.datasource.EnterTripDataSource
import com.going.data.dto.request.toEnterTripRequestDto
import com.going.domain.entity.request.EnterTripRequestModel
import com.going.domain.entity.response.EnterTripModel
import com.going.domain.repository.EnterTripRepository
import javax.inject.Inject

class EnterTripRepositoryImpl @Inject constructor(
private val enterTripDataSource: EnterTripDataSource,
) : EnterTripRepository {

override suspend fun postEnterTrip(
requestEnterTripModel: EnterTripRequestModel
): Result<EnterTripModel> =
runCatching {
enterTripDataSource.postEnterTrip(
requestEnterTripModel.toEnterTripRequestDto(),
).data.toEnterTripModel()
}
}
14 changes: 14 additions & 0 deletions data/src/main/java/com/going/data/service/EnterTripService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.going.data.service

import com.going.data.dto.BaseResponse
import com.going.data.dto.request.EnterTripRequestDto
import com.going.data.dto.response.EnterTripResponseDto
import retrofit2.http.Body
import retrofit2.http.POST

interface EnterTripService {
@POST("/api/trips/verify")
suspend fun postEnterTrip(
@Body request: EnterTripRequestDto,
): BaseResponse<EnterTripResponseDto>
}
6 changes: 3 additions & 3 deletions data/src/main/java/com/going/data/service/TodoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ interface TodoService {
suspend fun postToCreateTodo(
@Path("tripId") tripId: Long,
@Body request: TodoCreateRequestDto
): NonDataBaseResponse<Unit>
): NonDataBaseResponse

@DELETE("api/trips/todos/{todoId}")
suspend fun deleteTodo(
@Path("todoId") todoId: Long
): NonDataBaseResponse<Unit>
): NonDataBaseResponse

@GET("api/trips/todos/{todoId}")
suspend fun getTodoDetail(
@Path("todoId") todoId: Long
): BaseResponse<TodoDetailResponseDto>

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.going.domain.entity.request

data class EnterTripRequestModel(
val code: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.going.domain.entity.response

data class EnterTripModel(
val tripId: Long,
val title: String,
val startDate: String,
val endDate: String,
val day: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.going.domain.repository

import com.going.domain.entity.request.EnterTripRequestModel
import com.going.domain.entity.response.EnterTripModel

interface EnterTripRepository {
suspend fun postEnterTrip(
requestEnterTripModel: EnterTripRequestModel
): Result<EnterTripModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ import android.os.Bundle
import android.widget.TextView
import androidx.activity.viewModels
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.CodeState
import com.going.presentation.R
import com.going.presentation.databinding.ActivityEnterTripBinding
import com.going.presentation.enter.invitefinish.InviteFinishActivity
import com.going.presentation.starttrip.StartTripSplashActivity
import com.going.ui.base.BaseActivity
import com.going.ui.extension.UiState
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@AndroidEntryPoint
class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activity_enter_trip) {
private val viewModel by viewModels<EnterTripViewModel>()


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initBackBtnClickListener()
initBindingViewModel()
observeIsCodeAvailable()
initNextBtnClickListener()
observeEnterTripState()


}
Expand Down Expand Up @@ -76,10 +85,43 @@ class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activi
counter.setTextColor(getColor(color))
}


private fun observeEnterTripState() {
viewModel.tripState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Success -> {

Intent(this, InviteFinishActivity::class.java).apply {
putExtra(TITLE, state.data.title)
putExtra(START, state.data.startDate)
putExtra(END, state.data.endDate)
putExtra(DAY, state.data.day)
startActivity(this)
}
}

is UiState.Failure -> {
toast(getString(R.string.server_error))
}

is UiState.Loading -> return@onEach

is UiState.Empty -> return@onEach
}
}.launchIn(lifecycleScope)
}

private fun initNextBtnClickListener() {
binding.btnEnterTripNext.setOnSingleClickListener {
//다음 뷰로 이동
viewModel.checkInviteCodeFromServer()
}
}

companion object {
const val TITLE = "title"
const val START = "start"
const val END = "end"
const val DAY = "day"
}

}
Loading