Skip to content

Commit

Permalink
Merge pull request #168 from GSM-MSG/feature/#167_email_domain_networ…
Browse files Browse the repository at this point in the history
…k_setting

🔀 :: (#167) Email Domain Network Setting
  • Loading branch information
Chaejongin12 authored Apr 27, 2024
2 parents 870d341 + 2bc0a4d commit 872201a
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/data/src/main/java/com/msg/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.msg.data.repository.certification.CertificationRepository
import com.msg.data.repository.certification.CertificationRepositoryImpl
import com.msg.data.repository.club.ClubRepository
import com.msg.data.repository.club.ClubRepositoryImpl
import com.msg.data.repository.email.EmailRepository
import com.msg.data.repository.email.EmailRepositoryImpl
import com.msg.data.repository.faq.FaqRepository
import com.msg.data.repository.faq.FaqRepositoryImpl
import com.msg.data.repository.lecture.LectureRepository
Expand Down Expand Up @@ -70,4 +72,9 @@ abstract class RepositoryModule {
abstract fun bindPostRepository(
postRepositoryImpl: PostRepositoryImpl
): PostRepository

@Binds
abstract fun bindEmailRepository(
emailRepositoryImpl: EmailRepositoryImpl
): EmailRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.data.repository.email

import com.msg.model.remote.request.email.SendLinkToEmailRequest
import com.msg.model.remote.response.email.GetEmailAuthenticateStatusResponse
import kotlinx.coroutines.flow.Flow

interface EmailRepository {
suspend fun sendLinkToEmail(body: SendLinkToEmailRequest): Flow<Unit>
suspend fun getEmailAuthenticateStatus(email: String): Flow<GetEmailAuthenticateStatusResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.msg.data.repository.email

import com.msg.model.remote.request.email.SendLinkToEmailRequest
import com.msg.model.remote.response.email.GetEmailAuthenticateStatusResponse
import com.msg.network.datasource.email.EmailDataSource
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class EmailRepositoryImpl @Inject constructor(
private val emailDataSource: EmailDataSource
) : EmailRepository {
override suspend fun sendLinkToEmail(body: SendLinkToEmailRequest): Flow<Unit> {
return emailDataSource.sendLinkToEmail(
body = body
)
}

override suspend fun getEmailAuthenticateStatus(email: String): Flow<GetEmailAuthenticateStatusResponse> {
return emailDataSource.getEmailAuthenticateStatus(
email = email
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.msg.domain.email

import com.msg.data.repository.email.EmailRepository
import javax.inject.Inject

class GetEmailAuthenticateStatusUseCase @Inject constructor(
private val emailRepository: EmailRepository
) {
suspend operator fun invoke(email: String) = runCatching {
emailRepository.getEmailAuthenticateStatus(email = email)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.msg.domain.email

import com.msg.data.repository.email.EmailRepository
import com.msg.model.remote.request.email.SendLinkToEmailRequest
import javax.inject.Inject

class SendLinkToEmailUseCase @Inject constructor(
private val emailRepository: EmailRepository
) {
suspend operator fun invoke(body: SendLinkToEmailRequest) = runCatching {
emailRepository.sendLinkToEmail(body = body)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.msg.model.remote.request.email

data class SendLinkToEmailRequest(
val email: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.msg.model.remote.response.email

data class GetEmailAuthenticateStatusResponse(
val isAuthentication: Boolean,
)
20 changes: 20 additions & 0 deletions core/network/src/main/java/com/msg/network/api/EmailAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.msg.network.api

import com.msg.model.remote.request.email.SendLinkToEmailRequest
import com.msg.model.remote.response.email.GetEmailAuthenticateStatusResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface EmailAPI {
@POST("email")
suspend fun sendLinkToEmail(
@Body body: SendLinkToEmailRequest
)

@GET("email")
suspend fun getEmailAuthenticateStatus(
@Query("email") email: String
): GetEmailAuthenticateStatusResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.network.datasource.email

import com.msg.model.remote.request.email.SendLinkToEmailRequest
import com.msg.model.remote.response.email.GetEmailAuthenticateStatusResponse
import kotlinx.coroutines.flow.Flow

interface EmailDataSource {
suspend fun sendLinkToEmail(body: SendLinkToEmailRequest): Flow<Unit>
suspend fun getEmailAuthenticateStatus(email: String): Flow<GetEmailAuthenticateStatusResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.msg.network.datasource.email

import com.msg.model.remote.request.email.SendLinkToEmailRequest
import com.msg.model.remote.response.email.GetEmailAuthenticateStatusResponse
import com.msg.network.api.EmailAPI
import com.msg.network.util.BitgoeulApiHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

class EmailDataSourceImpl @Inject constructor(
private val emailAPI: EmailAPI
) : EmailDataSource {
override suspend fun sendLinkToEmail(body: SendLinkToEmailRequest): Flow<Unit> = flow {
emit(
BitgoeulApiHandler<Unit>()
.httpRequest { emailAPI.sendLinkToEmail(body = body) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)

override suspend fun getEmailAuthenticateStatus(email: String): Flow<GetEmailAuthenticateStatusResponse> = flow {
emit(
BitgoeulApiHandler<GetEmailAuthenticateStatusResponse>()
.httpRequest { emailAPI.getEmailAuthenticateStatus(email = email) }
.sendRequest()
)
}.flowOn(Dispatchers.IO)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.msg.network.datasource.certification.CertificationDataSource
import com.msg.network.datasource.certification.CertificationDataSourceImpl
import com.msg.network.datasource.club.ClubDataSource
import com.msg.network.datasource.club.ClubDataSourceImpl
import com.msg.network.datasource.email.EmailDataSource
import com.msg.network.datasource.email.EmailDataSourceImpl
import com.msg.network.datasource.faq.FaqDataSource
import com.msg.network.datasource.faq.FaqDataSourceImpl
import com.msg.network.datasource.lecture.LectureDataSource
Expand Down Expand Up @@ -70,4 +72,9 @@ abstract class DataSourceModule {
abstract fun bindPostDataSource(
postDataSourceImpl: PostDataSourceImpl
): PostDataSource

@Binds
abstract fun bindEmailDataSource(
emailDataSourceImpl: EmailDataSourceImpl
): EmailDataSource
}

0 comments on commit 872201a

Please sign in to comment.