-
Notifications
You must be signed in to change notification settings - Fork 1
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
내가 작성한 글 확인하기 기능 구현 #55
Merged
Merged
Changes from all commits
Commits
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
package com.whyranoid.data.datasource.post | ||
|
||
import android.util.Log | ||
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 | ||
import java.util.Date | ||
|
||
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) | ||
return kotlin.runCatching { | ||
val posts = requireNotNull(postService.getPosts(uid).body()) | ||
posts.map { it.toPostPreview() } | ||
} | ||
} | ||
|
||
override suspend fun getPostPreviews( | ||
|
@@ -20,7 +25,34 @@ class PostDataSourceImpl(private val postService: PostService) : PostDataSource | |
month: Int, | ||
day: Int, | ||
): Result<List<PostPreview>> { | ||
return Result.success(PostPreview.DUMMY_LIST) | ||
return getPostPreviews(uid).onSuccess { posts -> | ||
posts.filter { postPreview -> | ||
val date = Date(postPreview.date) | ||
Log.d("TODOREMOVE", "${date.year}, ${date.month + 1}, ${date.date}") | ||
date.month + 1 == month && year == date.year && day == date.date | ||
} | ||
} | ||
} | ||
|
||
override suspend fun getMyPostPreviews(uid: Long): Result<List<PostPreview>> { | ||
val response = postService.myPosts(uid) | ||
response.body()?.map { it.toPostPreview() } ?: throw Exception(response.message()) | ||
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. 추후에 Exception도 만들어야겠네요... 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. 넵 그리고 최근에 post 서버 내려갔었을 때 글 불러오니까 앱 터지더라구요 예외처리 안되어있는 부분 찾아서 해줘야 할 것 같습니다. |
||
return Result.success(response.body()?.map { it.toPostPreview() }!!) | ||
} | ||
|
||
override suspend fun getMyPostPreviews( | ||
uid: Long, | ||
year: Int, | ||
month: Int, | ||
day: Int, | ||
): Result<List<PostPreview>> { | ||
return getMyPostPreviews(uid).onSuccess { posts -> | ||
posts.filter { postPreview -> | ||
val date = Date(postPreview.date) | ||
Log.d("TODOREMOVE", "${date.year}, ${date.month + 1}, ${date.date}") | ||
date.month + 1 == month && year == date.year && day == date.date | ||
} | ||
} | ||
} | ||
|
||
// TODO: change to api call | ||
|
@@ -37,7 +69,8 @@ class PostDataSourceImpl(private val postService: PostService) : PostDataSource | |
): 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 colorModeBody = | ||
RequestBody.create(MediaType.parse("text/plain"), colorMode.toString()) | ||
val historyBody = RequestBody.create(MediaType.parse("text/plain"), history) | ||
|
||
val file = File(imagePath) | ||
|
@@ -46,7 +79,13 @@ class PostDataSourceImpl(private val postService: PostService) : PostDataSource | |
|
||
return kotlin.runCatching { | ||
val uploadPostResponse = | ||
postService.uploadPost(uidBody, contentBody, colorModeBody, historyBody, imagePart) | ||
postService.uploadPost( | ||
uidBody, | ||
contentBody, | ||
colorModeBody, | ||
historyBody, | ||
imagePart, | ||
) | ||
.body() | ||
uploadPostResponse?.message.toString() | ||
} | ||
|
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
20 changes: 20 additions & 0 deletions
20
data/src/main/java/com/whyranoid/data/model/account/UserResponse.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 com.whyranoid.data.model.account | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.whyranoid.domain.model.user.User | ||
|
||
data class UserResponse( | ||
@SerializedName("walkieId") val uid: Long, | ||
@SerializedName("nickname") val nickname: String, | ||
@SerializedName("profileImg") val profileImg: String, | ||
@SerializedName("status") val status: String, | ||
) { | ||
fun toUser(): User { | ||
return User( | ||
uid, | ||
status, | ||
nickname, | ||
profileImg, | ||
) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
data/src/main/java/com/whyranoid/data/model/post/PostResponse.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,38 @@ | ||
package com.whyranoid.data.model.post | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.whyranoid.data.model.account.UserResponse | ||
import com.whyranoid.domain.model.post.PostPreview | ||
import com.whyranoid.domain.model.post.TextVisibleState | ||
import com.whyranoid.domain.util.dateFormatter | ||
|
||
data class PostResponse( | ||
@SerializedName("viewerId") val viewerId: Long, | ||
@SerializedName("poster") val poster: UserResponse, | ||
@SerializedName("postId") val postId: Long, | ||
@SerializedName("liked") val liked: Boolean, | ||
@SerializedName("likers") val likers: List<UserResponse>, | ||
@SerializedName("photo") val photo: String, | ||
@SerializedName("content") val content: String, | ||
@SerializedName("date") val date: String, | ||
@SerializedName("colorMode") val colorMode: Long, | ||
@SerializedName("historyContent") val historyContent: String, | ||
) { | ||
fun toPostPreview(): PostPreview { | ||
val destructedHistoryContent = historyContent.split('_') | ||
println(destructedHistoryContent) | ||
return PostPreview( | ||
author = poster.toUser(), | ||
id = this.poster.uid, | ||
isLiked = this.liked, | ||
likers = this.likers.map { it.toUser() }, | ||
imageUrl = this.photo, | ||
date = dateFormatter.parse(this.date.replace("T", " ")).time, | ||
textVisibleState = TextVisibleState.values()[this.colorMode.toInt()], | ||
distanceText = destructedHistoryContent[2], | ||
timeText = destructedHistoryContent[3], | ||
paceText = destructedHistoryContent[4], | ||
address = destructedHistoryContent[1], | ||
) | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
domain/src/main/java/com/whyranoid/domain/model/post/PostPreview.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
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
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.
이 조건을 만족하는 애들만 뽑히는거죠?
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.
넵 맞습니다