-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
148 additions
and
36 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/stslex/aproselection/ui/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ interface NetworkClient { | |
val client: HttpClient | ||
|
||
val apiClient: HttpClient | ||
|
||
suspend fun regenerateToken() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/model/AuthMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.stslex.aproselection.feature.auth.data.model | ||
|
||
import com.stslex.aproselection.core.network.clients.auth.model.UserAuthResponseModel | ||
|
||
object AuthMapper { | ||
|
||
fun UserAuthResponseModel.toData(): UserModel = UserModel( | ||
uuid = uuid, | ||
username = username, | ||
nickname = nickname | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
feature/auth/src/main/java/com/stslex/aproselection/feature/auth/data/model/UserModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.stslex.aproselection.feature.auth.data.model | ||
|
||
data class UserModel( | ||
val uuid: String, | ||
val username: String, | ||
val nickname: String, | ||
) |
5 changes: 4 additions & 1 deletion
5
...uth/src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.stslex.aproselection.feature.auth.data.repository | ||
|
||
import com.stslex.aproselection.feature.auth.data.model.UserModel | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface AuthRepository { | ||
|
||
fun getHello(username: String): Flow<String> | ||
fun auth(username: String, password: String): Flow<UserModel> | ||
|
||
fun register(username: String, password: String): Flow<UserModel> | ||
} |
44 changes: 36 additions & 8 deletions
44
...src/main/java/com/stslex/aproselection/feature/auth/data/repository/AuthRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,45 @@ | ||
package com.stslex.aproselection.feature.auth.data.repository | ||
|
||
import com.stslex.aproselection.core.datastore.AppDataStore | ||
import com.stslex.aproselection.core.network.clients.auth.AuthNetworkClient | ||
import com.stslex.aproselection.core.network.clients.auth.model.UserAuthSendModel | ||
import com.stslex.aproselection.feature.auth.data.model.AuthMapper.toData | ||
import com.stslex.aproselection.feature.auth.data.model.UserModel | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
class AuthRepositoryImpl( | ||
private val networkClient: AuthNetworkClient | ||
private val networkClient: AuthNetworkClient, | ||
private val dataSource: AppDataStore | ||
) : AuthRepository { | ||
|
||
override fun getHello(username: String): Flow<String> = flow { | ||
val helloResponse = networkClient | ||
.getHello(username = username) | ||
.text | ||
emit(helloResponse) | ||
} | ||
|
||
override fun auth( | ||
username: String, | ||
password: String | ||
): Flow<UserModel> = networkClient.auth( | ||
UserAuthSendModel(username, password) | ||
) | ||
.onEach { response -> | ||
dataSource.setToken(response.token) | ||
dataSource.setUuid(response.uuid) | ||
} | ||
.map { user -> | ||
user.toData() | ||
} | ||
|
||
override fun register( | ||
username: String, | ||
password: String | ||
): Flow<UserModel> = networkClient.register( | ||
UserAuthSendModel(username, password) | ||
) | ||
.onEach { response -> | ||
dataSource.setToken(response.token) | ||
dataSource.setUuid(response.uuid) | ||
} | ||
.map { user -> | ||
user.toData() | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
...h/src/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.stslex.aproselection.feature.auth.domain.interactor | ||
|
||
import com.stslex.aproselection.feature.auth.data.model.UserModel | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface AuthInteractor { | ||
|
||
fun getHello(username: String): Flow<String> | ||
fun auth(username: String, password: String): Flow<UserModel> | ||
|
||
fun register(username: String, password: String): Flow<UserModel> | ||
} |
19 changes: 15 additions & 4 deletions
19
...c/main/java/com/stslex/aproselection/feature/auth/domain/interactor/AuthInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
package com.stslex.aproselection.feature.auth.domain.interactor | ||
|
||
import com.stslex.aproselection.feature.auth.data.model.UserModel | ||
import com.stslex.aproselection.feature.auth.data.repository.AuthRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class AuthInteractorImpl( | ||
private val repository: AuthRepository | ||
) : AuthInteractor { | ||
|
||
override fun getHello( | ||
username: String | ||
): Flow<String> = repository.getHello( | ||
username = username | ||
override fun auth( | ||
username: String, | ||
password: String | ||
): Flow<UserModel> = repository.auth( | ||
username = username, | ||
password = password | ||
) | ||
|
||
override fun register( | ||
username: String, | ||
password: String | ||
): Flow<UserModel> = repository.register( | ||
username = username, | ||
password = password | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters