-
Notifications
You must be signed in to change notification settings - Fork 21
Creating launchpad service implementation #4
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
13 changes: 13 additions & 0 deletions
13
...print-gustavo-santorio-2/app/src/main/java/com/devpass/spaceapp/data/api/NetworkModule.kt
This file contains hidden or 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.devpass.spaceapp.data.api | ||
|
|
||
| import retrofit2.Retrofit | ||
| import retrofit2.converter.gson.GsonConverterFactory | ||
|
|
||
| object NetworkModule { | ||
| val retrofitInstance by lazy { | ||
| Retrofit.Builder() | ||
| .baseUrl("https://api.spacexdata.com") | ||
| .addConverterFactory(GsonConverterFactory.create()) | ||
| .build() | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...nt-gustavo-santorio-2/app/src/main/java/com/devpass/spaceapp/data/api/SpaceXAPIService.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| package com.devpass.spaceapp.data.api | ||
|
|
||
| import com.devpass.spaceapp.launchpad.domain.dto.LaunchpadDTO | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.Query | ||
|
|
||
| interface SpaceXAPIService { | ||
|
|
||
| @GET("/v4/launchpads/{id}") | ||
| suspend fun fetchLaunchpadDetails(@Query("id") id: String): LaunchpadDTO | ||
| } |
38 changes: 38 additions & 0 deletions
38
...io-2/app/src/main/java/com/devpass/spaceapp/launchpad/data/FetchLaunchesRepositoryImpl.kt
This file contains hidden or 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,38 @@ | ||
| package com.devpass.spaceapp.launchpad.data | ||
|
|
||
| import com.devpass.spaceapp.data.api.NetworkModule | ||
| import com.devpass.spaceapp.data.api.SpaceXAPIService | ||
| import com.devpass.spaceapp.launchpad.domain.repository.FetchLaunchesRepository | ||
| import com.devpass.spaceapp.launchpad.domain.model.LaunchpadVO | ||
|
|
||
| class FetchLaunchesRepositoryImpl( | ||
| private val service: SpaceXAPIService = NetworkModule.retrofitInstance.create(SpaceXAPIService::class.java) | ||
| ) : FetchLaunchesRepository { | ||
| override suspend fun fetchLaunchpadDetails(id: String): Result<LaunchpadVO> { | ||
| return runCatching { | ||
| val response = service.fetchLaunchpadDetails(id = id) | ||
| with(response) { | ||
| LaunchpadVO( | ||
| name = name, | ||
| fullName = full_name, | ||
| region = region, | ||
| launchAttempts = launch_attempts.toString(), | ||
| launchSuccesses = launch_successes.toString() | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| return runCatching { | ||
| val response = service.fetchLaunchpadDetails(id = id) | ||
| with(response) { | ||
| LaunchpadVO( | ||
| name = name, | ||
| fullName = full_name, | ||
| region = region, | ||
| launchAttempts = launch_attempts.toString(), | ||
| launchSuccesses = launch_successes.toString() | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
...vo-santorio-2/app/src/main/java/com/devpass/spaceapp/launchpad/domain/dto/LaunchpadDTO.kt
This file contains hidden or 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.devpass.spaceapp.launchpad.domain.dto | ||
|
|
||
| data class LaunchpadDTO( | ||
| val full_name: String, | ||
| val id: String, | ||
| val latitude: Double, | ||
| val launch_attempts: Int, | ||
| val launch_successes: Int, | ||
| val launches: List<String>, | ||
| val locality: String, | ||
| val longitude: Double, | ||
| val name: String, | ||
| val region: String, | ||
| val rockets: List<String>, | ||
| val status: String, | ||
| val timezone: String | ||
| ) |
9 changes: 9 additions & 0 deletions
9
...o-santorio-2/app/src/main/java/com/devpass/spaceapp/launchpad/domain/model/LaunchpadVO.kt
This file contains hidden or 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.devpass.spaceapp.launchpad.domain.model | ||
|
|
||
| data class LaunchpadVO( | ||
| val name: String, | ||
| val fullName: String, | ||
| val region: String, | ||
| val launchAttempts: String, | ||
| val launchSuccesses: String | ||
| ) |
7 changes: 7 additions & 0 deletions
7
...src/main/java/com/devpass/spaceapp/launchpad/domain/repository/FetchLaunchesRepository.kt
This file contains hidden or 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,7 @@ | ||
| package com.devpass.spaceapp.launchpad.domain.repository | ||
|
|
||
| import com.devpass.spaceapp.launchpad.domain.model.LaunchpadVO | ||
|
|
||
| interface FetchLaunchesRepository { | ||
| suspend fun fetchLaunchpadDetails(id: String): Result<LaunchpadVO> | ||
| } |
2 changes: 1 addition & 1 deletion
2
.../presentation/LaunchpadDetailsActivity.kt → .../presentation/LaunchpadDetailsActivity.kt
This file contains hidden or 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
5 changes: 0 additions & 5 deletions
5
...o-santorio-2/app/src/main/java/com/devpass/spaceapp/repository/FetchLaunchesRepository.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...ntorio-2/app/src/main/java/com/devpass/spaceapp/repository/FetchLaunchesRepositoryImpl.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.