-
Notifications
You must be signed in to change notification settings - Fork 4
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
Iteration 1 review #31
Changes from all commits
a57bb50
ac63b45
efd902f
76374f6
9836c2b
e9d387a
f0eab54
6109e95
417441b
1de463b
c926178
e486849
cfd4e1f
068a38f
0e430d8
017eac5
c6ec080
0e88985
2f8f741
2e6cb40
8c747da
af5aed3
22ff440
0e79157
edfc8e4
bbb41b7
ccdd8fc
6d20ed4
fb03849
a4f9560
29d4783
0487daf
fa847a0
d56d68d
0066ebf
5fca205
0fd2ee9
8124282
d7fcced
3bd144b
a52f532
5615f46
6dca7f8
b197f39
6e36cbd
437f17b
8f2a4f9
b7d25bb
508aaa6
d6d30f8
da4ab58
2f5981d
8b05591
be6a8e7
93cfa3e
ef485b6
1a92e4d
6c0e151
abaecb7
ed83600
f107660
aa6efd3
7eda430
be6a618
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ru.practicum.android.diploma.data.db | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
|
||
@Database( | ||
version = 1, | ||
entities = [VacancyEntity::class] | ||
) | ||
abstract class AppDatabase : RoomDatabase() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ru.practicum.android.diploma.data.db | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "vacancy_table") | ||
data class VacancyEntity( | ||
@PrimaryKey(autoGenerate = true) | ||
val vacancyId: Int | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.practicum.android.diploma.data.db.dao | ||
|
||
import androidx.room.Dao | ||
|
||
@Dao | ||
interface VacancyDao | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ru.practicum.android.diploma.data.dto | ||
|
||
const val RESULT_CODE_NO_INTERNET = -1 | ||
const val RESULT_CODE_SUCCESS = 200 | ||
const val RESULT_CODE_BAD_REQUEST = 400 | ||
const val RESULT_CODE_SERVER_ERROR = 500 | ||
|
||
class Responce { | ||
var resultCode = 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ru.practicum.android.diploma.data.dto | ||
|
||
data class SearchRequest( | ||
val options: Map<String, String> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ru.practicum.android.diploma.data.dto | ||
|
||
data class VacancyRequest( | ||
val id: Int | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ru.practicum.android.diploma.data.network | ||
|
||
import retrofit2.http.GET | ||
import retrofit2.http.Headers | ||
import retrofit2.http.Path | ||
import retrofit2.http.QueryMap | ||
import ru.practicum.android.diploma.BuildConfig | ||
import ru.practicum.android.diploma.data.dto.Responce | ||
|
||
const val USER_AGENT_AUTHORIZATION = "Authorization: Bearer ${BuildConfig.HH_ACCESS_TOKEN}" | ||
const val USER_AGENT_APP_NAME = "HH-User-Agent: CareerHub ([email protected])" | ||
|
||
interface HHApiService { | ||
@Headers(USER_AGENT_AUTHORIZATION, USER_AGENT_APP_NAME) | ||
@GET("vacancies/{vacancy_id}") | ||
suspend fun getVacancy(@Path("vacancy_id") id: Int): Responce | ||
|
||
@Headers(USER_AGENT_AUTHORIZATION, USER_AGENT_APP_NAME) | ||
@GET("vacancies") | ||
suspend fun searchVacancies(@QueryMap options: Map<String, String>): Responce | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.practicum.android.diploma.data.network | ||
|
||
import ru.practicum.android.diploma.data.dto.Responce | ||
|
||
interface NetworkClient { | ||
suspend fun doRequest(dto: Any): Responce | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ru.practicum.android.diploma.data.network | ||
|
||
import android.content.Context | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import retrofit2.HttpException | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_BAD_REQUEST | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_NO_INTERNET | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_SERVER_ERROR | ||
import ru.practicum.android.diploma.data.dto.RESULT_CODE_SUCCESS | ||
import ru.practicum.android.diploma.data.dto.Responce | ||
import ru.practicum.android.diploma.data.dto.SearchRequest | ||
import ru.practicum.android.diploma.data.dto.VacancyRequest | ||
import ru.practicum.android.diploma.util.isInternetAvailable | ||
|
||
class RetrofitNetworkClient( | ||
private val hhApiService: HHApiService, | ||
private val context: Context | ||
) : NetworkClient { | ||
|
||
override suspend fun doRequest(dto: Any): Responce { | ||
if (!isInternetAvailable(context)) { | ||
return Responce().apply { resultCode = RESULT_CODE_NO_INTERNET } | ||
} | ||
return getResponce(dto = dto) | ||
} | ||
|
||
private suspend fun getResponce(dto: Any): Responce { | ||
return withContext(Dispatchers.IO) { | ||
try { | ||
when (dto) { | ||
is VacancyRequest -> { | ||
val response = hhApiService.getVacancy(dto.id) | ||
response.apply { resultCode = RESULT_CODE_SUCCESS } | ||
} | ||
|
||
is SearchRequest -> { | ||
val response = hhApiService.searchVacancies(options = dto.options) | ||
response.apply { resultCode = RESULT_CODE_SUCCESS } | ||
} | ||
|
||
else -> { | ||
Responce().apply { resultCode = RESULT_CODE_BAD_REQUEST } | ||
} | ||
} | ||
|
||
} catch (e: HttpException) { | ||
println("RetrofitClient error code: ${e.code()} message: ${e.message}") | ||
Responce().apply { resultCode = RESULT_CODE_SERVER_ERROR } | ||
} | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import androidx.room.Room | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.dsl.module | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import ru.practicum.android.diploma.data.db.AppDatabase | ||
import ru.practicum.android.diploma.data.network.HHApiService | ||
import ru.practicum.android.diploma.data.network.NetworkClient | ||
import ru.practicum.android.diploma.data.network.RetrofitNetworkClient | ||
|
||
const val BASE_URL = "https://api.hh.ru/" | ||
val dataModule = module { | ||
single<NetworkClient> { | ||
RetrofitNetworkClient( | ||
hhApiService = get(), | ||
context = androidContext() | ||
) | ||
} | ||
|
||
single<HHApiService> { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
.create(HHApiService::class.java) | ||
} | ||
single { | ||
Room.databaseBuilder(androidContext(), AppDatabase::class.java, "database.db") | ||
.fallbackToDestructiveMigration() | ||
.build() | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import org.koin.dsl.module | ||
|
||
val interactorModule = module { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import org.koin.dsl.module | ||
|
||
val repositoryModule = module { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.practicum.android.diploma.di | ||
|
||
import org.koin.dsl.module | ||
|
||
val viewModelModule = module { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.databinding.FragmentFavouritesBinding | ||
|
||
class FavouritesFragment : Fragment() { | ||
|
||
private val binding: FragmentFavouritesBinding by viewBinding(CreateMethod.INFLATE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. При использовании There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ко всем фрагментам это относится |
||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.fragment.findNavController | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.R | ||
import ru.practicum.android.diploma.databinding.FragmentFilterBinding | ||
|
||
class FilterFragment : Fragment() { | ||
|
||
private val binding: FragmentFilterBinding by viewBinding(CreateMethod.INFLATE) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
binding.buttonBackToSearchFromFilter.setOnClickListener { | ||
findNavController().navigate(R.id.mainFragment) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут либо |
||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.fragment.findNavController | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.R | ||
import ru.practicum.android.diploma.databinding.FragmentSearchBinding | ||
|
||
class SearchFragment : Fragment() { | ||
|
||
private val binding: FragmentSearchBinding by viewBinding(CreateMethod.INFLATE) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
binding.buttonToFilter.setOnClickListener { | ||
findNavController().navigate(R.id.action_searchFragment_to_filterFragment) | ||
} | ||
|
||
binding.buttonToVacancy.setOnClickListener { | ||
findNavController().navigate(R.id.action_searchFragment_to_vacancyFragment) | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ru.practicum.android.diploma.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import by.kirich1409.viewbindingdelegate.CreateMethod | ||
import by.kirich1409.viewbindingdelegate.viewBinding | ||
import ru.practicum.android.diploma.databinding.FragmentTeamBinding | ||
|
||
class TeamFragment : Fragment() { | ||
|
||
private val binding: FragmentTeamBinding by viewBinding(CreateMethod.INFLATE) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return binding.root | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Опечатка