Skip to content

Commit 7068886

Browse files
committed
feat: adding mappers and responses
1 parent 42dfee0 commit 7068886

File tree

14 files changed

+55
-14
lines changed

14 files changed

+55
-14
lines changed

app/src/main/java/com/paradoxo/materialgram/data/PostRepository.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.paradoxo.materialgram.data
33
import com.paradoxo.materialgram.data.local.PostLocalDataSource
44
import com.paradoxo.materialgram.data.network.PostService
55
import com.paradoxo.materialgram.domain.model.Post
6+
import com.paradoxo.materialgram.domain.toPost
67
import kotlinx.coroutines.flow.Flow
78
import kotlinx.coroutines.flow.flow
89
import javax.inject.Inject
@@ -24,7 +25,7 @@ class PostRepositoryImpl @Inject constructor(
2425
emit(localPosts)
2526
}
2627

27-
val remotePosts = postService.getPosts()
28+
val remotePosts = postService.getPosts().map { it.toPost() }
2829
emit(localPosts + remotePosts)
2930
}
3031
}

app/src/main/java/com/paradoxo/materialgram/data/VideoRepository.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.paradoxo.materialgram.data
33
import com.paradoxo.materialgram.data.local.VideoLocalDataSource
44
import com.paradoxo.materialgram.data.network.VideoService
55
import com.paradoxo.materialgram.domain.model.Reels
6+
import com.paradoxo.materialgram.domain.toReels
67
import kotlinx.coroutines.flow.Flow
78
import kotlinx.coroutines.flow.flow
89
import javax.inject.Inject
@@ -24,7 +25,7 @@ class VideoRepositoryImpl @Inject constructor(
2425
emit(localVideos)
2526
}
2627

27-
val remoteVideos = videoService.getVideos()
28+
val remoteVideos = videoService.getVideos().map { it.toReels() }
2829
emit(localVideos + remoteVideos)
2930
}
3031
}

app/src/main/java/com/paradoxo/materialgram/data/local/PostLocalDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PostLocalDataSource {
4848
val posts = listOf(
4949
Post(
5050
basePost = basePosts[0],
51-
medias = medias,
51+
images = medias,
5252
)
5353
)
5454
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.paradoxo.materialgram.data.model
2+
3+
import com.paradoxo.materialgram.domain.model.BasePost
4+
import com.paradoxo.materialgram.domain.model.Media
5+
6+
data class PostResponse(
7+
val basePost: BasePost,
8+
val medias: List<Media>,
9+
)
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.paradoxo.materialgram.data.model
2+
3+
import com.paradoxo.materialgram.domain.model.BasePost
4+
5+
6+
data class VideoResponse(
7+
val video: String,
8+
val thumbnail: String,
9+
val basePost: BasePost,
10+
)
11+
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.paradoxo.materialgram.data.network
22

3-
import com.paradoxo.materialgram.domain.model.Post
3+
import com.paradoxo.materialgram.data.model.PostResponse
44
import retrofit2.http.GET
55

66
interface PostService {
77

8-
@GET("posts.json")
9-
suspend fun getPosts(): List<Post>
8+
@GET("posts.json") // ".json" in the and because api is a mock from github pages
9+
suspend fun getPosts(): List<PostResponse>
1010
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.paradoxo.materialgram.data.network
22

3-
import com.paradoxo.materialgram.domain.model.Reels
3+
import com.paradoxo.materialgram.data.model.VideoResponse
44
import retrofit2.http.GET
55

66
interface VideoService {
77

8-
@GET("reels.json")
9-
suspend fun getVideos(): List<Reels>
8+
@GET("reels.json") // ".json" in the and because api is a mock from github pages
9+
suspend fun getVideos(): List<VideoResponse>
1010
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.paradoxo.materialgram.domain
2+
3+
import com.paradoxo.materialgram.data.model.PostResponse
4+
import com.paradoxo.materialgram.domain.model.Post
5+
6+
fun PostResponse.toPost(): Post = Post(
7+
basePost = basePost,
8+
images = medias
9+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.paradoxo.materialgram.domain
2+
3+
import com.paradoxo.materialgram.data.model.VideoResponse
4+
import com.paradoxo.materialgram.domain.model.Reels
5+
6+
fun VideoResponse.toReels(): Reels = Reels(
7+
video = video,
8+
thumbnail = thumbnail,
9+
basePost = basePost
10+
)

app/src/main/java/com/paradoxo/materialgram/domain/VideoUseCase.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ class VideoUseCaseImpl @Inject constructor(
1515
override suspend fun getVideos(): Flow<List<Reels>> {
1616
return repository.getVideos()
1717
}
18-
1918
}

0 commit comments

Comments
 (0)