-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from CashAdv/feature/76-edit-user-profile
Feature/76 edit user profile
- Loading branch information
Showing
59 changed files
with
2,080 additions
and
20 deletions.
There are no files selected for viewing
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
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
35 changes: 35 additions & 0 deletions
35
app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.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,35 @@ | ||
package app.cashadvisor.profile.data.api | ||
|
||
import app.cashadvisor.profile.data.dto.request.UpdateUserNameRequest | ||
import app.cashadvisor.profile.data.dto.response.ConfirmUpdateNameResponse | ||
import app.cashadvisor.profile.data.dto.response.ConfirmUpdatePicResponse | ||
import app.cashadvisor.profile.data.dto.response.ProfileInfoResponse | ||
import okhttp3.MultipartBody | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.Multipart | ||
import retrofit2.http.PUT | ||
import retrofit2.http.Part | ||
|
||
interface ProfileInfoApiService { | ||
|
||
@GET("profile/info/get") | ||
suspend fun getUserInfo( | ||
@Header("Authorization") accessToken: String | ||
): ProfileInfoResponse | ||
|
||
@PUT("profile/name/put") | ||
suspend fun updateUserName( | ||
@Header("Authorization") accessToken: String, | ||
@Body updateUserNameRequest: UpdateUserNameRequest | ||
): ConfirmUpdateNameResponse | ||
|
||
@Multipart | ||
@PUT("profile/image/put") | ||
suspend fun updateProfilePic( | ||
@Header("Authorization") accessToken: String, | ||
@Part part: MultipartBody.Part | ||
): ConfirmUpdatePicResponse | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoRemoteDataSource.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 app.cashadvisor.profile.data.api | ||
|
||
import app.cashadvisor.profile.data.dto.request.UpdateProfilePicRequest | ||
import app.cashadvisor.profile.data.dto.request.UpdateUserNameRequest | ||
import app.cashadvisor.profile.data.dto.response.ConfirmUpdateNameResponse | ||
import app.cashadvisor.profile.data.dto.response.ConfirmUpdatePicResponse | ||
import app.cashadvisor.profile.data.dto.response.ProfileInfoResponse | ||
|
||
interface ProfileInfoRemoteDataSource { | ||
|
||
suspend fun getUserInfo(accessToken: String): ProfileInfoResponse | ||
|
||
suspend fun updateUserName( | ||
dto: UpdateUserNameRequest, | ||
accessToken: String | ||
): ConfirmUpdateNameResponse | ||
|
||
suspend fun updateProfilePic( | ||
dto: UpdateProfilePicRequest, | ||
accessToken: String | ||
): ConfirmUpdatePicResponse | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoStorage.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,14 @@ | ||
package app.cashadvisor.profile.data.api | ||
|
||
import app.cashadvisor.profile.data.dto.UserInfoDto | ||
|
||
interface ProfileInfoStorage { | ||
|
||
suspend fun getProfileInfo(): UserInfoDto? | ||
|
||
suspend fun saveProfileInfo(userInfoDto: UserInfoDto) | ||
|
||
suspend fun updateUserName(name: String, surname: String) | ||
|
||
suspend fun updateProfilePic(picUrl: String) | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/app/cashadvisor/profile/data/dto/UserInfoDto.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 app.cashadvisor.profile.data.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserInfoDto( | ||
val surname: String, | ||
val name: String, | ||
@SerialName("user_id") val id: String, | ||
@SerialName("avatar_url") val profilePicUrl: String? | ||
) |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/app/cashadvisor/profile/data/dto/request/UpdateProfilePicRequest.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,11 @@ | ||
package app.cashadvisor.profile.data.dto.request | ||
|
||
import java.io.File | ||
|
||
data class UpdateProfilePicRequest( | ||
val profilePic: File | ||
) | ||
|
||
//data class UpdateProfilePicRequest( | ||
// val profilePicInputStream: InputStream | ||
//) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/app/cashadvisor/profile/data/dto/request/UpdateUserNameRequest.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 app.cashadvisor.profile.data.dto.request | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UpdateUserNameRequest( | ||
val name: String, | ||
val surname: String | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/app/cashadvisor/profile/data/dto/response/ConfirmUpdateNameResponse.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 app.cashadvisor.profile.data.dto.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ConfirmUpdateNameResponse( | ||
val message: String, | ||
@SerialName("status_code") val statusCode: Int | ||
) |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/app/cashadvisor/profile/data/dto/response/ConfirmUpdatePicResponse.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,11 @@ | ||
package app.cashadvisor.profile.data.dto.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ConfirmUpdatePicResponse( | ||
val message: String, | ||
@SerialName("status_code") val statusCode: Int, | ||
@SerialName("avatar_url") val profilePicUrl: String? | ||
) |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoResponse.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 app.cashadvisor.profile.data.dto.response | ||
|
||
import app.cashadvisor.profile.data.dto.UserInfoDto | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ProfileInfoResponse( | ||
@SerialName("status_code") val statusCode: Int, | ||
val message: String, | ||
@SerialName("profile") val userInfo: UserInfoDto? | ||
) |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRemoteDataSourceImpl.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,59 @@ | ||
package app.cashadvisor.profile.data.impl | ||
|
||
import app.cashadvisor.common.utill.exceptions.NetworkException | ||
import app.cashadvisor.profile.data.api.ProfileInfoApiService | ||
import app.cashadvisor.profile.data.api.ProfileInfoRemoteDataSource | ||
import app.cashadvisor.profile.data.dto.request.UpdateProfilePicRequest | ||
import app.cashadvisor.profile.data.dto.request.UpdateUserNameRequest | ||
import app.cashadvisor.profile.data.dto.response.ConfirmUpdateNameResponse | ||
import app.cashadvisor.profile.data.dto.response.ConfirmUpdatePicResponse | ||
import app.cashadvisor.profile.data.dto.response.ProfileInfoResponse | ||
import app.cashadvisor.profile.data.mapper.NetworkToProfileExceptionMapper | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody.Companion.asRequestBody | ||
import javax.inject.Inject | ||
|
||
|
||
class ProfileInfoRemoteDataSourceImpl @Inject constructor( | ||
private val profileInfoApiService: ProfileInfoApiService, | ||
private val networkToProfileExceptionMapper: NetworkToProfileExceptionMapper | ||
) : ProfileInfoRemoteDataSource { | ||
override suspend fun getUserInfo(accessToken: String): ProfileInfoResponse { | ||
return try { | ||
val response = profileInfoApiService.getUserInfo(accessToken = accessToken) | ||
response | ||
} catch (exception: NetworkException) { | ||
throw networkToProfileExceptionMapper.handleExceptionGettingProfile(exception) | ||
} | ||
} | ||
|
||
override suspend fun updateUserName( | ||
dto: UpdateUserNameRequest, | ||
accessToken: String | ||
): ConfirmUpdateNameResponse { | ||
return try { | ||
profileInfoApiService.updateUserName( | ||
updateUserNameRequest = dto, | ||
accessToken = accessToken | ||
) | ||
} catch (exception: NetworkException) { | ||
throw networkToProfileExceptionMapper.handleExceptionUpdatingProfile(exception) | ||
} | ||
} | ||
|
||
override suspend fun updateProfilePic( | ||
dto: UpdateProfilePicRequest, | ||
accessToken: String | ||
): ConfirmUpdatePicResponse { | ||
val requestFile = dto.profilePic.asRequestBody("image/*".toMediaTypeOrNull()) | ||
val part = MultipartBody.Part.createFormData("image", dto.profilePic.name, requestFile) | ||
|
||
return try { | ||
profileInfoApiService.updateProfilePic(accessToken, part) | ||
} catch (exception: NetworkException) { | ||
throw networkToProfileExceptionMapper.handleExceptionUpdatingProfile(exception) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.