-
Notifications
You must be signed in to change notification settings - Fork 0
[feat/#18] 스터디 등록하기 화면 api 연동 #21
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
112b7e8
d72fa2a
295ce05
d2ed962
4b6d9b3
5ff4837
80bd5c9
4223500
8cbe110
f6c5c88
40db5ad
beb444e
3adc947
8d8160c
e28c4fe
0966055
82d077d
c4e864f
00563f7
fb32281
5b6ece0
61049d2
b950331
b4ed2c5
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,33 @@ | ||
| package com.umcspot.spot.common.util | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.Bitmap | ||
| import android.graphics.BitmapFactory | ||
| import android.net.Uri | ||
| import timber.log.Timber | ||
| import java.io.File | ||
| import java.io.FileOutputStream | ||
|
|
||
| object FileUtil { | ||
| fun createTempFileFromUri(context: Context, uri: Uri): File? { | ||
| return runCatching { | ||
| val inputStream = context.contentResolver.openInputStream(uri) | ||
| val bitmap = BitmapFactory.decodeStream(inputStream) | ||
| inputStream?.close() | ||
|
|
||
| if (bitmap == null) return null | ||
|
|
||
| val file = File.createTempFile("upload_image_", ".jpg", context.cacheDir) | ||
|
|
||
| FileOutputStream(file).use { outputStream -> | ||
| bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream) | ||
| } | ||
|
|
||
| bitmap.recycle() | ||
|
|
||
| file | ||
| }.onFailure { e -> | ||
| Timber.e(e, "이미지 압축 및 임시 파일 생성 실패") | ||
| }.getOrNull() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="25dp" | ||
| android:height="18dp" | ||
| android:viewportWidth="25" | ||
| android:viewportHeight="18"> | ||
| <path | ||
| android:pathData="M7.546,14.539L2.33,9.323C2.071,9.073 1.724,8.934 1.363,8.938C1.003,8.941 0.658,9.085 0.403,9.34C0.148,9.595 0.003,9.94 0,10.301C-0.003,10.661 0.136,11.008 0.386,11.268L6.573,17.455C6.831,17.713 7.181,17.858 7.546,17.858C7.91,17.858 8.26,17.713 8.518,17.455L23.643,2.33C23.893,2.071 24.032,1.724 24.029,1.363C24.025,1.003 23.881,0.658 23.626,0.403C23.371,0.148 23.026,0.003 22.666,0C22.305,-0.003 21.958,0.136 21.698,0.386L7.546,14.539Z" | ||
| android:fillColor="#005BFF"/> | ||
| </vector> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||||||
| package com.umcspot.spot.ui.extension | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||||||||||||||||||||||
| import okhttp3.MultipartBody | ||||||||||||||||||||||
| import okhttp3.RequestBody | ||||||||||||||||||||||
| import okhttp3.RequestBody.Companion.toRequestBody | ||||||||||||||||||||||
| import com.google.gson.Gson | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| fun Any.toRequestBody(): RequestBody { | ||||||||||||||||||||||
| val jsonString = Gson().toJson(this) | ||||||||||||||||||||||
| return jsonString.toRequestBody("application/json".toMediaTypeOrNull()) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gson 인스턴스를 재사용하여 성능을 개선하세요. 매번 새로운 🔎 제안하는 수정사항+private val gson = Gson()
+
fun Any.toRequestBody(): RequestBody {
- val jsonString = Gson().toJson(this)
+ val jsonString = gson.toJson(this)
return jsonString.toRequestBody("application/json".toMediaTypeOrNull())
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| fun Any.toMultipartBodyPart(name: String): MultipartBody.Part { | ||||||||||||||||||||||
| val requestBody = this.toRequestBody() | ||||||||||||||||||||||
| return MultipartBody.Part.createFormData(name, null, requestBody) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ android { | |
| } | ||
| dependencies { | ||
| implementation(projects.domain.study) | ||
| implementation(projects.core.ui) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,33 @@ | ||
| package com.umcspot.spot.study.dto.request | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import kotlinx.serialization.SerialName | ||
| import com.umcspot.spot.model.StudyStyle | ||
| import com.umcspot.spot.model.StudyTheme | ||
| import kotlinx.serialization.Serializable | ||
| import kotlinx.serialization.SerialName | ||
|
|
||
| @SuppressLint("UnsafeOptInUsageError") | ||
| @Serializable | ||
| data class StudyRequestDto( | ||
| @SerialName("studyId") | ||
| val studyId : Int | ||
| ) | ||
| @SerialName("name") | ||
| val name: String, | ||
|
|
||
| @SerialName("maxMembers") | ||
| val maxMembers: Int, | ||
|
|
||
| @SerialName("hasFee") | ||
| val hasFee: Boolean, | ||
|
|
||
| @SerialName("amount") | ||
| val amount: Int, | ||
|
|
||
| @SerialName("description") | ||
| val description: String, | ||
|
|
||
| @SerialName("categories") | ||
| val categories: List<StudyTheme>, | ||
|
|
||
| @SerialName("styles") | ||
| val styles: List<StudyStyle>, | ||
|
|
||
| @SerialName("regionCodes") | ||
| val regionCodes: List<String> | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.umcspot.spot.study.dto.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CreateStudyResponseDto( | ||
| @SerialName("studyId") | ||
| val studyId: Long | ||
| ) | ||
|
Comment on lines
+6
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# 프로젝트에서 kotlinx.serialization과 Gson 사용 패턴 확인
echo "=== kotlinx.serialization 사용 현황 ==="
rg -n --type=kotlin "@Serializable|@SerialName" | head -20
echo -e "\n=== Gson 사용 현황 ==="
rg -n --type=kotlin "@SerializedName|import com.google.gson" | head -20
echo -e "\n=== Gradle 의존성 확인 ==="
fd -e gradle -e kts -x grep -l "serialization\|gson" {}
echo -e "\n=== 전체 DTO 파일 현황 ==="
fd "Dto.kt$" | head -15Repository: SPOTeam/Android-V2 Length of output: 4749 🏁 Script executed: #!/bin/bash
# Gradle 의존성 파일 내용 확인
fd -e gradle -e kts | xargs grep -l "serialization\|gson" | head -5 | xargs catRepository: SPOTeam/Android-V2 Length of output: 1827 🏁 Script executed: cat data/study/build.gradle.ktsRepository: SPOTeam/Android-V2 Length of output: 257 🏁 Script executed: # 다른 DTO들의 직렬화 어노테이션 사용 패턴 확인
rg -n "@Serializable|@SerializedName" data/ -A 2 -B 2 | head -50Repository: SPOTeam/Android-V2 Length of output: 4482 CreateStudyResponseDto는 올바른 직렬화 라이브러리를 사용합니다. 대신 같은 모듈의 StudyRequestDto와 일관성을 맞추세요. 이 파일은 프로젝트 전역 표준인 🤖 Prompt for AI Agents |
||
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.
리소스 누수 위험: InputStream이 예외 발생 시 닫히지 않을 수 있습니다.
Line 14에서 열린
inputStream이 Line 15의decodeStream에서 예외가 발생하면 Line 16의close()가 실행되지 않아 리소스 누수가 발생합니다.use()블록을 사용하여 예외 발생 여부와 관계없이 스트림이 닫히도록 보장해야 합니다.🔎 리소스 관리 개선 제안
fun createTempFileFromUri(context: Context, uri: Uri): File? { return runCatching { - val inputStream = context.contentResolver.openInputStream(uri) - val bitmap = BitmapFactory.decodeStream(inputStream) - inputStream?.close() - - if (bitmap == null) return null + context.contentResolver.openInputStream(uri)?.use { inputStream -> + val bitmap = BitmapFactory.decodeStream(inputStream) + ?: return null - val file = File.createTempFile("upload_image_", ".jpg", context.cacheDir) + val file = File.createTempFile("upload_image_", ".jpg", context.cacheDir) - FileOutputStream(file).use { outputStream -> - bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream) - } + FileOutputStream(file).use { outputStream -> + bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream) + } - bitmap.recycle() + bitmap.recycle() - file + file + } }.onFailure { e -> Timber.e(e, "이미지 압축 및 임시 파일 생성 실패") }.getOrNull() }📝 Committable suggestion
🤖 Prompt for AI Agents