forked from Yandex-Practicum/practicum-android-diploma
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #133 from AntaOtk/vacancy
исправить на хранение полной вакансии#122
- Loading branch information
Showing
14 changed files
with
117 additions
and
74 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
86 changes: 86 additions & 0 deletions
86
app/src/main/java/ru/practicum/android/diploma/data/VacancyEntityMapper.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,86 @@ | ||
package ru.practicum.android.diploma.data | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
import ru.practicum.android.diploma.data.db.entity.VacancyEntity | ||
import ru.practicum.android.diploma.domain.models.Contact | ||
import ru.practicum.android.diploma.domain.models.Phone | ||
import ru.practicum.android.diploma.domain.models.Salary | ||
import ru.practicum.android.diploma.domain.models.Vacancy | ||
import ru.practicum.android.diploma.domain.models.detail.FullVacancy | ||
import java.lang.reflect.Type | ||
|
||
class VacancyEntityMapper(private val gson: Gson) { | ||
fun toVacancyEntity(fullVacancy: FullVacancy): VacancyEntity { | ||
return VacancyEntity( | ||
fullVacancy.id, | ||
fullVacancy.name, | ||
fullVacancy.city, | ||
fullVacancy.employerName, | ||
fullVacancy.employerLogoUrl ?: "", | ||
gson.toJson(fullVacancy.salary), | ||
fullVacancy.alternate_url, | ||
fullVacancy.brandedDescription, | ||
fullVacancy.contacts?.name, | ||
fullVacancy.contacts?.email, | ||
gson.toJson(fullVacancy.contacts?.phones), | ||
fullVacancy.description, | ||
fullVacancy.experience, | ||
fullVacancy.employment, | ||
fullVacancy.skills | ||
) | ||
} | ||
fun fromVacancyEntityToList(vacancies: List<VacancyEntity>): List<Vacancy> { | ||
return vacancies.map { vacancy -> mapFromEntity(vacancy) } | ||
} | ||
|
||
private fun mapFromEntity(vacancyEntity: VacancyEntity): Vacancy { | ||
return Vacancy( | ||
vacancyEntity.id, | ||
vacancyEntity.name, | ||
vacancyEntity.city, | ||
vacancyEntity.employerName, | ||
0, | ||
vacancyEntity.employerLogoUrl, | ||
convertToSalary(vacancyEntity.salary), | ||
) | ||
} | ||
|
||
private fun convertToSalary(json: String?): Salary? { | ||
val myClassObject: Type = object : TypeToken<Salary>() {}.type | ||
return if (!json.isNullOrEmpty()) gson.fromJson(json, myClassObject) else null | ||
} | ||
|
||
fun fromVacancyEntityToFullVacancy(vacancy: VacancyEntity): FullVacancy { | ||
return FullVacancy( | ||
vacancy.id, | ||
vacancy.name, | ||
vacancy.city, | ||
vacancy.employerName, | ||
vacancy.employerLogoUrl, | ||
mapToSalary(vacancy.salary), | ||
vacancy.alternate_url, | ||
vacancy.brandedDescription, | ||
mapToContacts(vacancy), | ||
vacancy.description, | ||
vacancy.experience, | ||
vacancy.employment, | ||
vacancy.skills | ||
) | ||
|
||
} | ||
|
||
private fun mapToSalary(json: String?): Salary? { | ||
return gson.fromJson(json,Salary::class.java) | ||
} | ||
|
||
private fun mapToContacts(vacancy: VacancyEntity): Contact { | ||
val listOfMyClassObject: Type = object : TypeToken<ArrayList<Phone>?>() {}.type | ||
val phones: List<Phone> = if (!vacancy.contactPhones.isNullOrEmpty()) gson.fromJson(vacancy.contactPhones, listOfMyClassObject) else mutableListOf() | ||
return Contact( | ||
vacancy.contactName, | ||
vacancy.contactEmail, | ||
phones | ||
) | ||
} | ||
} |
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
Empty file.
9 changes: 0 additions & 9 deletions
9
app/src/main/java/ru/practicum/android/diploma/domain/detail/DetailInteractor.kt
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
app/src/main/java/ru/practicum/android/diploma/domain/detail/DetailRepository.kt
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
app/src/main/java/ru/practicum/android/diploma/domain/detail/impl/DetailInteractorImpl.kt
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
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