Skip to content

Commit

Permalink
Merge pull request #28 from pknu-wap/feature/jaino/#15
Browse files Browse the repository at this point in the history
Feature/jaino/#15
  • Loading branch information
jeongjaino authored Oct 11, 2023
2 parents 0fc6522 + 1c75ae2 commit 9fb2dd8
Show file tree
Hide file tree
Showing 26 changed files with 395 additions and 30 deletions.
117 changes: 117 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/dictionaries/jaino.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".WappApplication"
android:allowBackup="true"
Expand All @@ -24,4 +24,4 @@
</activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wap.wapp.core.data.repository.di
package com.wap.wapp.core.data.di

import com.wap.wapp.core.data.repository.auth.AuthRepository
import com.wap.wapp.core.data.repository.auth.AuthRepositoryImpl
Expand Down
19 changes: 19 additions & 0 deletions core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.wap.wapp.core.data.di

import com.wap.wapp.core.data.repository.user.UserRepository
import com.wap.wapp.core.data.repository.user.UserRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class DataModule {
@Binds
@Singleton
abstract fun providesUserRepository(
userRepositoryImpl: UserRepositoryImpl,
): UserRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ interface AuthRepository {
suspend fun hasPendingResult(): Boolean

suspend fun signIn(email: String): Result<String>

suspend fun signOut(): Result<Unit>

suspend fun deleteUser(): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ class AuthRepositoryImpl @Inject constructor(
override suspend fun signIn(email: String): Result<String> {
return authDataSource.signIn(email)
}

override suspend fun signOut(): Result<Unit> {
return authDataSource.signOut()
}

override suspend fun deleteUser(): Result<Unit> {
return authDataSource.deleteUser()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.wap.wapp.core.data.repository.user

import com.wap.wapp.core.model.user.UserProfile

interface UserRepository {
suspend fun getUserProfile(userId: String): Result<UserProfile>

suspend fun postUserProfile(
userId: String,
userName: String,
studentId: String,
registeredAt: String,
): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.wap.wapp.core.data.repository.user

import com.wap.wapp.core.model.user.UserProfile
import com.wap.wapp.core.network.model.user.UserProfileRequest
import com.wap.wapp.core.network.source.user.UserDataSource
import javax.inject.Inject

class UserRepositoryImpl @Inject constructor(
private val userDataSource: UserDataSource,
) : UserRepository {
override suspend fun getUserProfile(userId: String): Result<UserProfile> {
return userDataSource.getUserProfile(userId).mapCatching { response ->
response.toDomain()
}
}

override suspend fun postUserProfile(
userId: String,
userName: String,
studentId: String,
registeredAt: String,
): Result<Unit> {
return userDataSource.postUserProfile(
UserProfileRequest(
userId = userId,
userName = userName,
studentId = studentId,
registeredAt = registeredAt,
),
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wap.wapp.core.domain.model

enum class AuthState {
SIGN_IN, SIGN_UP
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wap.wapp.core.domain.usecase.auth

import com.wap.wapp.core.data.repository.auth.AuthRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class DeleteUserUseCase @Inject constructor(
private val authRepository: AuthRepository,
) {
suspend operator fun invoke(): Result<Unit> =
authRepository.deleteUser()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.wap.wapp.core.domain.usecase.auth

import com.wap.wapp.core.data.repository.auth.AuthRepository
import com.wap.wapp.core.data.repository.user.UserRepository
import com.wap.wapp.core.domain.model.AuthState
import com.wap.wapp.core.domain.model.AuthState.SIGN_IN
import com.wap.wapp.core.domain.model.AuthState.SIGN_UP
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject

@ActivityScoped
class SignInUseCase @Inject constructor(
private val authRepository: AuthRepository,
private val userRepository: UserRepository,
) {
suspend operator fun invoke(email: String): Result<AuthState> {
return runCatching {
val userId = authRepository.signIn(email)
.getOrThrow()

userRepository.getUserProfile(userId)
.fold(
onFailure = { exception ->
// 사용자를 조회할 수 없는 예외인 경우
val userNotFoundException = IllegalStateException()
if (exception == userNotFoundException) {
SIGN_UP
}
// 이외의 예외라면,
throw (exception)
},
onSuccess = {
SIGN_IN
},
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wap.wapp.core.domain.usecase.auth

import com.wap.wapp.core.data.repository.auth.AuthRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SignOutUseCase @Inject constructor(
private val authRepository: AuthRepository,
) {
suspend operator fun invoke(): Result<Unit> =
authRepository.signOut()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.wap.wapp.core.domain.usecase.user

import com.wap.wapp.core.data.repository.user.UserRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class PostUserProfileUseCase @Inject constructor(
private val userRepository: UserRepository,
) {
suspend operator fun invoke(
userId: String,
userName: String,
studentId: String,
registeredAt: String,
): Result<Unit> {
return userRepository.postUserProfile(
userId = userId,
userName = userName,
studentId = studentId,
registeredAt = registeredAt,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wap.wapp.core.network.model.auth
package com.wap.wapp.core.model.user

data class SignUpRequest(
data class UserProfile(
val userId: String,
val userName: String,
val studentId: String,
Expand Down
1 change: 1 addition & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {
}

dependencies {
implementation(project(":core:model"))
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.auth)
implementation(libs.firebase.firestore)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wap.wapp.core.network.constant

/*
파이어스토어 유저 컬렉션
*/
const val USER_COLLECTION = "users"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wap.wapp.core.network.model.user

data class UserProfileRequest(
val userId: String,
val userName: String,
val studentId: String,
val registeredAt: String,
) {
constructor() : this(
"",
"",
"",
"",
)
}
Loading

0 comments on commit 9fb2dd8

Please sign in to comment.