-
Notifications
You must be signed in to change notification settings - Fork 1
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 #43 from Team-Walkie/compose/add_post
게시글 업로드 구현
- Loading branch information
Showing
13 changed files
with
300 additions
and
65 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
26 changes: 0 additions & 26 deletions
26
data/src/main/java/com/whyranoid/data/datasource/PostDataSourceImpl.kt
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
data/src/main/java/com/whyranoid/data/datasource/post/PostDataSourceImpl.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,54 @@ | ||
package com.whyranoid.data.datasource.post | ||
|
||
import com.whyranoid.domain.datasource.PostDataSource | ||
import com.whyranoid.domain.model.post.Post | ||
import com.whyranoid.domain.model.post.PostPreview | ||
import okhttp3.MediaType | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import java.io.File | ||
|
||
class PostDataSourceImpl(private val postService: PostService) : PostDataSource { | ||
// TODO: change to api call | ||
override suspend fun getPostPreviews(uid: Long): Result<List<PostPreview>> { | ||
return Result.success(PostPreview.DUMMY_LIST) | ||
} | ||
|
||
override suspend fun getPostPreviews( | ||
uid: Long, | ||
year: Int, | ||
month: Int, | ||
day: Int, | ||
): Result<List<PostPreview>> { | ||
return Result.success(PostPreview.DUMMY_LIST) | ||
} | ||
|
||
// TODO: change to api call | ||
override suspend fun getPost(postId: Long): Result<Post> { | ||
return Result.success(Post.DUMMY) | ||
} | ||
|
||
override suspend fun uploadPost( | ||
uid: Long, | ||
content: String, | ||
colorMode: Int, | ||
history: String, | ||
imagePath: String, | ||
): Result<String> { | ||
val uidBody = RequestBody.create(MediaType.parse("text/plain"), uid.toString()) | ||
val contentBody = RequestBody.create(MediaType.parse("text/plain"), content) | ||
val colorModeBody = RequestBody.create(MediaType.parse("text/plain"), colorMode.toString()) | ||
val historyBody = RequestBody.create(MediaType.parse("text/plain"), history) | ||
|
||
val file = File(imagePath) | ||
val fileBody = RequestBody.create(MediaType.parse("image/*"), file) | ||
val imagePart = MultipartBody.Part.createFormData("image", file.name, fileBody) | ||
|
||
return kotlin.runCatching { | ||
val uploadPostResponse = | ||
postService.uploadPost(uidBody, contentBody, colorModeBody, historyBody, imagePart) | ||
.body() | ||
uploadPostResponse?.message.toString() | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
data/src/main/java/com/whyranoid/data/datasource/post/PostService.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,22 @@ | ||
package com.whyranoid.data.datasource.post | ||
|
||
import com.whyranoid.data.API | ||
import com.whyranoid.data.model.post.UploadPostResponse | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import retrofit2.Response | ||
import retrofit2.http.Multipart | ||
import retrofit2.http.POST | ||
import retrofit2.http.Part | ||
|
||
interface PostService { | ||
@Multipart | ||
@POST(API.UPLOAD_POST) | ||
suspend fun uploadPost( | ||
@Part("walkieId") walkieId: RequestBody, | ||
@Part("content") content: RequestBody, | ||
@Part("colorMode") colorMode: RequestBody, | ||
@Part("historyContent") historyContent: RequestBody, | ||
@Part image: MultipartBody.Part, | ||
): Response<UploadPostResponse> | ||
} |
6 changes: 6 additions & 0 deletions
6
data/src/main/java/com/whyranoid/data/model/post/UploadPostResponse.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,6 @@ | ||
package com.whyranoid.data.model.post | ||
|
||
data class UploadPostResponse( | ||
val status: Long, | ||
val message: String, | ||
) |
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
24 changes: 24 additions & 0 deletions
24
domain/src/main/java/com/whyranoid/domain/usecase/UploadPostUseCase.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,24 @@ | ||
package com.whyranoid.domain.usecase | ||
|
||
import com.whyranoid.domain.repository.AccountRepository | ||
import com.whyranoid.domain.repository.PostRepository | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class UploadPostUseCase @Inject constructor( | ||
private val postRepository: PostRepository, | ||
private val accountRepository: AccountRepository, | ||
) { | ||
suspend operator fun invoke( | ||
content: String, | ||
colorMode: Int, | ||
history: String, | ||
imagePath: String, | ||
): Result<String> { | ||
return accountRepository.uId.first()?.let { uid -> | ||
postRepository.uploadPost(uid, content, colorMode, history, imagePath) | ||
} ?: kotlin.run { | ||
Result.failure(Exception("Account Error")) | ||
} | ||
} | ||
} |
Oops, something went wrong.