Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into feature/#119-news-detail
Browse files Browse the repository at this point in the history
# Conflicts:
#	feature/news/src/main/java/com/teamwable/news/NewsTabType.kt
  • Loading branch information
chanubc committed Nov 26, 2024
2 parents 3dbfdc7 + a987de3 commit fedcb2f
Show file tree
Hide file tree
Showing 46 changed files with 683 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.teamwable.data.mapper.toData

import com.teamwable.network.dto.request.RequestPostCommentDto

internal fun Pair<String, String>.toPostCommentDto(): RequestPostCommentDto =
RequestPostCommentDto(first, second)
internal fun Triple<String, Long, Long>.toPostCommentDto(): RequestPostCommentDto =
RequestPostCommentDto(commentText = first, parentCommentId = second, parentCommentWriterId = third)
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,18 @@ internal fun ResponseCommentDto.toComment(): Comment =
this.time,
this.memberFanTeam,
this.contentId,
this.isBlind ?: false,
this.isBlind,
this.parentCommentId,
)

internal fun ResponseCommentDto.toComments(): List<Comment> {
val comments = mutableListOf<Comment>()

comments.add(this.toComment())

this.childComments?.forEach { child ->
comments.addAll(child.toComments())
}

return comments
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface CommentRepository {

suspend fun deleteComment(commentId: Long): Result<Unit>

suspend fun postComment(contentId: Long, commentText: String): Result<Unit>
suspend fun postComment(contentId: Long, commentInfo: Triple<String, Long, Long>): Result<Unit>

suspend fun postGhost(request: Ghost): Result<Unit>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ interface NewsRepository {
fun getNewsInfo(): Flow<PagingData<NewsInfoModel>>

fun getNoticeInfo(): Flow<PagingData<NewsInfoModel>>

suspend fun getNumber(): Result<Map<String, Int>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ interface UserInfoRepository {

fun getIsAdmin(): Flow<Boolean>

fun getNewsNumber(): Flow<Int>

fun getNoticeNumber(): Flow<Int>

suspend fun saveAccessToken(accessToken: String)

suspend fun saveRefreshToken(refreshToken: String)
Expand All @@ -35,6 +39,10 @@ interface UserInfoRepository {

suspend fun saveIsAdmin(isAdmin: Boolean)

suspend fun saveNewsNumber(newsNumber: Int)

suspend fun saveNoticeNumber(noticeNumber: Int)

suspend fun clearAll()

suspend fun clearForRefreshToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.teamwable.data.repositoryimpl
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.flatMap
import androidx.paging.map
import com.teamwable.data.mapper.toData.toPostCommentDto
import com.teamwable.data.mapper.toData.toPostCommentLikeDto
import com.teamwable.data.mapper.toData.toPostGhostDto
import com.teamwable.data.mapper.toModel.toComment
import com.teamwable.data.mapper.toModel.toComments
import com.teamwable.data.repository.CommentRepository
import com.teamwable.model.Comment
import com.teamwable.model.Ghost
Expand All @@ -28,7 +30,7 @@ internal class DefaultCommentRepository @Inject constructor(
getNextCursor = { comments -> comments.lastOrNull()?.commentId },
)
}.flow.map { pagingData ->
pagingData.map { it.toComment() }
pagingData.flatMap { it.toComments() }
}
}

Expand All @@ -50,9 +52,8 @@ internal class DefaultCommentRepository @Inject constructor(
return it.handleThrowable()
}

override suspend fun postComment(contentId: Long, commentText: String): Result<Unit> = runCatching {
val request = Pair(commentText, "comment").toPostCommentDto()
apiService.postComment(contentId, request)
override suspend fun postComment(contentId: Long, commentInfo: Triple<String, Long, Long>): Result<Unit> = runCatching {
apiService.postComment(contentId, commentInfo.toPostCommentDto())
Unit
}.onFailure {
return it.handleThrowable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ internal class DefaultNewsRepository @Inject constructor(
pagingData.map { it.toNoticeInfoModel() }
}
}

override suspend fun getNumber(): Result<Map<String, Int>> {
return runCatching {
mapOf(
"news" to newsService.getNumber().data.newsNumber,
"notice" to newsService.getNumber().data.noticeNumber
)
}.onFailure { return it.handleThrowable() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ internal class DefaultUserInfoRepository @Inject constructor(
override fun getIsAdmin(): Flow<Boolean> =
wablePreferencesDataSource.isAdmin

override fun getNewsNumber(): Flow<Int> =
wablePreferencesDataSource.newsNumber

override fun getNoticeNumber(): Flow<Int> =
wablePreferencesDataSource.noticeNumber

override suspend fun saveAccessToken(accessToken: String) {
wablePreferencesDataSource.updateAccessToken(accessToken)
}
Expand Down Expand Up @@ -64,6 +70,14 @@ internal class DefaultUserInfoRepository @Inject constructor(
wablePreferencesDataSource.updateIsAdmin(isAdmin)
}

override suspend fun saveNewsNumber(newsNumber: Int) {
wablePreferencesDataSource.updateNewsNumber(newsNumber)
}

override suspend fun saveNoticeNumber(noticeNumber: Int) {
wablePreferencesDataSource.updateNoticeNumber(noticeNumber)
}

override suspend fun clearAll() {
wablePreferencesDataSource.clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class DefaultWablePreferenceDatasource @Inject constructor(
val MemberProfileUrl = stringPreferencesKey("memberProfileUrl")
val IsPushAlarmAllowed = booleanPreferencesKey("isPushAlarmAllowed")
val IsAdmin = booleanPreferencesKey("isAdmin")
val NewsNumber = intPreferencesKey("newsNumber")
val NoticeNumber = intPreferencesKey("noticeNumber")
}

override val accessToken: Flow<String> = dataStore.data
Expand Down Expand Up @@ -76,6 +78,18 @@ class DefaultWablePreferenceDatasource @Inject constructor(
preferences[PreferencesKeys.IsAdmin] ?: false
}

override val newsNumber: Flow<Int> = dataStore.data
.catch { handleError(it) }
.map { preferences ->
preferences[PreferencesKeys.NewsNumber] ?: -1
}

override val noticeNumber: Flow<Int> = dataStore.data
.catch { handleError(it) }
.map { preferences ->
preferences[PreferencesKeys.NoticeNumber] ?: -1
}

override suspend fun updateAccessToken(accessToken: String) {
dataStore.edit { preferences ->
preferences[PreferencesKeys.AccessToken] = accessToken
Expand Down Expand Up @@ -124,6 +138,18 @@ class DefaultWablePreferenceDatasource @Inject constructor(
}
}

override suspend fun updateNewsNumber(newsNumber: Int) {
dataStore.edit { preferences ->
preferences[PreferencesKeys.NewsNumber] = newsNumber
}
}

override suspend fun updateNoticeNumber(noticeNumber: Int) {
dataStore.edit { preferences ->
preferences[PreferencesKeys.NoticeNumber] = noticeNumber
}
}

override suspend fun clear() {
dataStore.edit { preferences ->
preferences.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface WablePreferencesDataSource {
val memberProfileUrl: Flow<String>
val isPushAlarmAllowed: Flow<Boolean>
val isAdmin: Flow<Boolean>
val newsNumber: Flow<Int>
val noticeNumber: Flow<Int>

suspend fun updateAccessToken(accessToken: String)

Expand All @@ -28,6 +30,10 @@ interface WablePreferencesDataSource {

suspend fun updateIsAdmin(isAdmin: Boolean)

suspend fun updateNewsNumber(newsNumber: Int)

suspend fun updateNoticeNumber(noticeNumber: Int)

suspend fun clear()

suspend fun clearForRefreshToken()
Expand Down
1 change: 1 addition & 0 deletions core/model/src/main/java/com/teamwable/model/Comment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class Comment(
val postAuthorTeamTag: String,
val feedId: Long?,
val isBlind: Boolean,
val parentCommentId: Long?,
val ghostColor: String = GhostColor.DEFAULT_0,
val isAuth: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import retrofit2.http.Path
import retrofit2.http.Query

interface CommentService {
@GET("api/v2/content/{contentId}/comments")
@GET("api/v3/content/{contentId}/comments")
suspend fun getHomeDetailComments(
@Path(value = "contentId") contentId: Long,
@Query(value = "cursor") cursor: Long = -1,
Expand All @@ -31,7 +31,7 @@ interface CommentService {
@Path(value = "commentId") commentId: Long,
): BaseUnitResponse<Unit>

@POST("api/v1/content/{contentId}/comment")
@POST("api/v3/content/{contentId}/comment")
suspend fun postComment(
@Path(value = "contentId") contentId: Long,
@Body request: RequestPostCommentDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teamwable.network.datasource

import com.teamwable.network.dto.response.main.ResponseNewsNumberDto
import com.teamwable.network.dto.response.news.ResponseGameTypeDto
import com.teamwable.network.dto.response.news.ResponseNewsInfoDto
import com.teamwable.network.dto.response.news.ResponseNoticeInfoDto
Expand Down Expand Up @@ -28,4 +29,7 @@ interface NewsService {
suspend fun getNoticeInfo(
@Query(value = "cursor") contentId: Long = -1,
): BaseResponse<List<ResponseNoticeInfoDto>>

@GET("api/v1/information/number")
suspend fun getNumber(): BaseResponse<ResponseNewsNumberDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.teamwable.network.datasource

import com.teamwable.network.dto.response.notification.ResponseInformationDto
import com.teamwable.network.dto.response.notification.ResponseNotificationsDto
import com.teamwable.network.dto.response.notification.ResponseNumberDto
import com.teamwable.network.dto.response.notification.ResponseNotificationNumberDto
import com.teamwable.network.util.BaseResponse
import retrofit2.http.GET
import retrofit2.http.PATCH
import retrofit2.http.Query

interface NotificationService {
@GET("api/v1/notification/number")
suspend fun getNumber(): BaseResponse<ResponseNumberDto>
suspend fun getNumber(): BaseResponse<ResponseNotificationNumberDto>

@PATCH("api/v1/notification-check")
suspend fun patchCheck(): BaseResponse<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import kotlinx.serialization.Serializable
@Serializable
data class RequestPostCommentDto(
@SerialName("commentText") val commentText: String,
@SerialName("notificationTriggerType") val notificationTriggerType: String,
@SerialName("parentCommentId") val parentCommentId: Long,
@SerialName("parentCommentWriterId") val parentCommentWriterId: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ data class ResponseCommentDto(
@SerialName("commentImageUrl") val commentImageUrl: String? = null,
@SerialName("memberFanTeam") val memberFanTeam: String,
@SerialName("contentId") val contentId: Long? = null,
@SerialName("isBlind") val isBlind: Boolean? = null, // TODO::임시로 nullable 받음 대댓글 구현후 non-null 변경 예정
@SerialName("isBlind") val isBlind: Boolean,
@SerialName("parentCommentId") val parentCommentId: Long? = null, // -1 : 부모 댓글, null : profile의 comment, 이외 : 대댓글
@SerialName("childComments") val childComments: List<ResponseCommentDto>? = null, // null : 대댓글, [] : 부모 댓글의 대댓글 없음
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.teamwable.network.dto.response.main

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseNewsNumberDto(
@SerialName("newsNumber")
val newsNumber: Int = 0,
@SerialName("noticeNumber")
val noticeNumber: Int = 0
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseNumberDto(
data class ResponseNotificationNumberDto(
@SerialName("notificationNumber")
val notificationNumber: Int = 0
)
4 changes: 2 additions & 2 deletions core/ui/src/main/java/com/teamwable/ui/component/Snackbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class Snackbar(private val view: View, private val type: SnackbarType) {
}, duration)
}

fun updateToCommentComplete() {
initLayout(SnackbarType.COMMENT_COMPLETE)
fun updateToCommentComplete(type: SnackbarType) {
initLayout(type)
dismissSnackbar(1000)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.util.TypedValue
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.Toast
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
Expand Down Expand Up @@ -54,6 +55,12 @@ fun Context.hideKeyboard(view: View) {
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}

fun Context.showKeyboard(view: EditText) {
view.requestFocus()
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}

fun Context.openKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.showSoftInput(view, 0)
Expand Down
Loading

0 comments on commit fedcb2f

Please sign in to comment.