-
Notifications
You must be signed in to change notification settings - Fork 3
[API] Feed 메인 화면 API 연결 #93
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
Changes from all commits
df5f9c5
a5c3f86
d12fd87
c3b2350
a06cd7a
9ccde48
337bc58
2a1943d
b7cd436
a61eaba
e02e98f
39197cb
deb4f03
46b98b6
ebfaa52
3116785
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.texthip.thip.data.model.feed.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class FeedDetailResponse( | ||
| @SerialName("feedId") val feedId: Int, | ||
| @SerialName("creatorId") val creatorId: Int, | ||
| @SerialName("creatorNickname") val creatorNickname: String, | ||
| @SerialName("creatorProfileImageUrl") val creatorProfileImageUrl: String?, | ||
| @SerialName("aliasName") val aliasName: String, | ||
| @SerialName("aliasColor") val aliasColor: String, | ||
| @SerialName("postDate") val postDate: String, | ||
| @SerialName("bookTitle") val bookTitle: String, | ||
| @SerialName("isbn") val isbn: String, | ||
| @SerialName("bookAuthor") val bookAuthor: String, | ||
| @SerialName("contentBody") val contentBody: String, | ||
| @SerialName("contentUrls") val contentUrls: List<String>, | ||
| @SerialName("likeCount") val likeCount: Int, | ||
| @SerialName("commentCount") val commentCount: Int, | ||
| @SerialName("isSaved") val isSaved: Boolean, | ||
| @SerialName("isLiked") val isLiked: Boolean, | ||
| @SerialName("isWriter") val isWriter: Boolean, | ||
| @SerialName("tagList") val tagList: List<String> | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.texthip.thip.data.model.feeds.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class AllFeedResponse( | ||
| @SerialName("feedList") val feedList: List<AllFeedItem>, | ||
| @SerialName("nextCursor") val nextCursor: String?, | ||
| @SerialName("isLast") val isLast: Boolean | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class AllFeedItem( | ||
| @SerialName("feedId") val feedId: Int, | ||
| @SerialName("creatorId") val creatorId: Int, | ||
| @SerialName("creatorNickname") val creatorNickname: String, | ||
| @SerialName("creatorProfileImageUrl") val creatorProfileImageUrl: String?, | ||
| @SerialName("aliasName") val aliasName: String, | ||
| @SerialName("aliasColor") val aliasColor: String, | ||
| @SerialName("postDate") val postDate: String, | ||
| @SerialName("isbn") val isbn: String, | ||
| @SerialName("bookTitle") val bookTitle: String, | ||
| @SerialName("bookAuthor") val bookAuthor: String, | ||
| @SerialName("contentBody") val contentBody: String, | ||
| @SerialName("contentUrls") val contentUrls: List<String>, | ||
| @SerialName("likeCount") val likeCount: Int, | ||
| @SerialName("commentCount") val commentCount: Int, | ||
| @SerialName("isSaved") val isSaved: Boolean, | ||
| @SerialName("isLiked") val isLiked: Boolean, | ||
| @SerialName("isWriter") val isWriter: Boolean | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.texthip.thip.data.model.feeds.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class MyFeedResponse( | ||
| @SerialName("feedList") val feedList: List<MyFeedItem>, | ||
| @SerialName("nextCursor") val nextCursor: String?, | ||
| @SerialName("isLast") val isLast: Boolean | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class MyFeedItem( | ||
| @SerialName("feedId") val feedId: Int, | ||
| @SerialName("postDate") val postDate: String, | ||
| @SerialName("isbn") val isbn: String, | ||
| @SerialName("bookTitle") val bookTitle: String, | ||
| @SerialName("bookAuthor") val bookAuthor: String, | ||
| @SerialName("contentBody") val contentBody: String, | ||
| @SerialName("contentUrls") val contentUrls: List<String>, | ||
| @SerialName("likeCount") val likeCount: Int, | ||
| @SerialName("commentCount") val commentCount: Int, | ||
| @SerialName("isPublic") val isPublic: Boolean, | ||
| @SerialName("isWriter") val isWriter: Boolean | ||
| ) |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,10 @@ import android.net.Uri | |||||||||||
| import com.texthip.thip.data.model.base.handleBaseResponse | ||||||||||||
| import com.texthip.thip.data.model.feed.request.CreateFeedRequest | ||||||||||||
| import com.texthip.thip.data.model.feed.response.CreateFeedResponse | ||||||||||||
| import com.texthip.thip.data.model.feed.response.FeedDetailResponse | ||||||||||||
| import com.texthip.thip.data.model.feed.response.FeedWriteInfoResponse | ||||||||||||
| import com.texthip.thip.data.model.feeds.response.AllFeedResponse | ||||||||||||
| import com.texthip.thip.data.model.feeds.response.MyFeedResponse | ||||||||||||
| import com.texthip.thip.data.service.FeedService | ||||||||||||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||||||||||||
| import kotlinx.coroutines.Dispatchers | ||||||||||||
|
|
@@ -70,22 +73,20 @@ class FeedRepository @Inject constructor( | |||||||||||
| // 임시 파일 목록 추적 | ||||||||||||
| val tempFiles = mutableListOf<File>() | ||||||||||||
|
|
||||||||||||
| try { | ||||||||||||
| // 이미지 파일들을 MultipartBody.Part로 변환 | ||||||||||||
| val imageParts = if (imageUris.isNotEmpty()) { | ||||||||||||
| withContext(Dispatchers.IO) { | ||||||||||||
| imageUris.mapNotNull { uri -> | ||||||||||||
| try { | ||||||||||||
| uriToMultipartBodyPart(uri, "images", tempFiles) | ||||||||||||
| } catch (e: Exception) { | ||||||||||||
| null | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| // 이미지 파일들을 MultipartBody.Part로 변환 | ||||||||||||
| val imageParts = if (imageUris.isNotEmpty()) { | ||||||||||||
| withContext(Dispatchers.IO) { | ||||||||||||
| imageUris.mapNotNull { uri -> | ||||||||||||
| runCatching { | ||||||||||||
| uriToMultipartBodyPart(uri, "images", tempFiles) | ||||||||||||
| }.getOrNull() | ||||||||||||
| } | ||||||||||||
| } else { | ||||||||||||
| null | ||||||||||||
| } | ||||||||||||
| } else { | ||||||||||||
| null | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| try { | ||||||||||||
| feedService.createFeed(requestBody, imageParts) | ||||||||||||
| .handleBaseResponse() | ||||||||||||
| .getOrThrow() | ||||||||||||
|
|
@@ -100,7 +101,7 @@ class FeedRepository @Inject constructor( | |||||||||||
| paramName: String, | ||||||||||||
| tempFiles: MutableList<File> | ||||||||||||
| ): MultipartBody.Part? { | ||||||||||||
| return try { | ||||||||||||
| return runCatching { | ||||||||||||
| // MIME 타입 확인 | ||||||||||||
| val mimeType = context.contentResolver.getType(uri) ?: "image/jpeg" | ||||||||||||
| val extension = when (mimeType) { | ||||||||||||
|
|
@@ -122,25 +123,45 @@ class FeedRepository @Inject constructor( | |||||||||||
| FileOutputStream(tempFile).use { outputStream -> | ||||||||||||
| inputStream.copyTo(outputStream) | ||||||||||||
| } | ||||||||||||
| } ?: return null | ||||||||||||
| } ?: throw IllegalStateException("Failed to open input stream for URI: $uri") | ||||||||||||
|
||||||||||||
| } ?: throw IllegalStateException("Failed to open input stream for URI: $uri") | |
| } ?: throw IllegalStateException( | |
| "Failed to open input stream for URI: $uri (paramName: $paramName, mimeType: $mimeType). " + | |
| "Possible causes: file not found, permission denied, or invalid URI." | |
| ) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,5 @@ | ||||||
| package com.texthip.thip.ui.feed.component | ||||||
|
|
||||||
| import androidx.compose.foundation.Image | ||||||
| import androidx.compose.foundation.background | ||||||
| import androidx.compose.foundation.clickable | ||||||
| import androidx.compose.foundation.layout.Arrangement | ||||||
|
|
@@ -18,33 +17,32 @@ import androidx.compose.runtime.Composable | |||||
| import androidx.compose.ui.Alignment | ||||||
| import androidx.compose.ui.Modifier | ||||||
| import androidx.compose.ui.draw.clip | ||||||
| import androidx.compose.ui.graphics.painter.Painter | ||||||
| import androidx.compose.ui.layout.ContentScale | ||||||
| import androidx.compose.ui.res.painterResource | ||||||
| import androidx.compose.ui.res.stringResource | ||||||
| import androidx.compose.ui.tooling.preview.Preview | ||||||
| import androidx.compose.ui.unit.dp | ||||||
| import androidx.compose.ui.zIndex | ||||||
| import coil.compose.AsyncImage | ||||||
| import com.texthip.thip.R | ||||||
| import com.texthip.thip.ui.theme.ThipTheme | ||||||
| import com.texthip.thip.ui.theme.ThipTheme.colors | ||||||
| import com.texthip.thip.ui.theme.ThipTheme.typography | ||||||
|
|
||||||
| @Composable | ||||||
| fun ImageViewerModal( | ||||||
| images: List<Painter>, | ||||||
| imageUrls: List<String>, | ||||||
| initialIndex: Int = 0, | ||||||
| onDismiss: () -> Unit | ||||||
| ) { | ||||||
| val pagerState = rememberPagerState( | ||||||
| initialPage = initialIndex, | ||||||
| pageCount = { images.size } | ||||||
| pageCount = { imageUrls.size } | ||||||
| ) | ||||||
|
|
||||||
| Box( | ||||||
| modifier = Modifier | ||||||
| .fillMaxSize() | ||||||
| .background(colors.Black) | ||||||
| .clickable { onDismiss() } | ||||||
| ) { | ||||||
| // 닫기 버튼 | ||||||
|
|
@@ -71,8 +69,8 @@ fun ImageViewerModal( | |||||
| modifier = Modifier.fillMaxSize(), | ||||||
| contentAlignment = Alignment.Center | ||||||
| ) { | ||||||
| Image( | ||||||
| painter = images[page], | ||||||
| AsyncImage( | ||||||
| model = imageUrls[page], | ||||||
| contentDescription = null, | ||||||
| contentScale = ContentScale.Fit, // 원본 비율 유지하면서 화면에 맞춤 | ||||||
| modifier = Modifier.fillMaxSize() | ||||||
|
|
@@ -81,14 +79,14 @@ fun ImageViewerModal( | |||||
| } | ||||||
|
|
||||||
| // 페이지 인디케이터 (이미지가 2개 이상일 때만 표시) | ||||||
| if (images.size > 1) { | ||||||
| if (imageUrls.size > 1) { | ||||||
| Row( | ||||||
| modifier = Modifier | ||||||
| .align(Alignment.BottomCenter) | ||||||
| .padding(20.dp), | ||||||
| horizontalArrangement = Arrangement.spacedBy(8.dp) | ||||||
| ) { | ||||||
| repeat(images.size) { index -> | ||||||
| repeat(imageUrls.size) { index -> | ||||||
| Box( | ||||||
| modifier = Modifier | ||||||
| .size(8.dp) | ||||||
|
|
@@ -103,9 +101,9 @@ fun ImageViewerModal( | |||||
| } | ||||||
|
|
||||||
| // 이미지 카운터 (예: 1/3) | ||||||
| if (images.size > 1) { | ||||||
| if (imageUrls.size > 1) { | ||||||
| Text( | ||||||
| text = stringResource(id = R.string.tag_count, images.size, 3), | ||||||
| text = stringResource(id = R.string.tag_count, pagerState.currentPage + 1, imageUrls.size), | ||||||
|
||||||
| text = stringResource(id = R.string.tag_count, pagerState.currentPage + 1, imageUrls.size), | |
| text = stringResource(id = R.string.image_counter, pagerState.currentPage + 1, imageUrls.size), |
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.
💡 Verification agent
🧩 Analysis chain
이미지 파트 생성: 실패를 조용히 무시 + 이중 runCatching + null/empty 의미 모호성
아래와 같이 “부분 실패 시 전체 업로드 실패”로 명확화하고(권장), 예외 로깅은 외부에서 단일 책임으로 처리해 주세요. 이 변경은 아래 uriToMultipartBodyPart 개선 제안(예외는 던지고 상위에서 처리)과 함께 적용되는 것을 전제합니다.
적용 제안(해당 범위 내 diff):
검증 필요사항:
검증 스크립트:
🏁 Script executed:
Length of output: 194
rg가
--type=kt를 인식하지 못해 파일 패턴을 수정하여 재확인합니다. 아래 스크립트를 실행해 주세요.🏁 Script executed:
Length of output: 14184
handleBaseResponse 확장 함수 정의를 찾지 못했습니다. 아래 스크립트를 실행해 위치를 확인해 주세요.
🏁 Script executed:
Length of output: 25793
uriToMultipartBodyPart 함수 정의 내에서 runCatching이 중복 사용되는지 확인합니다. 아래 스크립트를 실행해 주세요.
🏁 Script executed:
Length of output: 1307
uriToMultipartBodyPart 함수 내부에서 예외 처리 흐름(중복 runCatching 여부)을 전체 확인하기 위해 아래 스크립트를 실행해 주세요.
🏁 Script executed:
Length of output: 2041
부분 실패 시 전체 업로드 실패 처리 및 로깅 중앙화 필요
검증 결과:
images: List<MultipartBody.Part>?파라미터는null허용이 확인되었습니다.uriToMultipartBodyPart내부에서 이미runCatching { … }.onFailure { e.printStackTrace() }로 예외를 흘려보내고, 외부 호출부에서도runCatching { … }.getOrNull()을 사용해 중복 처리되고 있습니다.Timber는 사용되지 않고 있어, 로깅은android.util.Log.e또는 프로젝트 표준 로거로 일원화하는 것이 좋습니다.아래와 같이 “부분 실패 시 전체 실패 처리” 로직을 적용해 주세요:
uriToMultipartBodyPart내부의runCatching은 제거하고, 예외는 상위(위 코드)에서만 처리하도록 단일 책임을 부여합니다.android.util.Log.e또는 Timber 사용 시Timber.e로 교체해 주세요.📝 Committable suggestion
🤖 Prompt for AI Agents