Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

126 41 connect with api editing profile #191

Open
wants to merge 50 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
23693c4
connect with api for chips
NadezhdaSakal Jun 10, 2024
4abe68f
Merge remote-tracking branch 'origin/develop' into 167-41--connect-wi…
NadezhdaSakal Jun 10, 2024
64d4727
add ChipsInteractor
NadezhdaSakal Jun 12, 2024
a42ec8c
fix header
NadezhdaSakal Jun 12, 2024
ffa67de
add recyclers for chips
NadezhdaSakal Jun 12, 2024
5e00fe9
Merge remote-tracking branch 'origin/develop' into 167-41--connect-wi…
NadezhdaSakal Jun 13, 2024
4a5b0d7
connect with api chip All
NadezhdaSakal Jun 14, 2024
6dc1fb1
fix detekt
NadezhdaSakal Jun 14, 2024
3c923e7
fix connect with api chip All
NadezhdaSakal Jun 14, 2024
c44a89a
fix chip project
NadezhdaSakal Jun 19, 2024
9b9ba3b
Merge remote-tracking branch 'origin/develop' into 167-41--connect-wi…
NadezhdaSakal Jun 19, 2024
9bdeab2
delete AuthInterceptor & add if
NadezhdaSakal Jun 19, 2024
17ee503
fix after detekt
NadezhdaSakal Jun 19, 2024
93b166b
fix layout
NadezhdaSakal Jun 19, 2024
7e8543b
fix connect chips
NadezhdaSakal Jun 19, 2024
baee54d
fix actions
NadezhdaSakal Jun 19, 2024
1083551
add di
NadezhdaSakal Jun 19, 2024
d5c8c83
add data
NadezhdaSakal Jun 19, 2024
5a3234d
add domain
NadezhdaSakal Jun 19, 2024
1653cd1
add presentation
NadezhdaSakal Jun 20, 2024
6ff0c80
add navigation
NadezhdaSakal Jun 28, 2024
1cf665c
Merge remote-tracking branch 'origin/develop' into 167-41--connect-wi…
NadezhdaSakal Jun 28, 2024
6ada545
resolve conflicts
NadezhdaSakal Jun 28, 2024
fad5ce0
Merge remote-tracking branch 'origin/develop' into 126-41-connect_wit…
NadezhdaSakal Jun 28, 2024
4fb41db
add plugin
NadezhdaSakal Jun 28, 2024
8b6e56e
add args
NadezhdaSakal Jun 28, 2024
aa78caa
fix after detekt
NadezhdaSakal Jun 28, 2024
ca0ab7d
Merge branch 'develop' into 167-41--connect-with-api-profile-chips
Jul 5, 2024
9e092c2
Add examples of common methods, fix item_news.xml guideline distance,…
Jul 6, 2024
f35eb50
Return detekt rules, refactoring, add marker NetworkModel for detekt
Jul 6, 2024
8c44d68
add fun getResult & refactor
NadezhdaSakal Jul 7, 2024
56f1714
refactor sealed interfaces
NadezhdaSakal Jul 7, 2024
0703d92
add extensions & refactor ProfileInfoRepoImplRepo
NadezhdaSakal Jul 7, 2024
744d6d5
add Response wrapper
NadezhdaSakal Jul 8, 2024
c7316ce
add catch blocks
NadezhdaSakal Jul 8, 2024
e9d7234
after detekt
NadezhdaSakal Jul 8, 2024
7406529
Merge branch 'develop' into 167-41--connect-with-api-profile-chips
NadezhdaSakal Jul 8, 2024
e69674c
refactor avatar profile
NadezhdaSakal Jul 9, 2024
0ddfe97
Merge remote-tracking branch 'origin/167-41--connect-with-api-profile…
NadezhdaSakal Jul 9, 2024
81bceaa
fix client
NadezhdaSakal Jul 10, 2024
ef50d2c
fix client
NadezhdaSakal Jul 10, 2024
ceca8ba
Fix news view, fix get response in ProfileRetrofitClient, fix show pl…
Jul 10, 2024
ce5fc06
add project
NadezhdaSakal Jul 10, 2024
9656b8e
Add get project by id request, add feedWithProject model
Jul 10, 2024
631d136
bind FeedWithProject
NadezhdaSakal Jul 10, 2024
8863801
bind FeedWithProject at ui
NadezhdaSakal Jul 10, 2024
40ebd3a
fix after detekt
NadezhdaSakal Jul 10, 2024
b9b57d1
Merge remote-tracking branch 'origin/167-41--connect-with-api-profile…
NadezhdaSakal Jul 10, 2024
00cf427
Merge remote-tracking branch 'origin/develop' into 126-41-connect_wit…
NadezhdaSakal Jul 10, 2024
d3173f0
add arguments
NadezhdaSakal Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ plugins {
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.ksp)
alias(libs.plugins.navigation.safeargs)
alias(libs.plugins.kotlinParcelize)

}

android {

namespace = "com.innoprog.android"
compileSdk = libs.versions.compileSdk.get().toInt()

Expand Down Expand Up @@ -79,4 +82,5 @@ dependencies {


implementation(project(":uikit"))

}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.innoprog.android.feature.profile.profiledetails.data.network
package com.innoprog.android.feature.profile.common

import com.google.gson.annotations.SerializedName
import com.innoprog.android.feature.profile.profiledetails.domain.models.ProfileCompany
import com.innoprog.android.network.data.Response

data class ProfileCompanyResponse(
Expand All @@ -15,3 +16,15 @@ data class ProfileCompanyResponse(
@SerializedName("role")
val role: String
) : Response()

fun ProfileCompanyResponse.mapToDomainCompany(): ProfileCompany {
return ProfileCompany(
id = id,
userId = userId,
name = name,
url = url,
role = role
)
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.innoprog.android.feature.profile.profiledetails.data.network
package com.innoprog.android.feature.profile.common

import com.google.gson.annotations.SerializedName
import com.innoprog.android.feature.profile.profiledetails.domain.models.CommunicationChannel
import com.innoprog.android.feature.profile.profiledetails.domain.models.Profile
import com.innoprog.android.network.data.Response

data class ProfileResponse(
Expand All @@ -16,3 +17,13 @@ data class ProfileResponse(
@SerializedName("authorities")
val authorities: List<String>
) : Response()

fun ProfileResponse.mapToDomainUserData(): Profile {
return Profile(
userId = userId,
name = name,
about = about,
communicationChannels = communicationChannels,
authorities = authorities
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.innoprog.android.feature.profile.editingprofile.data.impl

import com.innoprog.android.db.RoomDB
import com.innoprog.android.feature.profile.common.ProfileCompanyResponse
import com.innoprog.android.feature.profile.common.ProfileResponse
import com.innoprog.android.feature.profile.editingprofile.data.network.Request
import com.innoprog.android.feature.profile.editingprofile.domain.EditProfileInfoRepo
import com.innoprog.android.feature.profile.profiledetails.data.db.ProfileCompanyEntity
import com.innoprog.android.feature.profile.profiledetails.data.db.ProfileEntity
import com.innoprog.android.feature.profile.profiledetails.domain.models.Profile
import com.innoprog.android.feature.profile.profiledetails.domain.models.ProfileCompany
import com.innoprog.android.network.data.ApiConstants
import com.innoprog.android.network.data.NetworkClient
import com.innoprog.android.util.ErrorType
import com.innoprog.android.util.Resource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class EditProfileInfoRepoImpl @Inject constructor(
private val network: NetworkClient,
private val roomDB: RoomDB

) : EditProfileInfoRepo {

override suspend fun editProfile(name: String, about: String): Flow<Resource<Profile>> = flow {

val apiResponse =
network.doRequest(Request.PutProfile)

if (apiResponse is ProfileResponse && apiResponse.resultCode == ApiConstants.SUCCESS_CODE) {
emit(Resource.Success(mapToProfile(apiResponse)))
roomDB.profileDao().saveProfile(
ProfileEntity(
userId = apiResponse.userId,
name = apiResponse.name,
about = apiResponse.about,
communicationChannels = apiResponse.communicationChannels,
authorities = apiResponse.authorities
)
)
} else
emit(Resource.Error(getErrorType(apiResponse.resultCode)))
}

override suspend fun editProfileCompany(
name: String,
url: String,
role: String
): Flow<Resource<ProfileCompany>> = flow {
val response = network.doRequest(Request.PutProfileCompany)
if (response is ProfileCompanyResponse && response.resultCode == ApiConstants.SUCCESS_CODE) {
emit(Resource.Success(mapToProfileCompany(response)))
roomDB.profileCompanyDao().saveProfileCompany(
ProfileCompanyEntity(
id = response.id,
userId = response.userId,
name = response.name,
url = response.url,
role = response.role
)
)
} else
emit(Resource.Error(getErrorType(response.resultCode)))
}

private fun mapToProfile(response: ProfileResponse): Profile {
return Profile(
response.userId,
response.name,
response.about,
response.communicationChannels,
response.authorities
)
}

private fun mapToProfileCompany(response: ProfileCompanyResponse): ProfileCompany {
return ProfileCompany(
response.id,
response.userId,
response.name,
response.url,
response.role
)
}

private fun getErrorType(code: Int): ErrorType = when (code) {
ApiConstants.NO_INTERNET_CONNECTION_CODE -> ErrorType.NO_CONNECTION
ApiConstants.BAD_REQUEST_CODE -> ErrorType.BAD_REQUEST
ApiConstants.NOT_FOUND -> ErrorType.NOT_FOUND
else -> ErrorType.UNEXPECTED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.innoprog.android.feature.profile.editingprofile.data.network

import com.innoprog.android.feature.profile.common.ProfileCompanyResponse
import com.innoprog.android.feature.profile.common.ProfileResponse
import retrofit2.http.Body
import retrofit2.http.PUT

interface EditingProfileApi {

@PUT("/v1/profile")
suspend fun editProfile(
@Body body: EditingProfileBody
): ProfileResponse

@PUT("/v1/profile/company")
suspend fun editProfileCompany(
@Body body: EditingProfileCompanyBody
): ProfileCompanyResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.innoprog.android.feature.profile.editingprofile.data.network

import com.google.gson.annotations.SerializedName

data class EditingProfileBody(
@SerializedName("name")
val name: String,
@SerializedName("about")
val about: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.innoprog.android.feature.profile.editingprofile.data.network

import com.google.gson.annotations.SerializedName

data class EditingProfileCompanyBody(
@SerializedName("name")
val name: String,
@SerializedName("url")
val url: String,
@SerializedName("role")
val role: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.innoprog.android.feature.profile.editingprofile.data.network

sealed interface Request {
data object PutProfile : Request
data object PutProfileCompany : Request
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.innoprog.android.feature.profile.editingprofile.data.network

import com.innoprog.android.network.data.ApiConstants
import com.innoprog.android.network.data.NetworkClient
import com.innoprog.android.network.data.Response
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import retrofit2.HttpException
import javax.inject.Inject

class RetrofitClient @Inject constructor(
private val service: EditingProfileApi
) : NetworkClient {

override suspend fun doRequest(dto: Any): Response {

var response = Response()

return withContext(Dispatchers.IO) {
try {
response = when (dto) {

is Request.PutProfile -> {
val body = EditingProfileBody(name = "actual_name", about = "actual_about")
service.editProfile(body = body)
}

is Request.PutProfileCompany -> {
val body = EditingProfileCompanyBody(
name = "actual_name",
url = "actual_url",
role = "actual_role"
)
service.editProfileCompany(body = body)
}

else -> {
throw IllegalArgumentException("Unsupported request type")
}
}
response.apply { resultCode = ApiConstants.SUCCESS_CODE }
} catch (exception: HttpException) {
response.apply { resultCode = exception.code() }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.innoprog.android.feature.profile.editingprofile.di

import com.innoprog.android.di.AppComponent
import com.innoprog.android.di.ScreenComponent
import dagger.Component

@Component(
dependencies = [AppComponent::class],
modules = [EditingProfileModule::class]
)
interface EditingProfileComponent : ScreenComponent
interface EditingProfileComponent : ScreenComponent {
@Component.Builder
interface Builder {
fun build(): EditingProfileComponent
fun appComponent(appComponent: AppComponent): Builder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,49 @@ package com.innoprog.android.feature.profile.editingprofile.di

import androidx.lifecycle.ViewModel
import com.innoprog.android.di.ViewModelKey
import com.innoprog.android.feature.profile.editingprofile.data.impl.EditProfileInfoRepoImpl
import com.innoprog.android.feature.profile.editingprofile.data.network.EditingProfileApi
import com.innoprog.android.feature.profile.editingprofile.data.network.RetrofitClient
import com.innoprog.android.feature.profile.editingprofile.domain.EditProfileCompanyUseCase
import com.innoprog.android.feature.profile.editingprofile.domain.EditProfileInfoRepo
import com.innoprog.android.feature.profile.editingprofile.domain.EditProfileUseCase
import com.innoprog.android.feature.profile.editingprofile.domain.impl.EditProfileCompanyUseCaseImpl
import com.innoprog.android.feature.profile.editingprofile.domain.impl.EditProfileUseCaseImpl
import com.innoprog.android.feature.profile.editingprofile.presentation.EditingProfileViewModel
import com.innoprog.android.network.data.NetworkClient
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import retrofit2.Retrofit

@Module
@Module(
includes = [EditingProfileModule.EditProfileApiModule::class]
)
interface EditingProfileModule {

@IntoMap
@ViewModelKey(EditingProfileViewModel::class)
@Binds
fun bindEditingProfileViewModel(impl: EditingProfileViewModel): ViewModel

@Binds
fun bindRepository(impl: EditProfileInfoRepoImpl): EditProfileInfoRepo

@Binds
fun bindEditProfileUseCase(impl: EditProfileUseCaseImpl): EditProfileUseCase

@Binds
fun bindEditProfileCompanyUseCase(impl: EditProfileCompanyUseCaseImpl): EditProfileCompanyUseCase

@Binds
fun bindNetworkClient(impl: RetrofitClient): NetworkClient

@Module
class EditProfileApiModule {
@Provides
fun provideApi(retrofit: Retrofit): EditingProfileApi {
return retrofit.create(EditingProfileApi::class.java)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.innoprog.android.feature.profile.editingprofile.domain

import com.innoprog.android.feature.profile.profiledetails.domain.models.ProfileCompany
import com.innoprog.android.util.Resource
import kotlinx.coroutines.flow.Flow

interface EditProfileCompanyUseCase {
suspend fun editProfileCompany(name: String, url: String, role: String): Flow<Resource<ProfileCompany>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.innoprog.android.feature.profile.editingprofile.domain

import com.innoprog.android.feature.profile.profiledetails.domain.models.Profile
import com.innoprog.android.feature.profile.profiledetails.domain.models.ProfileCompany
import com.innoprog.android.util.Resource
import kotlinx.coroutines.flow.Flow

interface EditProfileInfoRepo {
suspend fun editProfile(name: String, about: String): Flow<Resource<Profile>>
suspend fun editProfileCompany(name: String, url: String, role: String): Flow<Resource<ProfileCompany>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.innoprog.android.feature.profile.editingprofile.domain

import com.innoprog.android.feature.profile.profiledetails.domain.models.Profile
import com.innoprog.android.util.Resource
import kotlinx.coroutines.flow.Flow

interface EditProfileUseCase {
suspend fun editProfile(name: String, about: String): Flow<Resource<Profile>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.innoprog.android.feature.profile.editingprofile.domain.impl

import com.innoprog.android.feature.profile.editingprofile.domain.EditProfileCompanyUseCase
import com.innoprog.android.feature.profile.editingprofile.domain.EditProfileInfoRepo
import com.innoprog.android.feature.profile.profiledetails.domain.models.ProfileCompany
import com.innoprog.android.util.Resource
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class EditProfileCompanyUseCaseImpl @Inject constructor(private val repository: EditProfileInfoRepo) :
EditProfileCompanyUseCase {

override suspend fun editProfileCompany(name: String, url: String, role: String): Flow<Resource<ProfileCompany>> {
return repository.editProfileCompany(name, url, role)
}
}
Loading
Loading