generated from AND-SOPT-ANDROID/and-sopt-android-template
-
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
166 additions
and
7 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/sopt/and/data/mapper/todata/UserMapper.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,23 @@ | ||
package org.sopt.and.data.mapper.todata | ||
|
||
import org.sopt.and.data.remote.model.request.LoginRequestDto | ||
import org.sopt.and.data.remote.model.request.UserInfoUpdateRequestDto | ||
import org.sopt.and.data.remote.model.request.UserRegistrationRequestDto | ||
import org.sopt.and.domain.model.User | ||
|
||
fun User.toUserRegistrationRequestDto(): UserRegistrationRequestDto = UserRegistrationRequestDto( | ||
username = this.username, | ||
password = this.password, | ||
hobby = this.hobby | ||
) | ||
|
||
fun User.toLoginRequestDto(): LoginRequestDto = LoginRequestDto( | ||
username = this.username, | ||
password = this.password | ||
) | ||
|
||
|
||
fun User.toUserInfoUpdateRequestDto(): UserInfoUpdateRequestDto = UserInfoUpdateRequestDto( | ||
hobby = this.hobby, | ||
password = this.password | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/and/data/mapper/todomain/HobbyResponseDtoMapper.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,8 @@ | ||
package org.sopt.and.data.mapper.todomain | ||
|
||
import org.sopt.and.data.remote.model.response.HobbyResponseDto | ||
import org.sopt.and.domain.model.Hobby | ||
|
||
fun HobbyResponseDto.toDomain(): Hobby = Hobby( | ||
hobby = this.hobby | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/and/data/mapper/todomain/LoginResponseDtoMapper.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,8 @@ | ||
package org.sopt.and.data.mapper.todomain | ||
|
||
import org.sopt.and.data.remote.model.response.LoginResponseDto | ||
import org.sopt.and.domain.model.Token | ||
|
||
fun LoginResponseDto.toDomain(): Token = Token( | ||
token = this.token | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/and/data/mapper/todomain/UserRegistrationResponseDtoMapper.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,8 @@ | ||
package org.sopt.and.data.mapper.todomain | ||
|
||
import org.sopt.and.data.remote.model.response.UserRegistrationResponseDto | ||
import org.sopt.and.domain.model.UserNo | ||
|
||
fun UserRegistrationResponseDto.toDomain(): UserNo = UserNo( | ||
no = this.no | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/and/data/remote/util/handleApiResponse.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,8 @@ | ||
package org.sopt.and.data.remote.util | ||
|
||
import org.sopt.and.data.remote.model.base.ApiResponse | ||
|
||
fun <T> ApiResponse<T>.handleApiResponse(): Result<T> { | ||
return if (this.result != null) Result.success(this.result) | ||
else Result.failure(Exception("No data Available")) | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/org/sopt/and/data/repositoryimpl/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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.sopt.and.data.repositoryimpl | ||
|
||
import org.sopt.and.data.mapper.todata.toUserRegistrationRequestDto | ||
import org.sopt.and.data.mapper.todomain.toDomain | ||
import org.sopt.and.data.remote.datasource.AuthRemoteDataSource | ||
import org.sopt.and.data.remote.model.request.LoginRequestDto | ||
import org.sopt.and.data.remote.util.handleApiResponse | ||
import org.sopt.and.domain.model.Token | ||
import org.sopt.and.domain.model.User | ||
import org.sopt.and.domain.model.UserNo | ||
import org.sopt.and.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class AuthRepositoryImpl @Inject constructor( | ||
private val authRemoteDataSource: AuthRemoteDataSource | ||
): AuthRepository { | ||
override suspend fun registerUser(user: User): Result<UserNo> { | ||
return runCatching { | ||
authRemoteDataSource.registerUser(userRegistrationRequestDto = user.toUserRegistrationRequestDto()).handleApiResponse().getOrThrow().toDomain() | ||
} | ||
} | ||
|
||
override suspend fun login(username: String, password: String): Result<Token> { | ||
return runCatching { | ||
authRemoteDataSource.login(loginRequestDto = LoginRequestDto( | ||
username = username, | ||
password = password | ||
)).handleApiResponse().getOrThrow().toDomain() | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/org/sopt/and/data/repositoryimpl/UserRepositoryImpl.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,38 @@ | ||
package org.sopt.and.data.repositoryimpl | ||
|
||
import org.sopt.and.data.mapper.todomain.toDomain | ||
import org.sopt.and.data.remote.datasource.UserRemoteDataSource | ||
import org.sopt.and.data.remote.model.request.UserInfoUpdateRequestDto | ||
import org.sopt.and.data.remote.util.handleApiResponse | ||
import org.sopt.and.domain.model.Hobby | ||
import org.sopt.and.domain.repository.UserRepository | ||
import javax.inject.Inject | ||
|
||
class UserRepositoryImpl @Inject constructor( | ||
private val userRemoteDataSource: UserRemoteDataSource | ||
): UserRepository { | ||
override suspend fun getMyHobby(token: String): Result<Hobby> { | ||
return runCatching { | ||
userRemoteDataSource.getMyHobby(token = token).handleApiResponse().getOrThrow().toDomain() | ||
} | ||
} | ||
|
||
override suspend fun getOthersHobby(token: String, userNo: Int): Result<Hobby> { | ||
return runCatching { | ||
userRemoteDataSource.getOthersHobby(token = token, userNo = userNo).handleApiResponse().getOrThrow().toDomain() | ||
} | ||
} | ||
|
||
override suspend fun updateUserInfo( | ||
token: String, | ||
password: String?, | ||
hobby: String? | ||
): Result<Unit> { | ||
return runCatching { | ||
userRemoteDataSource.updateUserInfo(token = token, userInfoUpdateRequestDto = UserInfoUpdateRequestDto( | ||
password = password, | ||
hobby = hobby | ||
)).handleApiResponse().getOrThrow() | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
package org.sopt.and.domain.model | ||
|
||
data class Hobby( | ||
val hobby: String | ||
) |
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,5 @@ | ||
package org.sopt.and.domain.model | ||
|
||
data class Token( | ||
val token: String | ||
) |
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 org.sopt.and.domain.model | ||
|
||
data class User( | ||
val username: String, | ||
val password: String, | ||
val hobby: String, | ||
) |
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,5 @@ | ||
package org.sopt.and.domain.model | ||
|
||
data class UserNo( | ||
val no: Int | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/sopt/and/domain/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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.domain.model.Token | ||
import org.sopt.and.domain.model.User | ||
import org.sopt.and.domain.model.UserNo | ||
|
||
interface AuthRepository { | ||
suspend fun registerUser(user: User): Result<UserNo> | ||
suspend fun login(username: String, password: String): Result<Token> | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/sopt/and/domain/repository/UserRepository.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,9 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.domain.model.Hobby | ||
|
||
interface UserRepository { | ||
suspend fun getMyHobby(token: String): Result<Hobby> | ||
suspend fun getOthersHobby(token: String, userNo: Int): Result<Hobby> | ||
suspend fun updateUserInfo(token: String, password: String?, hobby: String?): Result<Unit> | ||
} |