Skip to content

Commit

Permalink
Merge pull request #54 from meongmory/feature/api-register-family
Browse files Browse the repository at this point in the history
[feature/api-register-family] 펫 다이어리 생성 API 기본 틀 구현
  • Loading branch information
seuriseuljjeok authored Sep 7, 2023
2 parents bee4c74 + b879432 commit beba914
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.meongmoryteam.meongmory.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.meongmoryteam.data.service.family.FamilyApi
import com.meongmoryteam.data.service.login.LoginApi
import com.meongmoryteam.data.service.logout.LogoutApi
import com.meongmoryteam.data.service.mypage.MyPageApi
Expand Down Expand Up @@ -55,6 +56,12 @@ object NetworkModule {
return retrofit.create(LoginApi::class.java)
}

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

@Provides
@Singleton
fun provideMyPageApi(retrofit: Retrofit): MyPageApi {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.meongmoryteam.meongmory.di

import com.meongmoryteam.data.datasource.family.FamilyDataSource
import com.meongmoryteam.data.datasource.family.FamilyDataSourceImpl
import com.meongmoryteam.data.datasource.login.LoginDataSource
import com.meongmoryteam.data.datasource.login.LoginDataSourceImpl
import com.meongmoryteam.data.repository.family.FamilyRepositoryImpl
import com.meongmoryteam.data.repository.login.LoginRepositoryImpl
import com.meongmoryteam.domain.repository.family.FamilyRepository
import com.meongmoryteam.data.datasource.logout.LogoutDataSource
import com.meongmoryteam.data.datasource.logout.LogoutDataSourceImpl
import com.meongmoryteam.data.datasource.mypage.MyPageDataSource
Expand Down Expand Up @@ -34,6 +39,18 @@ abstract class RepositoryModule {
loginDataSourceImpl: LoginDataSourceImpl
): LoginDataSource

@Singleton
@Binds
abstract fun bindFamilyRepository(
familyRepositoryImpl: FamilyRepositoryImpl
): FamilyRepository

@Singleton
@Binds
abstract fun bindFamilyDataSource(
familyDataSourceImpl: FamilyDataSourceImpl
): FamilyDataSource

@Singleton
@Binds
abstract fun bindMyPageRepository(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.meongmoryteam.data.datasource.family

import com.meongmoryteam.data.model.request.family.RegisterFamilyCodeRequest
import com.meongmoryteam.data.model.request.family.RegisterFamilyNameRequest
import com.meongmoryteam.data.model.response.family.PostRegisterFamilyCodeRes
import com.meongmoryteam.data.model.response.family.PostRegisterFamilyNameRes

interface FamilyDataSource {
suspend fun registerFamilyWithName(registerFamilyNameReq: RegisterFamilyNameRequest): Result<PostRegisterFamilyNameRes>
suspend fun registerFamilyWithCode(familyId: String, registerFamilyCodeReq: RegisterFamilyCodeRequest): Result<PostRegisterFamilyCodeRes>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.meongmoryteam.data.datasource.family

import com.meongmoryteam.data.model.request.family.RegisterFamilyCodeRequest
import com.meongmoryteam.data.model.request.family.RegisterFamilyNameRequest
import com.meongmoryteam.data.model.response.family.PostRegisterFamilyCodeRes
import com.meongmoryteam.data.model.response.family.PostRegisterFamilyNameRes
import com.meongmoryteam.data.service.family.FamilyApi
import javax.inject.Inject

class FamilyDataSourceImpl @Inject constructor(
private val familyApi: FamilyApi
) : FamilyDataSource {
override suspend fun registerFamilyWithName(registerFamilyNameReq: RegisterFamilyNameRequest): Result<PostRegisterFamilyNameRes> {
return runCatching { familyApi.postRegisterFamilyName(registerFamilyNameReq) }
}

override suspend fun registerFamilyWithCode(
familyId: String,
registerFamilyCodeReq: RegisterFamilyCodeRequest
): Result<PostRegisterFamilyCodeRes> {
return runCatching { familyApi.postRegisterFamilyCode(familyId, registerFamilyCodeReq) }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.meongmoryteam.data.model.request.family

import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyCodeRequestEntity
import kotlinx.serialization.Serializable

@Serializable
data class RegisterFamilyCodeRequest(
val familyCode: String
)

fun RegisterFamilyCodeRequestEntity.toRegisterWithCodeRequest(): RegisterFamilyCodeRequest {
return RegisterFamilyCodeRequest(
familyCode = this.familyCode
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.meongmoryteam.data.model.request.family

import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyCodeRequestEntity
import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyNameRequestEntity
import kotlinx.serialization.Serializable

@Serializable
data class RegisterFamilyNameRequest(
val name: String
)

fun RegisterFamilyNameRequestEntity.toRegisterWithNameRequest(): RegisterFamilyNameRequest {
return RegisterFamilyNameRequest(
name = this.name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.meongmoryteam.data.model.response.family

import com.meongmoryteam.domain.model.response.family.PostRegisterFamilyCodeEntity
import kotlinx.serialization.Serializable

@Serializable
data class PostRegisterFamilyCodeRes(
val code: String,
val data: String,
val message: String,
val status: Int,
)

fun PostRegisterFamilyCodeRes.toPostRegisterFamilyCodeEntity(): PostRegisterFamilyCodeEntity {
return PostRegisterFamilyCodeEntity(
code = this.code,
data = this.data,
message = this.message,
status = this.status,
)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.meongmoryteam.data.model.response.family

import com.meongmoryteam.domain.model.response.family.PostRegisterFamilyNameEntity
import kotlinx.serialization.Serializable

@Serializable
data class PostRegisterFamilyNameRes(
val code: String,
val data: String,
val message: String,
val status: Int,
)

fun PostRegisterFamilyNameRes.toPostRegisterFamilyNameEntity(): PostRegisterFamilyNameEntity {
return PostRegisterFamilyNameEntity(
code = this.code,
data = this.data,
message = this.message,
status = this.status,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.meongmoryteam.data.repository.family

import com.meongmoryteam.data.datasource.family.FamilyDataSource
import com.meongmoryteam.data.model.request.family.toRegisterWithCodeRequest
import com.meongmoryteam.data.model.request.family.toRegisterWithNameRequest
import com.meongmoryteam.data.model.response.family.toPostRegisterFamilyCodeEntity
import com.meongmoryteam.data.model.response.family.toPostRegisterFamilyNameEntity
import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyCodeRequestEntity
import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyNameRequestEntity
import com.meongmoryteam.domain.model.response.family.PostRegisterFamilyCodeEntity
import com.meongmoryteam.domain.model.response.family.PostRegisterFamilyNameEntity
import com.meongmoryteam.domain.repository.family.FamilyRepository
import javax.inject.Inject

class FamilyRepositoryImpl @Inject constructor(
private val familyDataSource: FamilyDataSource
) : FamilyRepository {
override suspend fun postRegisterWithName(registerFamilyNameRequestEntity: RegisterFamilyNameRequestEntity): Result<PostRegisterFamilyNameEntity> {
return familyDataSource.registerFamilyWithName(registerFamilyNameRequestEntity.toRegisterWithNameRequest())
.map { it.toPostRegisterFamilyNameEntity() }
}

override suspend fun postRegisterWithCode(
familyId: String,
registerFamilyCodeRequestEntity: RegisterFamilyCodeRequestEntity
): Result<PostRegisterFamilyCodeEntity> {
return familyDataSource.registerFamilyWithCode(
familyId,
registerFamilyCodeRequestEntity.toRegisterWithCodeRequest()
).map { it.toPostRegisterFamilyCodeEntity() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.meongmoryteam.data.service.family

import com.meongmoryteam.data.model.request.family.RegisterFamilyCodeRequest
import com.meongmoryteam.data.model.request.family.RegisterFamilyNameRequest
import com.meongmoryteam.data.model.response.family.PostRegisterFamilyCodeRes
import com.meongmoryteam.data.model.response.family.PostRegisterFamilyNameRes
import retrofit2.http.Body
import retrofit2.http.POST
import retrofit2.http.Path

interface FamilyApi {
@POST("families")
suspend fun postRegisterFamilyName(
@Body registerFamilyNameRequest: RegisterFamilyNameRequest
): PostRegisterFamilyNameRes

@POST("families/{familyId}/invite")
suspend fun postRegisterFamilyCode(
@Path(value = "familyId") familyId: String,
@Body registerFamilyCodeRequest: RegisterFamilyCodeRequest
): PostRegisterFamilyCodeRes
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.meongmoryteam.domain.model.reqeust.family

data class RegisterFamilyCodeRequestEntity (
val familyCode: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.meongmoryteam.domain.model.reqeust.family

data class RegisterFamilyNameRequestEntity(
val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.meongmoryteam.domain.model.response.family

data class PostRegisterFamilyCodeEntity(
val code: String,
val data: String,
val message: String,
val status: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.meongmoryteam.domain.model.response.family

data class PostRegisterFamilyNameEntity(
val code: String,
val data: String,
val message: String,
val status: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.meongmoryteam.domain.repository.family

import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyCodeRequestEntity
import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyNameRequestEntity
import com.meongmoryteam.domain.model.response.family.PostRegisterFamilyCodeEntity
import com.meongmoryteam.domain.model.response.family.PostRegisterFamilyNameEntity

interface FamilyRepository {
suspend fun postRegisterWithName(registerFamilyNameRequestEntity: RegisterFamilyNameRequestEntity): Result<PostRegisterFamilyNameEntity>
suspend fun postRegisterWithCode(
familyId: String,
registerFamilyCodeRequestEntity: RegisterFamilyCodeRequestEntity
): Result<PostRegisterFamilyCodeEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.meongmoryteam.domain.usecase.family

import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyCodeRequestEntity
import com.meongmoryteam.domain.repository.family.FamilyRepository
import javax.inject.Inject

class PostRegisterFamilyCodeUseCase @Inject constructor(
private val familyRepository: FamilyRepository
) {
suspend operator fun invoke(
familyId: String,
registerFamilyCodeRequestEntity: RegisterFamilyCodeRequestEntity
) = familyRepository.postRegisterWithCode(familyId, registerFamilyCodeRequestEntity)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.meongmoryteam.domain.usecase.family

import com.meongmoryteam.domain.model.reqeust.family.RegisterFamilyNameRequestEntity
import com.meongmoryteam.domain.repository.family.FamilyRepository
import javax.inject.Inject

class PostRegisterFamilyNameUseCase @Inject constructor(
private val familyRepository: FamilyRepository
) {
suspend operator fun invoke(registerFamilyNameRequestEntity: RegisterFamilyNameRequestEntity) =
familyRepository.postRegisterWithName(registerFamilyNameRequestEntity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class RegisterFamilyContract {
val familyName: String = "",
val isFilledName: Boolean = false,
val isFilledCode: Boolean = false,
val invalidCode: Boolean = false
val invalidCode: Boolean = true,
val familyId: String = ""
) : ViewState

sealed class RegisterFamilySideEffect : ViewSideEffect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ fun RegisterFamilyScreen(
TextComponent(
text = stringResource(R.string.register_family_info),
style = Typography.titleMedium,
color = DarkGrey
color = DarkGrey,
maxLine = 5
)
}
Column(modifier = Modifier.padding(bottom = 30.dp)) {
Expand Down
Loading

0 comments on commit beba914

Please sign in to comment.