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
feat: 장르/작품 선호 api 연결
  • Loading branch information
yeonjeen committed Aug 29, 2024
commit 9ab0aa9dc0464017908a2bef998b591fde3478f9
28 changes: 28 additions & 0 deletions app/src/main/java/com/teamwss/websoso/data/mapper/UserMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +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 @@ -54,3 +59,26 @@ fun MyProfileResponseDto.toData(): MyProfileEntity {
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
@@ -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
)
}
15 changes: 14 additions & 1 deletion 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,7 +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 @@ -44,5 +46,16 @@ interface UserApi {
)

@GET("users/my-profile")
suspend fun getMyProfile():MyProfileResponseDto
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,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
Expand Up @@ -2,14 +2,15 @@ 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
import com.teamwss.websoso.data.remote.api.UserApi
import com.teamwss.websoso.data.remote.request.UserInfoRequestDto
import com.teamwss.websoso.data.remote.request.UserProfileStatusRequestDto
import com.teamwss.websoso.data.remote.response.MyProfileResponseDto
import javax.inject.Inject

class UserRepository @Inject constructor(
Expand Down Expand Up @@ -44,7 +45,15 @@ class UserRepository @Inject constructor(
userApi.putUserInfo(UserInfoRequestDto(gender, birthYear))
}

suspend fun fetchMyProfile(): MyProfileEntity{
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()
}
}