-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the ExtensionRepoService to use DTOs (#573)
* Refactor the ExtensionRepoService to use DTOs Slightly refactored the `ExtensionRepoService` so it uses a DTO with `parseAs` to avoid parsing the JSON response by hand. The default Json instance Injekt provides here has `ignoreUnknownKeys` enabled, so the `ExtensionRepoMetaDto` only specifies the meta key of the response content. The extension function `toExtensionRepo` allows for mapping the new DTO to the `domain` `ExtensionRepo` data class. * Implement feedback - Removed SerialName of the ExtensionRepoMetaDto property and renamed it `meta`, same as the incoming attribute. - Added a more general catch clause that also logs the occurring Exception Detekt likes to complain about TooGenericExceptionCaught, hence the Suppress annotation on the function.
- Loading branch information
1 parent
9672ea8
commit 8c437ce
Showing
2 changed files
with
35 additions
and
24 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoDto.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,27 @@ | ||
package mihon.domain.extensionrepo.service | ||
|
||
import kotlinx.serialization.Serializable | ||
import mihon.domain.extensionrepo.model.ExtensionRepo | ||
|
||
@Serializable | ||
data class ExtensionRepoMetaDto( | ||
val meta: ExtensionRepoDto, | ||
) | ||
|
||
@Serializable | ||
data class ExtensionRepoDto( | ||
val name: String, | ||
val shortName: String?, | ||
val website: String, | ||
val signingKeyFingerprint: String, | ||
) | ||
|
||
fun ExtensionRepoMetaDto.toExtensionRepo(baseUrl: String): ExtensionRepo { | ||
return ExtensionRepo( | ||
baseUrl = baseUrl, | ||
name = meta.name, | ||
shortName = meta.shortName, | ||
website = meta.website, | ||
signingKeyFingerprint = meta.signingKeyFingerprint, | ||
) | ||
} |
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