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 23 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
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
android:screenOrientation="portrait" />
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".ui.notice.NoticeActivity"
Expand Down Expand Up @@ -102,5 +102,9 @@
android:name=".ui.myActivityDetail.MyActivityDetailActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".ui.otherUserPage.OtherUserPageActivity"
android:exported="false"
android:screenOrientation="portrait" />
</application>
</manifest>
41 changes: 40 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,10 +2,17 @@ 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.AttractivePointKeywordDto
import com.teamwss.websoso.data.remote.response.BlockedUsersResponseDto
import com.teamwss.websoso.data.remote.response.GenrePreferenceDto
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 @@ -42,4 +49,36 @@ 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 GenrePreferenceDto.toData(): GenrePreferenceEntity {
return GenrePreferenceEntity(
genreName = this.genreName,
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() }
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
)
}

fun AttractivePointKeywordDto.toData(): NovelPreferenceEntity.KeywordEntity {
return NovelPreferenceEntity.KeywordEntity(
keywordName = this.keywordName,
keywordCount = this.keywordCount
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
)
}

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>
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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,
val keywordCount: Int
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
)
}
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,29 @@
package com.teamwss.websoso.data.remote.response

import com.teamwss.websoso.data.model.GenrePreferenceEntity
import com.teamwss.websoso.ui.main.myPage.myActivity.model.Genres
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
){
fun toData(): GenrePreferenceEntity {
val koreanGenreName = Genres.from(genreName)?.korean ?: genreName // 한글로 변환
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
return GenrePreferenceEntity(
genreName = koreanGenreName,
genreImage = genreImage,
genreCount = genreCount
)
}
}
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,37 @@
package com.teamwss.websoso.ui.main.myPage

import android.util.Log
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
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 ->
Log.e("MyPageViewModel", "Failed to load user profile", exception)
yeonjeen marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
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
Loading