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 1 commit
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
Prev Previous commit
Next Next commit
refactor: 코드리뷰 반영
  • Loading branch information
yeonjeen committed Aug 29, 2024
commit 3629ac7a02970e2fe5edfb77374fbe4e698c43ff
15 changes: 8 additions & 7 deletions app/src/main/java/com/teamwss/websoso/data/mapper/UserMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ 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.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 @@ -60,22 +60,23 @@ fun MyProfileResponseDto.toData(): MyProfileEntity {
)
}

fun GenrePreferenceDto.toData(): GenrePreferenceEntity {
fun GenrePreferenceResponseDto.GenrePreferenceDto.toData(): GenrePreferenceEntity {
val koreanGenreName = Genres.from(this.genreName)?.korean ?: this.genreName
return GenrePreferenceEntity(
genreName = this.genreName,
genreName = koreanGenreName,
genreImage = this.genreImage,
genreCount = this.genreCount,
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() }
keywords = this.keywords.map { it.toData() },
)
}

fun AttractivePointKeywordDto.toData(): NovelPreferenceEntity.KeywordEntity {
fun NovelPreferenceResponseDto.AttractivePointKeywordDto.toData(): NovelPreferenceEntity.KeywordEntity {
return NovelPreferenceEntity.KeywordEntity(
keywordName = this.keywordName,
keywordCount = this.keywordCount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
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
return GenrePreferenceEntity(
genreName = koreanGenreName,
genreImage = genreImage,
genreCount = genreCount,
)
}
) {
@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
Expand Up @@ -9,12 +9,12 @@ data class NovelPreferenceResponseDto(
val attractivePoints: List<String>,
@SerialName("keywords")
val keywords: List<AttractivePointKeywordDto>,
)

@Serializable
data class AttractivePointKeywordDto(
@SerialName("keywordName")
val keywordName: String,
@SerialName("keywordCount")
val keywordCount: Int,
)
) {
@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,6 +1,5 @@
package com.teamwss.websoso.ui.main.myPage

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -13,7 +12,7 @@ import javax.inject.Inject

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

private val _myProfile = MutableLiveData<MyProfileEntity>()
Expand All @@ -30,7 +29,6 @@ class MyPageViewModel @Inject constructor(
}.onSuccess { myProfile ->
_myProfile.value = myProfile
}.onFailure { exception ->
Log.e("MyPageViewModel", "Failed to load user profile", exception)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.teamwss.websoso.ui.main.myPage.myLibrary

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -16,23 +15,23 @@ import javax.inject.Inject

@HiltViewModel
class MyLibraryViewModel @Inject constructor(
private val userRepository: UserRepository
private val userRepository: UserRepository,
) :
ViewModel() {
private val _genres = MutableLiveData<List<GenrePreferenceEntity>>()
val genres: LiveData<List<GenrePreferenceEntity>> = _genres
val genres: LiveData<List<GenrePreferenceEntity>> get()= _genres

private val _dominantGenres = MutableLiveData<List<GenrePreferenceEntity>>()
val topGenres: LiveData<List<GenrePreferenceEntity>> = _dominantGenres
val topGenres: LiveData<List<GenrePreferenceEntity>> get()= _dominantGenres

private val _restGenres = MutableLiveData<List<GenrePreferenceEntity>>()
val restGenres: LiveData<List<GenrePreferenceEntity>> = _restGenres
val restGenres: LiveData<List<GenrePreferenceEntity>> get()= _restGenres

private val _isGenreListVisible = MutableLiveData<Boolean>(false)
val isGenreListVisible: LiveData<Boolean> = _isGenreListVisible
val isGenreListVisible: LiveData<Boolean> get()= _isGenreListVisible

private val _novelPreferences = MutableLiveData<NovelPreferenceEntity>()
val novelPreferences: LiveData<NovelPreferenceEntity> = _novelPreferences
val novelPreferences: LiveData<NovelPreferenceEntity> get()= _novelPreferences

private val _attractivePointsText = MutableLiveData<String>()
val attractivePointsText: LiveData<String> get() = _attractivePointsText
Expand All @@ -58,7 +57,6 @@ class MyLibraryViewModel @Inject constructor(
}.onSuccess { novelStats ->
_novelStats.value = novelStats
}.onFailure { exception ->
Log.e("NovelViewModel", "Failed to load novel counts", exception)
}
}
}
Expand All @@ -73,7 +71,6 @@ class MyLibraryViewModel @Inject constructor(
_dominantGenres.value = sortedGenres.take(3)
_restGenres.value = sortedGenres.drop(3)
}.onFailure { exception ->
Log.e("MyLibraryViewModel", "Failed to load genre preference", exception)
}
}
}
Expand All @@ -94,7 +91,6 @@ class MyLibraryViewModel @Inject constructor(
_novelPreferences.value = novelPreferences
_translatedAttractivePoints.value = translateAttractivePoints(novelPreferences.attractivePoints)
m6z1 marked this conversation as resolved.
Show resolved Hide resolved
}.onFailure { exception ->
Log.e("MyLibraryViewModel", "Failed to load novel preferences", exception)
}
}
}
Expand Down