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

Refactor/#916 refactor datalayer refactoring #917

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions android/2023-emmsale/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

# ApiResponse 클래스의 타입 매개변수를 유지하기 위해 추가. 안하면 CallAdapter에서 retrofit2.Call<ApiResponse>를 반환하는 CallAdapter 만들 수 없음.
-keepnames, allowobfuscation class com.emmsale.data.common.retrofit.callAdapter.ApiResponse
-keepnames, allowobfuscation class com.emmsale.data.network.callAdapter.ApiResponse

# 카카오 공유하기
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
-keep interface com.kakao.sdk.**.*Api
-keep class com.kakao.sdk.**.model.* { <fields>; }
-keep class * extends com.google.gson.TypeAdapter
-keep class * extends com.google.gson.TypeAdapter

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.ActivityResponse
import com.emmsale.data.model.Activity
import com.emmsale.data.model.ActivityType
import com.emmsale.data.network.apiModel.response.ActivityResponse
import com.emmsale.model.Activity
import com.emmsale.model.ActivityType

fun List<ActivityResponse>.toData(): List<Activity> = map { it.toData() }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.BlockedMemberResponse
import com.emmsale.data.model.BlockedMember
import com.emmsale.data.network.apiModel.response.BlockedMemberResponse
import com.emmsale.model.BlockedMember

fun List<BlockedMemberResponse>.toData(): List<BlockedMember> = map(BlockedMemberResponse::toData)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.CommentFamilyApiModel
import com.emmsale.data.apiModel.response.CommentResponse
import com.emmsale.data.model.Comment
import com.emmsale.data.model.Feed
import com.emmsale.data.model.Member
import com.emmsale.data.network.apiModel.response.CommentFamilyApiModel
import com.emmsale.data.network.apiModel.response.CommentResponse
import com.emmsale.model.Comment
import com.emmsale.model.Feed
import com.emmsale.model.Member

@JvmName("mapCommentFamilyApiModelsToData")
fun List<CommentFamilyApiModel>.toData(): List<Comment> = map(CommentFamilyApiModel::toData)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.emmsale.data.mapper

import com.emmsale.data.model.CompetitionStatus
import com.emmsale.model.CompetitionStatus

fun List<CompetitionStatus>.toApiModel(): List<String> = map { it.toApiModel() }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.emmsale.data.mapper

import com.emmsale.data.model.ConferenceStatus
import com.emmsale.model.ConferenceStatus

fun List<ConferenceStatus>.toApiModel(): List<String> = map { it.toApiModel() }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.emmsale.data.mapper

import com.emmsale.BuildConfig
import com.emmsale.data.apiModel.response.EventResponse
import com.emmsale.data.model.Event
import com.emmsale.data.model.OnOfflineMode
import com.emmsale.data.model.PaymentType
import com.emmsale.data.network.apiModel.response.EventResponse
import com.emmsale.model.Event
import com.emmsale.model.OnOfflineMode
import com.emmsale.model.PaymentType

fun List<EventResponse>.toData(): List<Event> = map { it.toData() }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.emmsale.data.mapper

import com.emmsale.data.common.database.entity.EventSearchHistoryEntity
import com.emmsale.data.model.EventSearchHistory
import com.emmsale.data.persistence.database.EventSearchHistoryEntity
import com.emmsale.model.EventSearchHistory

fun EventSearchHistory.toEntity(): EventSearchHistoryEntity = EventSearchHistoryEntity(
query = query,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.EventTagResponse
import com.emmsale.data.model.EventTag
import com.emmsale.data.network.apiModel.response.EventTagResponse
import com.emmsale.model.EventTag

fun EventTagResponse.toData(): EventTag = EventTag(
id = id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.emmsale.data.mapper

import com.emmsale.BuildConfig
import com.emmsale.data.apiModel.response.FeedResponse
import com.emmsale.data.model.Event
import com.emmsale.data.model.Feed
import com.emmsale.data.network.apiModel.response.FeedResponse
import com.emmsale.model.Event
import com.emmsale.model.Feed

fun List<FeedResponse>.toData(): List<Feed> = map { it.toData() }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.LoginResponse
import com.emmsale.data.model.Login
import com.emmsale.data.model.Token
import com.emmsale.data.network.apiModel.response.LoginResponse
import com.emmsale.model.Login
import com.emmsale.model.Token

fun LoginResponse.toData(): Login = Login(
token = Token(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.MemberResponse
import com.emmsale.data.model.Member
import com.emmsale.data.network.apiModel.response.MemberResponse
import com.emmsale.model.Member

fun MemberResponse.toData() = Member(
id = id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.MessageResponse
import com.emmsale.data.model.Message
import com.emmsale.data.network.apiModel.response.MessageResponse
import com.emmsale.model.Message

fun List<MessageResponse>.toData(): List<Message> = map { it.toData() }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.MessageRoomResponse
import com.emmsale.data.model.MessageRoom
import com.emmsale.data.network.apiModel.response.MessageRoomResponse
import com.emmsale.model.MessageRoom

fun List<MessageRoomResponse>.toData(): List<MessageRoom> = map { it.toData() }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.CommentTypeNotificationResponse
import com.emmsale.data.apiModel.response.EventTypeNotificationResponse
import com.emmsale.data.apiModel.response.NotificationResponse
import com.emmsale.data.apiModel.response.NotificationResponse.NotificationType
import com.emmsale.data.model.Comment
import com.emmsale.data.model.Event
import com.emmsale.data.model.Feed
import com.emmsale.data.model.Member
import com.emmsale.data.model.notification.ChildCommentNotification
import com.emmsale.data.model.notification.InterestEventNotification
import com.emmsale.data.model.notification.Notification
import com.emmsale.data.network.apiModel.response.CommentTypeNotificationResponse
import com.emmsale.data.network.apiModel.response.EventTypeNotificationResponse
import com.emmsale.data.network.apiModel.response.NotificationResponse
import com.emmsale.data.network.apiModel.response.NotificationResponse.NotificationType
import com.emmsale.model.Comment
import com.emmsale.model.Event
import com.emmsale.model.Feed
import com.emmsale.model.Member
import com.emmsale.model.notification.ChildCommentNotification
import com.emmsale.model.notification.InterestEventNotification
import com.emmsale.model.notification.Notification
import kotlinx.serialization.json.Json

@JvmName("NotificationResponse")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.emmsale.data.mapper

import com.emmsale.data.apiModel.response.RecruitmentResponse
import com.emmsale.data.model.Event
import com.emmsale.data.model.Recruitment
import com.emmsale.data.network.apiModel.response.RecruitmentResponse
import com.emmsale.model.Event
import com.emmsale.model.Recruitment

fun List<RecruitmentResponse>.toData(): List<Recruitment> = map {
it.toData()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package com.emmsale.data.common.retrofit
package com.emmsale.data.network

import android.content.Context
import android.content.Intent
import com.emmsale.data.repository.interfaces.TokenRepository
import com.emmsale.presentation.ui.login.LoginActivity
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import javax.inject.Inject

class AuthInterceptor(private val context: Context) : Interceptor {
private val tokenRepository = EntryPointAccessors
.fromApplication<AuthInterceptorEntryPoint>(context)
.getTokenRepository()
class AuthInterceptor @Inject constructor(
private val context: Context,
private val tokenRepository: TokenRepository,
) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val token = tokenRepository.getToken()
val tokenAddedRequest = chain.request().putAccessToken(token?.accessToken)
val token = tokenRepository.getToken()?.accessToken
val tokenAddedRequest = chain.request().putAccessToken(token)

val response = chain.proceed(tokenAddedRequest)
if (response.isAccessTokenInvalid()) {
Expand All @@ -28,7 +25,7 @@ class AuthInterceptor(private val context: Context) : Interceptor {
return response
}

private fun Response.isAccessTokenInvalid(): Boolean = (code == 401)
private fun Response.isAccessTokenInvalid(): Boolean = (code == UNAUTHORIZED_ERROR_CODE)

private fun Request.putAccessToken(token: String?): Request =
putHeader(ACCESS_TOKEN_HEADER, ACCESS_TOKEN_FORMAT.format(token))
Expand All @@ -38,20 +35,15 @@ class AuthInterceptor(private val context: Context) : Interceptor {
value: String,
): Request = newBuilder().addHeader(key, value).build()

private fun navigateToLogin() {
private fun navigateToLogin() { // bad practice but now approved
val loginStartIntent = Intent(context, LoginActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(loginStartIntent)
}

@EntryPoint
@InstallIn(SingletonComponent::class)
interface AuthInterceptorEntryPoint {
fun getTokenRepository(): TokenRepository
}

companion object {
private const val ACCESS_TOKEN_HEADER = "authorization"
private const val ACCESS_TOKEN_FORMAT = "Bearer %s"
private const val UNAUTHORIZED_ERROR_CODE = 401
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.request
package com.emmsale.data.network.apiModel.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.request
package com.emmsale.data.network.apiModel.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.request
package com.emmsale.data.network.apiModel.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.request
package com.emmsale.data.network.apiModel.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.request
package com.emmsale.data.network.apiModel.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.request
package com.emmsale.data.network.apiModel.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.request
package com.emmsale.data.network.apiModel.request

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.response
package com.emmsale.data.network.apiModel.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.data.apiModel.response
package com.emmsale.data.network.apiModel.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Loading
Loading