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

[Penify] Full Repo Documentation #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions app/src/main/kotlin/com/skydoves/sandwichdemo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ class MainActivity : AppCompatActivity() {
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
}
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
22 changes: 22 additions & 0 deletions app/src/main/kotlin/com/skydoves/sandwichdemo/MainRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ class MainRepository(
private val disneyService: DisneyService,
) {

/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
fun fetchPostersFlow(): Flow<ApiResponse<List<Poster>>> = flow {
val response = disneyService.fetchDisneyPosters()
emit(response)
Expand Down
35 changes: 33 additions & 2 deletions app/src/main/kotlin/com/skydoves/sandwichdemo/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ class MainViewModel(private val mainRepository: MainRepository) : ViewModel() {
retrofit()
}

/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
private fun retrofit() = viewModelScope.launch {
mainRepository.fetchPosters()
// handles the success scenario when the API request succeeds.
Expand Down Expand Up @@ -128,7 +139,17 @@ class MainViewModel(private val mainRepository: MainRepository) : ViewModel() {
}
}

// Ktor example
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
private fun ktor() = viewModelScope.launch {
val response = client.getApiResponse<PokemonResponse>("https://pokeapi.co/api/v2/pokemon") {
contentType(ContentType.Application.Json)
Expand All @@ -148,7 +169,17 @@ class MainViewModel(private val mainRepository: MainRepository) : ViewModel() {
}
}

// Ktorfit example
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
private fun ktorfit() = viewModelScope.launch {
val ktorfit = Ktorfit.Builder().baseUrl("https://pokeapi.co/api/v2/")
.converterFactories(ApiResponseConverterFactory.create())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ class MainViewModelFactory : ViewModelProvider.Factory {
}
throw IllegalArgumentException("Unknown ViewModel class.")
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
11 changes: 11 additions & 0 deletions app/src/main/kotlin/com/skydoves/sandwichdemo/SandwichDemoApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,15 @@ class SandwichDemoApp : Application() {
lateinit var sandwichApp: Application
private set
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,6 +48,17 @@ class PosterAdapter : RecyclerView.Adapter<PosterAdapter.PosterViewHolder>() {

private val items = mutableListOf<Poster>()

/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
fun addPosterList(posters: List<Poster>) {
items.clear()
items.addAll(posters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,34 @@ object RecyclerViewBinding {

@JvmStatic
@BindingAdapter("adapter")
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
fun bindAdapter(view: RecyclerView, posterAdapter: PosterAdapter) {
view.adapter = posterAdapter
}

@JvmStatic
@BindingAdapter("adapterPosterList")
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
fun bindAdapterPosterList(view: RecyclerView, posters: List<Poster>?) {
if (!posters.isNullOrEmpty()) {
(view.adapter as? PosterAdapter)?.addPosterList(posters)
Expand All @@ -39,6 +61,17 @@ object RecyclerViewBinding {

@JvmStatic
@BindingAdapter("loadImage")
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
fun bindLoadImage(view: AppCompatImageView, url: String) {
Glide.with(view.context)
.load(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ class MainDataSourceActivity : AppCompatActivity() {
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
}
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,15 @@ class MainDataSourceViewModel constructor(disneyService: DisneyDataSourceService
disposable.clear()
}
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ class MainDataSourceViewModelFactory : ViewModelProvider.Factory {
}
throw IllegalArgumentException("Unknown ViewModel class.")
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ object ErrorEnvelopeMapper : ApiErrorModelMapper<ErrorMessage> {
override fun map(apiErrorResponse: ApiResponse.Failure.Error): ErrorMessage {
return ErrorMessage(apiErrorResponse.statusCode.code, apiErrorResponse.message())
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ object SuccessPosterMapper : ApiSuccessModelMapper<List<Poster>, Poster?> {
override fun map(apiSuccessResponse: ApiResponse.Success<List<Poster>>): Poster? {
return apiSuccessResponse.data.firstOrNull()
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ import retrofit2.http.GET
interface DisneyDataSourceService {

@GET("DisneyPosters.json")
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
fun fetchDisneyPosterList(): DataSource<List<Poster>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,30 @@ import retrofit2.http.GET
interface DisneyService {

@GET("DisneyPosters.json")
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
suspend fun fetchDisneyPosters(): ApiResponse<List<Poster>>

@GET("DisneyPosters.json")
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
fun fetchDisneyPostersAsync(): Deferred<ApiResponse<List<Poster>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ import de.jensklingenberg.ktorfit.http.GET
public interface KtorfitPokemonService {

@GET("pokemon")
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
suspend fun getPokemon(): ApiResponse<PokemonResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ internal class RequestInterceptor : Interceptor {
Timber.d("$request")
return chain.proceed(request)
}
/**
* Transforms the sign-up request data to match the backend's expected format.
*
* @param {SignUpRequest} signUpData - The original sign-up request data.
*
* @returns {Object} The transformed sign-up request data with the following changes:
* - `firstName` is mapped to `first_name`
* - `lastName` is mapped to `last_name`
* - `email` is mapped to `username`
* - All other properties remain unchanged.
*/
}
Loading
Loading