Path under core/data/.../<domain>/ |
Example |
model/ |
LoginResult |
exception/ |
AuthException |
remote/service/ |
AuthService |
remote/dto/request|response/ |
LoginRequest, TokenResponse |
local/ |
TokenLocalDataSource, WorkoutPhotoLocalDataSource, WorkoutEntityMapper |
repository/ |
AuthRepository, AuthRepositoryImpl |
Path under core/database/.../ |
Example |
| (root) |
RouteeDatabase (one Room DB for the app, internal) |
dao/ |
WorkoutDao, WorkoutPhotoDao |
entity/ |
WorkoutEntity, TrackPointEntity, WorkoutPhotoEntity |
Hilt modules live in core/data/.../di/ and core/database/.../di/.
| Item |
Rule |
| Entity โ model |
core/data/.../<domain>/local/ |
| Schema |
Commit core/database/schemas/. New version โ @AutoMigration, no destructive migration |
| Write |
Insert only where a row is created, update with @Update (not @Upsert or REPLACE) |
internal interface AuthService {
@POST("api/v1/auth/login")
suspend fun login(@Body request: LoginRequest): BaseResponse<TokenResponse>
}
@Serializable
internal data class TokenResponse( // DTO๋ internal, core:data ๋ฐ์ผ๋ก ์ ๋๊ฐ
@SerialName("accessToken") val accessToken: String,
@SerialName("refreshToken") val refreshToken: String,
)
// ํจ์ ์ด๋ฆ
interface RecapRepository {
suspend fun getRecap(id: Long): Result<Recap> // get: 1ํ ์กฐํ
fun observeRecaps(): Flow<List<Recap>> // observe: Flow๋ก ๊ณ์ ๊ตฌ๋
suspend fun saveRecap(recap: Recap): Result<Unit> // save, update: ์ ์ฅ, ์์
suspend fun deleteRecap(id: Long): Result<Unit> // delete: ํ๋, clear: ์ ๋ถ
suspend fun shareRecap(id: Long): Result<Unit> // ๊ทธ ์ธ ๋์์ ๋๋ฉ์ธ ๋์ฌ (login, register)
} // post, put, patch๋ Service์๋ง
// ๊ตฌํ (core/data/.../auth)
internal class AuthRepositoryImpl @Inject constructor( // ๊ตฌํ์ฒด๋ internal
private val authService: AuthService,
private val apiResponseHandler: ApiResponseHandler,
) : AuthRepository {
override suspend fun login(idToken: String, provider: SocialProvider): Result<LoginResult> =
apiResponseHandler.safeApiCall { authService.login(LoginRequest(idToken, provider.name)) } // runCatching ๋์
.mapApiException(::mapAuthException)
}
| Qualifier |
Access token |
TimeZone header |
For |
@Auth |
Yes |
Yes |
Most APIs (default) |
@NoAuth |
No |
Yes |
Login, sign-up, token reissue |
@Module
@InstallIn(SingletonComponent::class)
internal abstract class RecapModule {
@Binds @Singleton
abstract fun bindRecapRepository(impl: RecapRepositoryImpl): RecapRepository
companion object {
@Provides @Singleton
fun provideRecapService(@Auth retrofit: Retrofit): RecapService = retrofit.create()
}
}