-
Notifications
You must be signed in to change notification settings - Fork 0
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
✨ connect home layout to server via API #96
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
371a327
:lipstick: update feed item layout
kmkim2689 1b0af18
:lipstick: update feed item spacing
kmkim2689 8ba8966
:lock: add base urls to BaseConfig
kmkim2689 6fe6c48
:sparkles: add DTOs for recipe responses
kmkim2689 d86e9c1
:sparkles: implement retrofit client
kmkim2689 55f9fac
:sparkles: implement connection with server on HomeFragment
kmkim2689 249c9c2
:rotating_light: resolve kt lint warnings
kmkim2689 d8abd10
:green_heart: resolve kt lint failure
kmkim2689 24fd51b
:green_heart: add local.properties variable to ci pipeline
kmkim2689 8f91796
:green_heart: edit local.properties variable to ci pipeline
kmkim2689 5c75553
:rotating_light: resolve kt lint failure
kmkim2689 28c071e
:recycle: remove redundant @SerializedName annotations
kmkim2689 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 29 additions & 0 deletions
29
...pp/src/main/java/net/pengcook/android/data/datasource/feed/DefaultFeedRemoteDataSource.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,29 @@ | ||
package net.pengcook.android.data.datasource.feed | ||
|
||
import net.pengcook.android.data.model.feed.item.FeedItemResponse | ||
import net.pengcook.android.data.model.feed.step.RecipeStepResponse | ||
import net.pengcook.android.data.remote.api.FeedService | ||
import retrofit2.Response | ||
|
||
class DefaultFeedRemoteDataSource( | ||
private val feedService: FeedService, | ||
) : FeedRemoteDataSource { | ||
override suspend fun fetchRecipes( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
): Response<List<FeedItemResponse>> { | ||
return feedService.fetchRecipes(pageNumber, pageSize) | ||
} | ||
|
||
override suspend fun fetchRecipeSteps(recipeId: Long): Response<List<RecipeStepResponse>> { | ||
return feedService.fetchRecipeSteps(recipeId) | ||
} | ||
|
||
override suspend fun fetchRecipesByCategory( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
category: String, | ||
): Response<List<FeedItemResponse>> { | ||
return feedService.fetchRecipesByCategory(pageNumber, pageSize, category) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
android/app/src/main/java/net/pengcook/android/data/datasource/feed/FeedRemoteDataSource.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,20 @@ | ||
package net.pengcook.android.data.datasource.feed | ||
|
||
import net.pengcook.android.data.model.feed.item.FeedItemResponse | ||
import net.pengcook.android.data.model.feed.step.RecipeStepResponse | ||
import retrofit2.Response | ||
|
||
interface FeedRemoteDataSource { | ||
suspend fun fetchRecipes( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
): Response<List<FeedItemResponse>> | ||
|
||
suspend fun fetchRecipeSteps(recipeId: Long): Response<List<RecipeStepResponse>> | ||
|
||
suspend fun fetchRecipesByCategory( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
category: String, | ||
): Response<List<FeedItemResponse>> | ||
} |
Empty file.
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/net/pengcook/android/data/model/feed/item/AuthorResponse.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 net.pengcook.android.data.model.feed.item | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class AuthorResponse( | ||
@SerializedName("authorId") | ||
val authorId: Long, | ||
@SerializedName("authorImage") | ||
val authorImage: String, | ||
@SerializedName("authorName") | ||
val authorName: String, | ||
) | ||
10 changes: 10 additions & 0 deletions
10
android/app/src/main/java/net/pengcook/android/data/model/feed/item/CategoryResponse.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 net.pengcook.android.data.model.feed.item | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CategoryResponse( | ||
@SerializedName("categoryId") | ||
val categoryId: Long, | ||
@SerializedName("categoryName") | ||
val categoryName: String, | ||
) |
26 changes: 26 additions & 0 deletions
26
android/app/src/main/java/net/pengcook/android/data/model/feed/item/FeedItemResponse.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,26 @@ | ||
package net.pengcook.android.data.model.feed.item | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class FeedItemResponse( | ||
@SerializedName("author") | ||
val author: AuthorResponse, | ||
@SerializedName("category") | ||
val category: List<CategoryResponse>, | ||
@SerializedName("cookingTime") | ||
val cookingTime: String, | ||
@SerializedName("description") | ||
val description: String, | ||
@SerializedName("difficulty") | ||
val difficulty: Int, | ||
@SerializedName("ingredient") | ||
val ingredient: List<IngredientResponse>, | ||
@SerializedName("likeCount") | ||
val likeCount: Int, | ||
@SerializedName("recipeId") | ||
val recipeId: Long, | ||
@SerializedName("thumbnail") | ||
val thumbnail: String, | ||
@SerializedName("title") | ||
val title: String, | ||
) |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/net/pengcook/android/data/model/feed/item/IngredientResponse.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 net.pengcook.android.data.model.feed.item | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class IngredientResponse( | ||
@SerializedName("ingredientId") | ||
val ingredientId: Long, | ||
@SerializedName("ingredientName") | ||
val ingredientName: String, | ||
@SerializedName("requirement") | ||
val requirement: String, | ||
) |
16 changes: 16 additions & 0 deletions
16
android/app/src/main/java/net/pengcook/android/data/model/feed/step/RecipeStepResponse.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,16 @@ | ||
package net.pengcook.android.data.model.feed.step | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class RecipeStepResponse( | ||
@SerializedName("description") | ||
val description: String, | ||
@SerializedName("id") | ||
val id: Long, | ||
@SerializedName("image") | ||
val image: Any, | ||
@SerializedName("recipeId") | ||
val recipeId: Int, | ||
@SerializedName("sequence") | ||
val sequence: Int, | ||
) |
Empty file.
28 changes: 28 additions & 0 deletions
28
android/app/src/main/java/net/pengcook/android/data/remote/api/FeedService.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,28 @@ | ||
package net.pengcook.android.data.remote.api | ||
|
||
import net.pengcook.android.data.model.feed.item.FeedItemResponse | ||
import net.pengcook.android.data.model.feed.step.RecipeStepResponse | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
import retrofit2.http.Query | ||
|
||
interface FeedService { | ||
@GET("/api/recipes") | ||
suspend fun fetchRecipes( | ||
@Query("pageNumber") pageNumber: Int, | ||
@Query("pageSize") pageSize: Int, | ||
): Response<List<FeedItemResponse>> | ||
|
||
@GET("/api/recipes/{recipeId}/steps") | ||
suspend fun fetchRecipeSteps( | ||
@Path("recipeId") recipeId: Long, | ||
): Response<List<RecipeStepResponse>> | ||
|
||
@GET("/api/categories") | ||
suspend fun fetchRecipesByCategory( | ||
@Query("pageNumber") pageNumber: Int, | ||
@Query("pageSize") pageSize: Int, | ||
@Query("category") category: String, | ||
): Response<List<FeedItemResponse>> | ||
} |
61 changes: 61 additions & 0 deletions
61
android/app/src/main/java/net/pengcook/android/data/repository/feed/DefaultFeedRepository.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,61 @@ | ||
package net.pengcook.android.data.repository.feed | ||
|
||
import net.pengcook.android.data.datasource.feed.FeedRemoteDataSource | ||
import net.pengcook.android.data.model.feed.item.FeedItemResponse | ||
import net.pengcook.android.data.model.feed.step.RecipeStepResponse | ||
import net.pengcook.android.data.util.mapper.toFeed | ||
import net.pengcook.android.data.util.mapper.toRecipeStep | ||
import net.pengcook.android.data.util.network.NetworkResponseHandler | ||
import net.pengcook.android.presentation.core.model.Feed | ||
import net.pengcook.android.presentation.detail.RecipeStep | ||
import retrofit2.Response | ||
|
||
class DefaultFeedRepository( | ||
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. 왜 이름이 Default가 붙어있나요? 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. 기본 구현체 이름에 prefix로 Default를 붙이기로 저희 팀 컨벤션으로 정했기에 붙였습니다! |
||
private val feedRemoteDataSource: FeedRemoteDataSource, | ||
) : FeedRepository, NetworkResponseHandler { | ||
override suspend fun fetchRecipes( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
): Result<List<Feed>> { | ||
return runCatching { | ||
val response = feedRemoteDataSource.fetchRecipes(pageNumber, pageSize) | ||
body(response, RESPONSE_CODE_SUCCESS).map(FeedItemResponse::toFeed) | ||
} | ||
} | ||
|
||
override suspend fun fetchRecipeSteps(recipeId: Long): Result<List<RecipeStep>> { | ||
return runCatching { | ||
val response = feedRemoteDataSource.fetchRecipeSteps(recipeId) | ||
body(response, RESPONSE_CODE_SUCCESS).map(RecipeStepResponse::toRecipeStep) | ||
} | ||
} | ||
|
||
override suspend fun fetchRecipesByCategory( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
category: String, | ||
): Result<List<Feed>> { | ||
return runCatching { | ||
val response = | ||
feedRemoteDataSource.fetchRecipesByCategory(pageNumber, pageSize, category) | ||
body(response, RESPONSE_CODE_SUCCESS).map(FeedItemResponse::toFeed) | ||
} | ||
} | ||
|
||
override fun <T> body( | ||
response: Response<T>, | ||
validHttpCode: Int, | ||
): T { | ||
val code = response.code() | ||
val body = response.body() | ||
if (code != validHttpCode) throw RuntimeException(EXCEPTION_HTTP_CODE) | ||
if (body == null) throw RuntimeException(EXCEPTION_NULL_BODY) | ||
return body | ||
} | ||
|
||
companion object { | ||
private const val EXCEPTION_HTTP_CODE = "Http code is not appropriate." | ||
private const val EXCEPTION_NULL_BODY = "Response body is null." | ||
private const val RESPONSE_CODE_SUCCESS = 200 | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
android/app/src/main/java/net/pengcook/android/data/repository/feed/FeedRepository.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,19 @@ | ||
package net.pengcook.android.data.repository.feed | ||
|
||
import net.pengcook.android.presentation.core.model.Feed | ||
import net.pengcook.android.presentation.detail.RecipeStep | ||
|
||
interface FeedRepository { | ||
suspend fun fetchRecipes( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
): Result<List<Feed>> | ||
|
||
suspend fun fetchRecipeSteps(recipeId: Long): Result<List<RecipeStep>> | ||
|
||
suspend fun fetchRecipesByCategory( | ||
pageNumber: Int, | ||
pageSize: Int, | ||
category: String, | ||
): Result<List<Feed>> | ||
} |
26 changes: 26 additions & 0 deletions
26
android/app/src/main/java/net/pengcook/android/data/util/mapper/FeedMapper.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,26 @@ | ||
package net.pengcook.android.data.util.mapper | ||
|
||
import net.pengcook.android.data.model.feed.item.FeedItemResponse | ||
import net.pengcook.android.data.model.feed.step.RecipeStepResponse | ||
import net.pengcook.android.presentation.core.model.Feed | ||
import net.pengcook.android.presentation.detail.RecipeStep | ||
|
||
fun FeedItemResponse.toFeed(): Feed = | ||
Feed( | ||
id = recipeId, | ||
username = author.authorName, | ||
profileImageUrl = author.authorImage, | ||
recipeImageUrl = thumbnail, | ||
recipeTitle = title, | ||
likeCount = likeCount, | ||
commentCount = 0, | ||
) | ||
|
||
fun RecipeStepResponse.toRecipeStep(): RecipeStep = | ||
RecipeStep( | ||
stepId = id, | ||
recipeId = recipeId, | ||
description = description, | ||
image = image, | ||
sequence = sequence, | ||
) |
10 changes: 10 additions & 0 deletions
10
android/app/src/main/java/net/pengcook/android/data/util/network/NetworkResponseHandler.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 net.pengcook.android.data.util.network | ||
|
||
import retrofit2.Response | ||
|
||
interface NetworkResponseHandler { | ||
fun <T> body( | ||
response: Response<T>, | ||
validHttpCode: Int, | ||
): T | ||
} |
17 changes: 17 additions & 0 deletions
17
android/app/src/main/java/net/pengcook/android/data/util/network/RetrofitClient.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,17 @@ | ||
package net.pengcook.android.data.util.network | ||
|
||
import net.pengcook.android.BuildConfig | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitClient { | ||
private val retrofit = | ||
Retrofit.Builder() | ||
.baseUrl(BuildConfig.BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
|
||
fun <T> service(apiService: Class<T>): T { | ||
return retrofit.create(apiService) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/net/pengcook/android/presentation/detail/RecipeStep.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 net.pengcook.android.presentation.detail | ||
|
||
data class RecipeStep( | ||
val stepId: Long, | ||
val recipeId: Int, | ||
val description: String, | ||
val image: Any, | ||
val sequence: Int, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
SerializedName을 추가해야하나요? 어차피 변수명이랑 똑같은데
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.
제거하겠습니다!