-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT/#10] 앱에 서버 연결하기 #13
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
base: develop
Are you sure you want to change the base?
Changes from all commits
eb06f62
ced3768
7eba75b
811c202
580c6e3
a816788
3f694bc
43b9c15
888defb
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,13 @@ | ||
| package com.example.gundamdexapp | ||
|
|
||
| import android.app.Application | ||
| import com.example.gundamdexapp.data.network.AppContainer | ||
|
|
||
| class GundamApplication : Application() { | ||
| lateinit var appContainer: AppContainer | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
| appContainer = AppContainer() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.example.gundamdexapp.data.network | ||
|
|
||
| import com.example.gundamdexapp.data.network.repositoryImpl.GundamRepositoryImpl | ||
| import com.example.gundamdexapp.domain.repository.GundamRepository | ||
|
|
||
| class AppContainer { | ||
| val gundamRepository: GundamRepository by lazy { | ||
| GundamRepositoryImpl(SupabaseNetwork.gundamApi) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.example.gundamdexapp.data.network | ||
|
|
||
| import com.example.gundamdexapp.BuildConfig | ||
| import com.example.gundamdexapp.data.network.api.GundamApi | ||
| import kotlinx.serialization.json.Json | ||
| import okhttp3.MediaType.Companion.toMediaType | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.logging.HttpLoggingInterceptor | ||
| import retrofit2.Retrofit | ||
| import retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
|
|
||
| object SupabaseNetwork { | ||
| // Logcat에서 통신 로그를 보기 위한 설정 | ||
| private val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
| level = HttpLoggingInterceptor.Level.BODY | ||
| } | ||
|
|
||
| private val okHttpClient = OkHttpClient.Builder() | ||
| .addInterceptor(loggingInterceptor) | ||
| .build() | ||
|
|
||
| private val json = Json { | ||
| ignoreUnknownKeys = true | ||
| } | ||
|
|
||
| private val retrofit = Retrofit.Builder() | ||
| .baseUrl("${BuildConfig.SUPABASE_URL}/") | ||
| .client(okHttpClient) | ||
| .addConverterFactory(json.asConverterFactory("application/json".toMediaType())) | ||
| .build() | ||
|
|
||
| val gundamApi: GundamApi = retrofit.create(GundamApi::class.java) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.example.gundamdexapp.data.network.api | ||
|
|
||
| import com.example.gundamdexapp.BuildConfig | ||
| import com.example.gundamdexapp.data.network.dto.GundamDto | ||
| import retrofit2.Response | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.Header | ||
| import retrofit2.http.Query | ||
|
|
||
| interface GundamApi { | ||
| @GET("rest/v1/gundams") | ||
| suspend fun getGundams( | ||
| @Header("apikey") apikey: String = BuildConfig.SUPABASE_ANON_KEY, | ||
| @Header("Authorization") auth: String = "Bearer ${BuildConfig.SUPABASE_ANON_KEY}", | ||
| @Query("select") selectQuery: String = "*, armaments(*)", | ||
| ): Response<List<GundamDto>> | ||
|
|
||
| @GET("rest/v1/gundams") | ||
| suspend fun getGundamDetail( | ||
| @Header("apikey") apikey: String = BuildConfig.SUPABASE_ANON_KEY, | ||
| @Header("Authorization") auth: String = "Bearer ${BuildConfig.SUPABASE_ANON_KEY}", | ||
| @Query("id") idFilter: String, | ||
| @Query("select") selectQuery: String = "*, armaments(*)", | ||
| ): Response<List<GundamDto>> | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||||||||||||||
| package com.example.gundamdexapp.data.network.dto | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import com.example.gundamdexapp.domain.model.Armament | ||||||||||||||||||||||||||||||
| import kotlinx.serialization.SerialName | ||||||||||||||||||||||||||||||
| import kotlinx.serialization.Serializable | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @Serializable | ||||||||||||||||||||||||||||||
| data class ArmamentDto( | ||||||||||||||||||||||||||||||
| @SerialName("gundam_id") | ||||||||||||||||||||||||||||||
| val gundamId: String, | ||||||||||||||||||||||||||||||
| val name: String, | ||||||||||||||||||||||||||||||
| val details: String? = null, | ||||||||||||||||||||||||||||||
| @SerialName("indicator_color") | ||||||||||||||||||||||||||||||
| val indicatorColor: String, | ||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
| fun toDomain(): Armament = Armament( | ||||||||||||||||||||||||||||||
| name = this.name, | ||||||||||||||||||||||||||||||
| details = this.details ?: "", | ||||||||||||||||||||||||||||||
| indicatorColor = this.indicatorColor, | ||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+19
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. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🛡️ 제안 수정 `@SerialName`("indicator_color")
- val indicatorColor: String,
+ val indicatorColor: String? = null,
) {
fun toDomain(): Armament = Armament(
name = this.name,
details = this.details ?: "",
- indicatorColor = this.indicatorColor,
+ indicatorColor = this.indicatorColor ?: "",
)
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.example.gundamdexapp.data.network.dto | ||
|
|
||
| import com.example.gundamdexapp.domain.model.Armaments | ||
| import com.example.gundamdexapp.domain.model.Dimensions | ||
| import com.example.gundamdexapp.domain.model.GundamInfo | ||
| import com.example.gundamdexapp.domain.model.TechnicalSpecifications | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class GundamDto( | ||
| val id: String, | ||
| @SerialName("model_number") | ||
| val modelNumber: String? = null, | ||
| val name: String, | ||
| val series: String, | ||
| @SerialName("image_url") | ||
| val imageUrl: String? = null, | ||
| val era: String, | ||
| val faction: String, | ||
| val pilot: String? = null, | ||
| val description: String, | ||
| @SerialName("dim_weight") | ||
| val weight: String? = null, | ||
| @SerialName("dim_height") | ||
| val height: String? = null, | ||
| @SerialName("tech_generator_output") | ||
| val generatorOutput: String? = null, | ||
| @SerialName("tech_armor_material") | ||
| val armorMaterial: String? = null, | ||
| @SerialName("tech_total_trust") | ||
| val totalTrust: String? = null, | ||
| @SerialName("tech_sensor_radius") | ||
| val sensorRadius: String? = null, | ||
| @SerialName("tech_crew") | ||
| val crew: String? = null, | ||
| val armaments: List<ArmamentDto> = emptyList(), | ||
| ) { | ||
| fun toDomain(): GundamInfo = GundamInfo( | ||
| id = this.id, | ||
| modelNumber = this.modelNumber ?: MISSING_TEXT, | ||
| name = this.name, | ||
| series = this.series, | ||
| imageUrl = this.imageUrl ?: MISSING_URL, | ||
| era = this.era, | ||
| faction = this.faction, | ||
| pilot = this.pilot ?: MISSING_TEXT, | ||
| description = this.description, | ||
| dimensions = Dimensions( | ||
| height = this.height ?: MISSING_TEXT, | ||
| weight = this.weight ?: MISSING_TEXT, | ||
| ), | ||
| technicalSpecifications = TechnicalSpecifications( | ||
| generatorOutput = this.generatorOutput ?: MISSING_TEXT, | ||
| armorMaterial = this.armorMaterial ?: MISSING_TEXT, | ||
| totalTrust = this.totalTrust ?: MISSING_TEXT, | ||
| sensorRadius = this.sensorRadius ?: MISSING_TEXT, | ||
| crew = this.crew ?: MISSING_TEXT, | ||
| ), | ||
| armaments = Armaments(this.armaments.map { it.toDomain() }), | ||
| ) | ||
|
|
||
| companion object { | ||
| const val MISSING_TEXT = "[ ? ]" | ||
| const val MISSING_URL = | ||
| "https://imgfiles-cdn.plaync.com/file/BladeNSoul/download/20190802085052-S4BOYrvsgcmithzSaShj0-v4" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.example.gundamdexapp.data.network.repositoryImpl | ||
|
|
||
| import com.example.gundamdexapp.data.network.api.GundamApi | ||
| import com.example.gundamdexapp.domain.model.GundamInfo | ||
| import com.example.gundamdexapp.domain.repository.GundamRepository | ||
|
|
||
| class GundamRepositoryImpl( | ||
| private val api: GundamApi, | ||
| ) : GundamRepository { | ||
| override suspend fun getGundamList(): Result<List<GundamInfo>> = try { | ||
| val response = api.getGundams() | ||
|
|
||
| if (response.isSuccessful) { | ||
| val dtoList = response.body() ?: emptyList() | ||
|
|
||
| val domainList = dtoList.map { it.toDomain() } | ||
| Result.success(domainList) | ||
| } else { | ||
| Result.failure(Exception("서버 통신 실패 : ${response.code()}")) | ||
| } | ||
| } catch (e: Exception) { | ||
| Result.failure(e) | ||
| } | ||
|
|
||
| override suspend fun getGundamDetail(id: String): Result<List<GundamInfo>> = try { | ||
| val response = api.getGundamDetail(idFilter = "eq.$id") | ||
|
|
||
| if (response.isSuccessful) { | ||
| val gundamDto = response.body() ?: emptyList() | ||
|
|
||
| val domainList = gundamDto.map { it.toDomain() } | ||
| Result.success(domainList) | ||
| } else { | ||
| Result.failure(Exception("서버 통신 실패 : ${response.code()}")) | ||
| } | ||
|
Comment on lines
+25
to
+35
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. 🩺 Stability & Availability | 🟡 Minor 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# 상세 ViewModel에서 getGundamDetail 결과 처리 방식 확인
rg -nP 'getGundamDetail|\.first\(|\[0\]|getOrNull' --type=kotlin -C3 app/src/main/java/com/example/gundamdexapp/feature/detailRepository: noeyhoj/Gundamdex Length of output: 1572 빈 결과 처리 로직 상세 설명
상세 조회 API 가 존재하지 않는 경우 빈 리스트를 성공 응답으로 반환할 때, 이를 🤖 Prompt for AI Agents |
||
| } catch (e: Exception) { | ||
| Result.failure(e) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.example.gundamdexapp.domain.repository | ||
|
|
||
| import com.example.gundamdexapp.domain.model.GundamInfo | ||
|
|
||
| interface GundamRepository { | ||
| suspend fun getGundamList(): Result<List<GundamInfo>> | ||
| suspend fun getGundamDetail(id: String): Result<List<GundamInfo>> | ||
| } |
This file was deleted.
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.
🔒 Security & Privacy | 🟠 Major
🧩 Analysis chain
🌐 Web query:
Does OkHttp HttpLoggingInterceptor Level.BODY log request headers like Authorization?💡 Result:
Yes, the OkHttp HttpLoggingInterceptor at Level.BODY will log request headers, including sensitive ones like Authorization, by default [1][2][3]. Because the BODY and HEADERS levels log all request and response headers, they pose a risk of leaking sensitive information such as authentication tokens, cookies, or other private data [2][4][5]. OkHttp explicitly warns that these levels should only be used in controlled or non-production environments to avoid accidental exposure [2][4]. To prevent sensitive headers from being logged, you must explicitly redact them using the redactHeader method [2][4][5]: logging.redactHeader("Authorization"); logging.redactHeader("Cookie"); Once redacted, the interceptor will replace the header's value in the logs with a placeholder (typically "██") rather than printing the actual sensitive data [2][5].
Citations:
릴리스 빌드에서 인증 헤더가 Logcat에 노출될 위험이 있습니다.
HttpLoggingInterceptor.Level.BODY는 요청 및 응답 헤더 전체를 기록합니다. 코드에서 전송하는apikey나Authorization헤더가 로그에 그대로 노출되며, 이는 보안 위험입니다.해당 로깅 레벨을 디버그 빌드에서만 적용하고 릴리스 빌드에서는 logs 를 끄도록 수정해야 합니다.
🔒 제안 수정
📝 Committable suggestion
🤖 Prompt for AI Agents