Skip to content
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

feat: 마이페이지 프로필 및 내 서재 api 연결 #262

Merged
merged 21 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion app/src/main/java/com/teamwss/websoso/data/mapper/UserMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ package com.teamwss.websoso.data.mapper

import com.teamwss.websoso.data.model.BlockedUsersEntity
import com.teamwss.websoso.data.model.BlockedUsersEntity.BlockedUserEntity
import com.teamwss.websoso.data.model.GenrePreferenceEntity
import com.teamwss.websoso.data.model.MyProfileEntity
import com.teamwss.websoso.data.model.NovelPreferenceEntity
import com.teamwss.websoso.data.model.UserInfoEntity
import com.teamwss.websoso.data.model.UserNovelStatsEntity
import com.teamwss.websoso.data.model.UserProfileStatusEntity
import com.teamwss.websoso.data.remote.response.BlockedUsersResponseDto
import com.teamwss.websoso.data.remote.response.GenrePreferenceResponseDto
import com.teamwss.websoso.data.remote.response.MyProfileResponseDto
import com.teamwss.websoso.data.remote.response.NovelPreferenceResponseDto
import com.teamwss.websoso.data.remote.response.UserInfoResponseDto
import com.teamwss.websoso.data.remote.response.UserNovelStatsResponseDto
import com.teamwss.websoso.data.remote.response.UserProfileStatusResponseDto
import com.teamwss.websoso.ui.main.myPage.myActivity.model.Genres

fun UserInfoResponseDto.toData(): UserInfoEntity {
return UserInfoEntity(
Expand Down Expand Up @@ -42,4 +49,37 @@ fun UserProfileStatusResponseDto.toData(): UserProfileStatusEntity {
return UserProfileStatusEntity(
isProfilePublic = isProfilePublic,
)
}
}

fun MyProfileResponseDto.toData(): MyProfileEntity {
return MyProfileEntity(
nickname = this.nickname,
intro = this.intro,
avatarImage = this.avatarImage,
genrePreferences = this.genrePreferences
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
)
}

fun GenrePreferenceResponseDto.GenrePreferenceDto.toData(): GenrePreferenceEntity {
val koreanGenreName = Genres.from(this.genreName)?.korean ?: this.genreName
return GenrePreferenceEntity(
genreName = koreanGenreName,
genreImage = this.genreImage,
genreCount = this.genreCount
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
)
}

fun NovelPreferenceResponseDto.toData(): NovelPreferenceEntity {
return NovelPreferenceEntity(
attractivePoints = this.attractivePoints,
keywords = this.keywords.map { it.toData() },
)
}

fun NovelPreferenceResponseDto.AttractivePointKeywordDto.toData(): NovelPreferenceEntity.KeywordEntity {
return NovelPreferenceEntity.KeywordEntity(
keywordName = this.keywordName,
keywordCount = this.keywordCount,
)
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.teamwss.websoso.data.model

data class GenrePreferenceEntity(
val genreIcon: String,
val genreImage: String,
val genreName: String,
val genreCount: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.teamwss.websoso.data.model

data class MyProfileEntity(
val nickname: String,
val intro: String,
val avatarImage: String,
val genrePreferences: List<String>,
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.teamwss.websoso.data.model

data class NovelPreferenceEntity(
val attractivePoint: Array<String>,
val keywords: Array<KeywordEntity>,
) {
val attractivePoints: List<String>,
val keywords: List<KeywordEntity>,
){
data class KeywordEntity(
val keywordName: String,
val keywordCount: Int,
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/teamwss/websoso/data/remote/api/UserApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.teamwss.websoso.data.remote.api
import com.teamwss.websoso.data.remote.request.UserInfoRequestDto
import com.teamwss.websoso.data.remote.request.UserProfileStatusRequestDto
import com.teamwss.websoso.data.remote.response.BlockedUsersResponseDto
import com.teamwss.websoso.data.remote.response.GenrePreferenceResponseDto
import com.teamwss.websoso.data.remote.response.MyProfileResponseDto
import com.teamwss.websoso.data.remote.response.NovelPreferenceResponseDto
import com.teamwss.websoso.data.remote.response.UserInfoResponseDto
import com.teamwss.websoso.data.remote.response.UserNovelStatsResponseDto
import com.teamwss.websoso.data.remote.response.UserProfileStatusResponseDto
Expand Down Expand Up @@ -41,4 +44,18 @@ interface UserApi {
suspend fun putUserInfo(
@Body userInfoRequestDto: UserInfoRequestDto,
)

@GET("users/my-profile")
suspend fun getMyProfile(): MyProfileResponseDto

@GET("users/{userId}/preferences/genres")
suspend fun getGenrePreference(
@Path("userId") userId: Long
): GenrePreferenceResponseDto

@GET("users/{userId}/preferences/attractive-points")
suspend fun getNovelPreferences(
@Path("userId") userId: Long
): NovelPreferenceResponseDto
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.teamwss.websoso.data.remote.response

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

@Serializable
data class GenrePreferenceResponseDto(
@SerialName("genrePreferences")
val genrePreferences: List<GenrePreferenceDto>,
) {
@Serializable
data class GenrePreferenceDto(
@SerialName("genreName")
val genreName: String,
@SerialName("genreImage")
val genreImage: String,
@SerialName("genreCount")
val genreCount: Int,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.teamwss.websoso.data.remote.response

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

@Serializable
data class MyProfileResponseDto(
@SerialName("nickname")
val nickname: String,
@SerialName("intro")
val intro: String,
@SerialName("avatarImage")
val avatarImage: String,
@SerialName("genrePreferences")
val genrePreferences: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.teamwss.websoso.data.remote.response

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

@Serializable
data class NovelPreferenceResponseDto(
@SerialName("attractivePoints")
val attractivePoints: List<String>,
@SerialName("keywords")
val keywords: List<AttractivePointKeywordDto>,
) {
@Serializable
data class AttractivePointKeywordDto(
@SerialName("keywordName")
val keywordName: String,
@SerialName("keywordCount")
val keywordCount: Int,
)
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
package com.teamwss.websoso.data.repository

import com.teamwss.websoso.data.model.GenrePreferenceEntity
import com.teamwss.websoso.data.model.NovelPreferenceEntity
import javax.inject.Inject

class FakeUserRepository @Inject constructor() {
val gender: String = "MALE"

fun getGenres(): List<GenrePreferenceEntity> {
return listOf(
GenrePreferenceEntity(
"https://cdn-icons-png.flaticon.com/512/660/660026.png",
"로판",
10
),
GenrePreferenceEntity(
"https://cdn-icons-png.flaticon.com/512/660/660026.png",
"로맨스",
8
),
GenrePreferenceEntity("https://cdn-icons-png.flaticon.com/512/660/660026.png", "무협", 6),
GenrePreferenceEntity(
"https://cdn-icons-png.flaticon.com/512/660/660026.png",
"판타지",
4
),
GenrePreferenceEntity("https://cdn-icons-png.flaticon.com/512/660/660026.png", "코믹", 2)
)
}

fun getNovelPreferences(): NovelPreferenceEntity {
val attractivePoints = arrayOf(
"character", "relationship", "material"
)
val keywords = arrayOf(
NovelPreferenceEntity.KeywordEntity("혐호관계", 2),
NovelPreferenceEntity.KeywordEntity("궁중암투", 4),
NovelPreferenceEntity.KeywordEntity("후회", 5),
NovelPreferenceEntity.KeywordEntity("정치물", 9),
NovelPreferenceEntity.KeywordEntity("빙의", 4)
)
return NovelPreferenceEntity(attractivePoints, keywords)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.teamwss.websoso.data.repository

import com.teamwss.websoso.data.mapper.toData
import com.teamwss.websoso.data.model.BlockedUsersEntity
import com.teamwss.websoso.data.model.GenrePreferenceEntity
import com.teamwss.websoso.data.model.MyProfileEntity
import com.teamwss.websoso.data.model.NovelPreferenceEntity
import com.teamwss.websoso.data.model.UserInfoEntity
import com.teamwss.websoso.data.model.UserNovelStatsEntity
import com.teamwss.websoso.data.model.UserProfileStatusEntity
Expand Down Expand Up @@ -41,4 +44,16 @@ class UserRepository @Inject constructor(
suspend fun saveUserInfo(gender: String, birthYear: Int) {
userApi.putUserInfo(UserInfoRequestDto(gender, birthYear))
}

suspend fun fetchMyProfile(): MyProfileEntity {
return userApi.getMyProfile().toData()
}

suspend fun fetchGenrePreference(userId: Long): List<GenrePreferenceEntity> {
return userApi.getGenrePreference(userId).genrePreferences.map { it.toData() }
}

suspend fun fetchNovelPreferences(userId: Long): NovelPreferenceEntity {
return userApi.getNovelPreferences(userId).toData()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import com.google.android.material.tabs.TabLayoutMediator
import com.teamwss.websoso.R
import com.teamwss.websoso.common.ui.base.BaseFragment
Expand All @@ -14,15 +15,22 @@ import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_page) {
private val myPageViewModel: MyPageViewModel by viewModels()
private val viewPagerAdapter by lazy { MyPageViewPagerAdapter(this) }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bindViewModel()
setUpViewPager()
setUpItemVisibilityOnToolBar()
onSettingButtonClick()
}

private fun bindViewModel() {
binding.myPageViewModel = myPageViewModel
binding.lifecycleOwner = viewLifecycleOwner
}

private fun setUpViewPager() {
val tabTitleItems =
listOf(getText(R.string.my_page_library), getText(R.string.my_page_activity))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.teamwss.websoso.ui.main.myPage

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.teamwss.websoso.data.model.MyProfileEntity
import com.teamwss.websoso.data.repository.UserRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MyPageViewModel @Inject constructor(
private val userRepository: UserRepository,
) : ViewModel() {

private val _myProfile = MutableLiveData<MyProfileEntity>()
val myProfile: LiveData<MyProfileEntity> get() = _myProfile

init {
updateUserProfile()
}

private fun updateUserProfile() {
viewModelScope.launch {
runCatching {
userRepository.fetchMyProfile()
}.onSuccess { myProfile ->
_myProfile.value = myProfile
}.onFailure { exception ->
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum class Genres(val korean: String) {
ROMANCEFANTASY("로판"),
BOYSLOVE("BL"),
FANTASY("판타지"),
MODERN_FANTASY("현판"),
MODERNFANTASY("현판"),
WUXIA("무협"),
DRAMA("드라마"),
MYSTERY("미스터리"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ class MyLibraryFragment : BaseFragment<FragmentMyLibraryBinding>(R.layout.fragme
}

private fun setUpObserve() {
myLibraryViewModel.genres.observe(viewLifecycleOwner) { genres ->
myLibraryViewModel.restGenres.observe(viewLifecycleOwner) { genres ->
restGenrePreferenceAdapter.updateRestGenrePreferenceData(genres)
}

myLibraryViewModel.isGenreListVisible.observe(viewLifecycleOwner) { isVisible ->
updateRestGenrePreferenceVisibility(isVisible)
}

myLibraryViewModel.attractivePointsText.observe(viewLifecycleOwner) { combinedText ->
myLibraryViewModel.translatedAttractivePoints.observe(viewLifecycleOwner) { translatedPoints ->
val combinedText =
translatedPoints.joinToString(", ") + getString(R.string.my_library_attractive_point_fixed_text)
applyTextColors(combinedText)
}

Expand All @@ -70,12 +72,13 @@ class MyLibraryFragment : BaseFragment<FragmentMyLibraryBinding>(R.layout.fragme

val spannableStringBuilder = SpannableStringBuilder()

val fixedText = getString(R.string.my_library_attractive_point_fixed_text).trim()
val attractivePointTextLength = combinedText.indexOf(fixedText)
val fixedText = getString(R.string.my_library_attractive_point_fixed_text)

if (attractivePointTextLength != -1) {
val splitText = combinedText.split(fixedText)

if (splitText.isNotEmpty()) {
val attractivePoints =
SpannableString(combinedText.substring(0, attractivePointTextLength)).apply {
SpannableString(splitText[0]).apply {
setSpan(
ForegroundColorSpan(primary100),
0,
Expand All @@ -86,7 +89,7 @@ class MyLibraryFragment : BaseFragment<FragmentMyLibraryBinding>(R.layout.fragme
spannableStringBuilder.append(attractivePoints)

val fixedSpannable =
SpannableString(combinedText.substring(attractivePointTextLength)).apply {
SpannableString(fixedText).apply {
setSpan(
ForegroundColorSpan(gray300),
0,
Expand All @@ -110,7 +113,6 @@ class MyLibraryFragment : BaseFragment<FragmentMyLibraryBinding>(R.layout.fragme
binding.tvMyLibraryAttractivePoints.text = spannableStringBuilder
}


private fun updateNovelPreferencesKeywords(novelPreferences: NovelPreferenceEntity) {
novelPreferences.keywords.forEach { keyword ->
val chip = createKeywordChip(keyword)
Expand Down
Loading