-
Notifications
You must be signed in to change notification settings - Fork 0
질문 좋아요 기능 구현 #32
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
Merged
The head ref may contain hidden characters: "31-\uC9C8\uBB38-\uC88B\uC544\uC694-\uD47C-\uBB38\uC81C-\uD655\uC778-\uAE30\uB2A5-\uAD6C\uD604"
Merged
질문 좋아요 기능 구현 #32
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad5c257
feat: Question 모델에 좋아요/푼 문제 필드 추가
chanho0908 1a326a5
feat: 사용자별 질문 조회를 위한 RPC 함수 연동
chanho0908 d2fd8ee
refactor: 'favorite' 용어를 'like'로 변경
chanho0908 b6475f3
feat: 질문 좋아요 기능 API 연동
chanho0908 9399ba2
test: 질문 좋아요 기능 테스트 추가
chanho0908 dafb621
feat: 질문 좋아요 UI 기능 구현
chanho0908 6e9da08
test: Domain 테스트에서 favorite 용어를 like로 수정
chanho0908 21d8870
refactor: uid를 메서드로 변경하여 상태 일관성 보장
chanho0908 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 32 additions & 27 deletions
59
.../com/peto/droidmorning/data/datasource/question/remote/DefaultRemoteQuestionDataSource.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,50 @@ | ||
| package com.peto.droidmorning.data.datasource.question.remote | ||
|
|
||
| import com.peto.droidmorning.data.model.LikeRequest | ||
| import com.peto.droidmorning.data.model.QuestionResponse | ||
| import io.github.jan.supabase.auth.Auth | ||
| import io.github.jan.supabase.postgrest.Postgrest | ||
| import io.github.jan.supabase.postgrest.query.Columns | ||
| import io.github.jan.supabase.postgrest.query.Order | ||
| import io.github.jan.supabase.postgrest.query.filter.TextSearchType | ||
| import io.github.jan.supabase.postgrest.rpc | ||
|
|
||
| class DefaultRemoteQuestionDataSource( | ||
| private val postgrest: Postgrest, | ||
| auth: Auth, | ||
| ) : RemoteQuestionDataSource { | ||
| override suspend fun fetchQuestions(): List<QuestionResponse> = | ||
| postgrest | ||
| .from(TABLE_NAME) | ||
| .select(columns = Columns.ALL) { | ||
| order(column = ORDER_BY_CREATED_AT, order = Order.DESCENDING) | ||
| }.decodeList<QuestionResponse>() | ||
| private val uid: String = | ||
| auth.currentSessionOrNull()?.user?.id | ||
| ?: throw IllegalStateException("User not logged in") | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| override suspend fun fetchQuestions(): List<QuestionResponse> { | ||
| val params = mapOf(RPC_FETCH_QUESTIONS_PARAM_NAME to uid) | ||
| return postgrest | ||
| .rpc(RPC_FETCH_QUESTIONS, params) | ||
| .decodeList<QuestionResponse>() | ||
| } | ||
|
|
||
| override suspend fun fetchQuestionsByCategory(category: String): List<QuestionResponse> = | ||
| override suspend fun addLike(questionId: Long) { | ||
| val request = LikeRequest(uid, questionId) | ||
| postgrest | ||
| .from(TABLE_NAME) | ||
| .select(columns = Columns.ALL) { | ||
| filter { | ||
| eq(CATEGORY_COLUMN, category) | ||
| } | ||
| order(column = ORDER_BY_CREATED_AT, order = Order.DESCENDING) | ||
| }.decodeList<QuestionResponse>() | ||
| .from(FAVORITES_TABLE) | ||
| .insert(request) | ||
| } | ||
|
|
||
| override suspend fun searchQuestions(query: String): List<QuestionResponse> = | ||
| override suspend fun removeLike(questionId: Long) { | ||
| postgrest | ||
| .from(TABLE_NAME) | ||
| .select(columns = Columns.ALL) { | ||
| .from(FAVORITES_TABLE) | ||
| .delete { | ||
| filter { | ||
| textSearch(FTS_COLUMN, query, TextSearchType.WEBSEARCH) | ||
| eq(USER_ID_COLUMN, uid) | ||
| eq(QUESTION_ID_COLUMN, questionId) | ||
| } | ||
| order(column = ORDER_BY_CREATED_AT, order = Order.DESCENDING) | ||
| }.decodeList<QuestionResponse>() | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val TABLE_NAME = "questions" | ||
| private const val CATEGORY_COLUMN = "category" | ||
| private const val FTS_COLUMN = "fts" | ||
| private const val ORDER_BY_CREATED_AT = "created_at" | ||
| private const val RPC_FETCH_QUESTIONS = "fetch_questions" | ||
| private const val RPC_FETCH_QUESTIONS_PARAM_NAME = "uid" | ||
|
|
||
| private const val FAVORITES_TABLE = "favorites" | ||
| private const val USER_ID_COLUMN = "user_id" | ||
| private const val QUESTION_ID_COLUMN = "question_id" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
data/src/commonMain/kotlin/com/peto/droidmorning/data/model/LikeRequest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.peto.droidmorning.data.model | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class LikeRequest( | ||
| @SerialName("user_id") | ||
| val userId: String, | ||
| @SerialName("question_id") | ||
| val questionId: Long, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: chanho0908/DroidMorning
Length of output: 154
🏁 Script executed:
Repository: chanho0908/DroidMorning
Length of output: 2691
🏁 Script executed:
Repository: chanho0908/DroidMorning
Length of output: 4874
필터링된 목록에서만 검색하므로 특정 상황에서 좋아요 토글이 무시될 수 있습니다.
낙관적 업데이트 패턴과 실패 시 롤백 처리가 잘 구현되었습니다.
toggleQuestionLike는 원본 데이터인allQuestions를 업데이트하고,filteredQuestions는 계산 속성(computed property)으로서 자동으로 변경사항을 반영하므로 상태 동기화 문제는 없습니다.다만 하나의 중요한 문제가 있습니다:
Line 87의 검색 범위 문제:
filteredQuestions에서만 질문을 찾고 있어, 현재 활성화된 필터에 의해 숨겨진 질문은 좋아요 토글이 실패합니다. 예를 들어 사용자가 "좋아요한 문제만" 필터 상태에서 좋아요 중인 문제를 토글하려고 하면, 해당 질문이filteredQuestions에 포함되지 않아 작업이 무시됩니다.개선 방안:
_uiState.value.allQuestions에서 검색하거나,allQuestions접근을 위한 공개 속성을 추가하는 것을 고려해볼 수 있습니다.성공 시
loadQuestions()호출로 서버와 재동기화할 필요는 없어 보입니다. 현재 구현은 낙관적 업데이트의 장점(빠른 응답)을 유지하면서 필요시에만 롤백하므로 효율적입니다.🤖 Prompt for AI Agents