-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AN] feat: 네트워크 통신 세팅 및 토큰 매니저 구현 (#143)
- Loading branch information
1 parent
d96d129
commit 55e1e80
Showing
63 changed files
with
906 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
android/app/src/main/java/com/woowacourse/friendogly/application/di/AppModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
android/app/src/main/java/com/woowacourse/friendogly/data/datasource/KakaoLoginDataSource.kt
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
android/app/src/main/java/com/woowacourse/friendogly/data/mapper/FootprintMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
android/app/src/main/java/com/woowacourse/friendogly/data/mapper/JwtTokenMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
android/app/src/main/java/com/woowacourse/friendogly/data/mapper/LocationMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/woowacourse/friendogly/data/model/FootprintDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/com/woowacourse/friendogly/data/model/JwtTokenDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/com/woowacourse/friendogly/data/model/LocationDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
18 changes: 18 additions & 0 deletions
18
android/app/src/main/java/com/woowacourse/friendogly/data/repository/ClubRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
23 changes: 23 additions & 0 deletions
23
...d/app/src/main/java/com/woowacourse/friendogly/data/repository/FootprintRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../app/src/main/java/com/woowacourse/friendogly/data/repository/KakaoLoginRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
android/app/src/main/java/com/woowacourse/friendogly/data/repository/LocalRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
13 changes: 13 additions & 0 deletions
13
android/app/src/main/java/com/woowacourse/friendogly/data/source/ClubDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
15 changes: 15 additions & 0 deletions
15
android/app/src/main/java/com/woowacourse/friendogly/data/source/FootprintDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>> | ||
} |
8 changes: 8 additions & 0 deletions
8
android/app/src/main/java/com/woowacourse/friendogly/data/source/KakaoLoginDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
11 changes: 11 additions & 0 deletions
11
android/app/src/main/java/com/woowacourse/friendogly/data/source/LocalDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/woowacourse/friendogly/domain/model/Footprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/com/woowacourse/friendogly/domain/model/JwtToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/com/woowacourse/friendogly/domain/model/Location.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
13 changes: 13 additions & 0 deletions
13
android/app/src/main/java/com/woowacourse/friendogly/domain/repository/ClubRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
15 changes: 15 additions & 0 deletions
15
...oid/app/src/main/java/com/woowacourse/friendogly/domain/repository/FootprintRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>> | ||
} |
Oops, something went wrong.