Skip to content

Commit

Permalink
[AN] feat: 네트워크 통신 세팅 및 토큰 매니저 구현 (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
junjange authored and takoyakimchi committed Oct 23, 2024
1 parent d96d129 commit 55e1e80
Show file tree
Hide file tree
Showing 63 changed files with 906 additions and 61 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.navigation.safeargs)
id("kotlin-kapt")
id("com.google.gms.google-services")
kotlin("plugin.serialization") version "1.9.22"
id("kotlin-parcelize")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ import android.app.Application
import com.kakao.sdk.common.KakaoSdk
import com.naver.maps.map.NaverMapSdk
import com.woowacourse.friendogly.BuildConfig
import com.woowacourse.friendogly.kakao.di.KakaoModule
import com.woowacourse.friendogly.application.di.AppModule

class FriendoglyApplication : Application() {
override fun onCreate() {
super.onCreate()
initNaverMapSdk()
KakaoSdk.init(this, BuildConfig.KAKAO_NATIVE_APP_KEY)
AppModule.setInstance(applicationContext)
}

private fun initNaverMapSdk() {
NaverMapSdk.getInstance(this).client =
NaverMapSdk.NaverCloudPlatformClient(BuildConfig.NAVER_CLIEND_ID)
}

companion object {
val kakaoModule: KakaoModule = KakaoModule()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.woowacourse.friendogly.application.di

import android.content.Context
import com.woowacourse.friendogly.BuildConfig
import com.woowacourse.friendogly.data.repository.ClubRepositoryImpl
import com.woowacourse.friendogly.data.repository.FootprintRepositoryImpl
import com.woowacourse.friendogly.data.repository.KakaoLoginRepositoryImpl
import com.woowacourse.friendogly.data.repository.LocalRepositoryImpl
import com.woowacourse.friendogly.data.source.ClubDataSource
import com.woowacourse.friendogly.data.source.FootprintDataSource
import com.woowacourse.friendogly.data.source.KakaoLoginDataSource
import com.woowacourse.friendogly.data.source.LocalDataSource
import com.woowacourse.friendogly.domain.repository.ClubRepository
import com.woowacourse.friendogly.domain.repository.FootprintRepository
import com.woowacourse.friendogly.domain.repository.KakaoLoginRepository
import com.woowacourse.friendogly.domain.repository.LocalRepository
import com.woowacourse.friendogly.domain.usecase.DeleteClubUseCase
import com.woowacourse.friendogly.domain.usecase.DeleteLocalDataUseCase
import com.woowacourse.friendogly.domain.usecase.GetClubMineUseCase
import com.woowacourse.friendogly.domain.usecase.GetFootprintsUseCase
import com.woowacourse.friendogly.domain.usecase.GetJwtTokenUseCase
import com.woowacourse.friendogly.domain.usecase.KakaoLoginUseCase
import com.woowacourse.friendogly.domain.usecase.PostClubParticipationUseCase
import com.woowacourse.friendogly.domain.usecase.PostClubUseCase
import com.woowacourse.friendogly.domain.usecase.PostFootprintUseCase
import com.woowacourse.friendogly.domain.usecase.SaveJwtTokenUseCase
import com.woowacourse.friendogly.kakao.source.KakaoLoginDataSourceImpl
import com.woowacourse.friendogly.local.di.LocalModule
import com.woowacourse.friendogly.local.source.LocalDataSourceImpl
import com.woowacourse.friendogly.remote.api.BaseUrl
import com.woowacourse.friendogly.remote.di.RemoteModule
import com.woowacourse.friendogly.remote.source.ClubDataSourceImpl
import com.woowacourse.friendogly.remote.source.FootprintDataSourceImpl

class AppModule(context: Context) {
private val baseUrl = BaseUrl(BuildConfig.base_url)

private val localModule = LocalModule(context)

private val footprintService =
RemoteModule.createFootprintService(
baseUrl = baseUrl,
localModule = localModule,
)

private val clubService =
RemoteModule.createClubService(
baseUrl = baseUrl,
localModule = localModule,
)

// data source
private val clubDataSource: ClubDataSource = ClubDataSourceImpl(service = clubService)
private val footprintDataSource: FootprintDataSource =
FootprintDataSourceImpl(service = footprintService)
private val localDataSource: LocalDataSource = LocalDataSourceImpl(localModule = localModule)
private val kakaoLoginDataSource: KakaoLoginDataSource = KakaoLoginDataSourceImpl()

// repository
private val clubRepository: ClubRepository = ClubRepositoryImpl(source = clubDataSource)
private val footprintRepository: FootprintRepository =
FootprintRepositoryImpl(source = footprintDataSource)
private val localRepository: LocalRepository = LocalRepositoryImpl(source = localDataSource)
private val kakaoLoginRepository: KakaoLoginRepository =
KakaoLoginRepositoryImpl(dataSource = kakaoLoginDataSource)

// use case
val kakaoLoginUseCase: KakaoLoginUseCase = KakaoLoginUseCase(repository = kakaoLoginRepository)
val deleteClubUseCase: DeleteClubUseCase = DeleteClubUseCase(repository = clubRepository)
val getClubMineUseCase: GetClubMineUseCase = GetClubMineUseCase(repository = clubRepository)
val getFootprintUseCase: GetFootprintsUseCase =
GetFootprintsUseCase(repository = footprintRepository)
val postClubParticipationUseCase: PostClubParticipationUseCase =
PostClubParticipationUseCase(repository = clubRepository)
val postClubUseCase: PostClubUseCase = PostClubUseCase(repository = clubRepository)
val postFootprintUseCase: PostFootprintUseCase =
PostFootprintUseCase(repository = footprintRepository)
val getJwtTokenUseCase: GetJwtTokenUseCase = GetJwtTokenUseCase(repository = localRepository)
val saveJwtTokenUseCase: SaveJwtTokenUseCase = SaveJwtTokenUseCase(repository = localRepository)
val deleteLocalDataUseCase: DeleteLocalDataUseCase =
DeleteLocalDataUseCase(repository = localRepository)

companion object {
private var instance: AppModule? = null

fun setInstance(context: Context) {
instance = AppModule(context)
}

fun getInstance(): AppModule = requireNotNull(instance)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.woowacourse.friendogly.data.mapper

import com.woowacourse.friendogly.data.model.FootprintDto
import com.woowacourse.friendogly.domain.model.Footprint

fun FootprintDto.toDomain(): Footprint {
return Footprint(
footprintId = this.footprintId,
latitude = this.latitude,
longitude = this.longitude,
createdAt = this.createdAt,
isMine = this.isMine,
)
}

fun List<FootprintDto>.toDomain(): List<Footprint> {
return map { dto ->
dto.toDomain()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.woowacourse.friendogly.data.mapper

import com.woowacourse.friendogly.data.model.JwtTokenDto
import com.woowacourse.friendogly.domain.model.JwtToken

fun JwtTokenDto.toDomain(): JwtToken {
return JwtToken(
accessToken = this.accessToken,
refreshToken = this.refreshToken,
)
}

fun JwtToken.toData(): JwtTokenDto {
return JwtTokenDto(
accessToken = this.accessToken,
refreshToken = this.refreshToken,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.woowacourse.friendogly.data.mapper

import com.woowacourse.friendogly.data.model.LocationDto
import com.woowacourse.friendogly.domain.model.Location

fun LocationDto.toDomain(): Location {
return Location(
latitude = this.latitude,
longitude = this.longitude,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.woowacourse.friendogly.data.model

data class FootprintDto(
val footprintId: Int,
val latitude: Double,
val longitude: Double,
val createdAt: String,
val isMine: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.woowacourse.friendogly.data.model

data class JwtTokenDto(
val accessToken: String?,
val refreshToken: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.woowacourse.friendogly.data.model

data class LocationDto(
val latitude: Double,
val longitude: Double,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.woowacourse.friendogly.data.repository

import com.woowacourse.friendogly.data.mapper.toDomain
import com.woowacourse.friendogly.data.source.ClubDataSource
import com.woowacourse.friendogly.domain.model.Location
import com.woowacourse.friendogly.domain.repository.ClubRepository

class ClubRepositoryImpl(
private val source: ClubDataSource,
) : ClubRepository {
override suspend fun postClub(): Result<Location> = source.postClub().mapCatching { result -> result.toDomain() }

override suspend fun deleteClub(id: Long): Result<Location> = source.deleteClub(id = id).mapCatching { result -> result.toDomain() }

override suspend fun postClubParticipation(): Result<Unit> = source.postClubParticipation()

override suspend fun getClubMine(): Result<Unit> = source.getClubMine()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.woowacourse.friendogly.data.repository

import com.woowacourse.friendogly.data.mapper.toDomain
import com.woowacourse.friendogly.data.source.FootprintDataSource
import com.woowacourse.friendogly.domain.model.Footprint
import com.woowacourse.friendogly.domain.repository.FootprintRepository

class FootprintRepositoryImpl(
private val source: FootprintDataSource,
) : FootprintRepository {
override suspend fun postFootprint(
latitude: Double,
longitude: Double,
): Result<Unit> = source.postFootprint(latitude = latitude, longitude = longitude)

override suspend fun getFootprints(
latitude: Double,
longitude: Double,
): Result<List<Footprint>> =
source.getFootprints(latitude = latitude, longitude = longitude).mapCatching { result ->
result.toDomain()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.woowacourse.friendogly.data.repository

import android.content.Context
import com.woowacourse.friendogly.data.datasource.KakaoLoginDataSource
import com.woowacourse.friendogly.data.mapper.toDomain
import com.woowacourse.friendogly.data.source.KakaoLoginDataSource
import com.woowacourse.friendogly.domain.model.KakaoAccessToken
import com.woowacourse.friendogly.domain.repository.KakaoLoginRepository

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.woowacourse.friendogly.data.repository

import com.woowacourse.friendogly.data.mapper.toData
import com.woowacourse.friendogly.data.mapper.toDomain
import com.woowacourse.friendogly.data.source.LocalDataSource
import com.woowacourse.friendogly.domain.model.JwtToken
import com.woowacourse.friendogly.domain.repository.LocalRepository

class LocalRepositoryImpl(
private val source: LocalDataSource,
) : LocalRepository {
override suspend fun getJwtToken(): Result<JwtToken> = source.getJwtToken().mapCatching { result -> result.toDomain() }

override suspend fun saveJwtToken(jwtToken: JwtToken): Result<Unit> = source.saveJwtToken(jwtTokenDto = jwtToken.toData())

override suspend fun deleteLocalData(): Result<Unit> = source.deleteLocalData()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.woowacourse.friendogly.data.source

import com.woowacourse.friendogly.data.model.LocationDto

interface ClubDataSource {
suspend fun postClub(): Result<LocationDto>

suspend fun deleteClub(id: Long): Result<LocationDto>

suspend fun postClubParticipation(): Result<Unit>

suspend fun getClubMine(): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.woowacourse.friendogly.data.source

import com.woowacourse.friendogly.data.model.FootprintDto

interface FootprintDataSource {
suspend fun postFootprint(
latitude: Double,
longitude: Double,
): Result<Unit>

suspend fun getFootprints(
latitude: Double,
longitude: Double,
): Result<List<FootprintDto>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.woowacourse.friendogly.data.source

import android.content.Context
import com.woowacourse.friendogly.data.model.KakaoAccessTokenDto

interface KakaoLoginDataSource {
suspend fun login(context: Context): Result<KakaoAccessTokenDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.woowacourse.friendogly.data.source

import com.woowacourse.friendogly.data.model.JwtTokenDto

interface LocalDataSource {
suspend fun getJwtToken(): Result<JwtTokenDto>

suspend fun saveJwtToken(jwtTokenDto: JwtTokenDto): Result<Unit>

suspend fun deleteLocalData(): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.woowacourse.friendogly.domain.model

data class Footprint(
val footprintId: Int,
val latitude: Double,
val longitude: Double,
val createdAt: String,
val isMine: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.woowacourse.friendogly.domain.model

data class JwtToken(
val accessToken: String?,
val refreshToken: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.woowacourse.friendogly.domain.model

data class Location(
val latitude: Double,
val longitude: Double,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.woowacourse.friendogly.domain.repository

import com.woowacourse.friendogly.domain.model.Location

interface ClubRepository {
suspend fun postClub(): Result<Location>

suspend fun deleteClub(id: Long): Result<Location>

suspend fun postClubParticipation(): Result<Unit>

suspend fun getClubMine(): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.woowacourse.friendogly.domain.repository

import com.woowacourse.friendogly.domain.model.Footprint

interface FootprintRepository {
suspend fun postFootprint(
latitude: Double,
longitude: Double,
): Result<Unit>

suspend fun getFootprints(
latitude: Double,
longitude: Double,
): Result<List<Footprint>>
}
Loading

0 comments on commit 55e1e80

Please sign in to comment.