From be20a22fe93114b3e02625ae59d8cf0ba76876f9 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Tue, 14 Jun 2022 21:14:20 +0800 Subject: [PATCH] fix apis --- .../kotlin/top/jie65535/jcf/CurseforgeApi.kt | 37 ++++++++-------- .../kotlin/top/jie65535/jcf/model/Category.kt | 43 +++++++++++++++++++ .../top/jie65535/jcf/model/Pagination.kt | 15 +++++++ .../jie65535/jcf/model/SortableGameVersion.kt | 4 ++ .../kotlin/top/jie65535/jcf/model/mod/Mod.kt | 26 ++++++++++- .../jcf/model/response/SearchModsResponse.kt | 2 +- 6 files changed, 107 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt b/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt index 008a446..44db1cd 100644 --- a/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt +++ b/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt @@ -16,6 +16,7 @@ import top.jie65535.jcf.model.response.* /** * [Api docs](https://docs.curseforge.com/) + * @author jie65535 */ @OptIn(ExperimentalSerializationApi::class) class CurseforgeApi(apiKey: String) { @@ -57,7 +58,7 @@ class CurseforgeApi(apiKey: String) { * Specify a game id for a list of all game categories, * or a class id for a list of categories under that class. */ - suspend fun getCategories(gameId: Int, classId: Int?): Array { + suspend fun getCategories(gameId: Int, classId: Int? = null): Array { return json.decodeFromString( http.get("/v1/categories") { parameter("gameId", gameId) @@ -87,17 +88,17 @@ class CurseforgeApi(apiKey: String) { */ suspend fun searchMods( gameId: Int, - classId: Int?, - categoryId: Int?, - gameVersion: String?, - searchFilter: String?, - sortField: ModsSearchSortField?, - sortOrder: SortOrder?, - modLoaderType: ModLoaderType?, - gameVersionTypeId: Int?, - slug: String?, - index: Int?, - pageSize: Int? + classId: Int? = null, + categoryId: Int? = null, + gameVersion: String? = null, + searchFilter: String? = null, + sortField: ModsSearchSortField? = null, + sortOrder: SortOrder? = null, + modLoaderType: ModLoaderType? = null, + gameVersionTypeId: Int? = null, + slug: String? = null, + index: Int? = null, + pageSize: Int? = null ): SearchModsResponse { return json.decodeFromString( http.get("/v1/mods/search") { @@ -147,7 +148,7 @@ class CurseforgeApi(apiKey: String) { suspend fun getFeaturedMods( gameId: Int, excludedModIds: IntArray, - gameVersionTypeId: Int? + gameVersionTypeId: Int? = null ): FeaturedModsResponse { return json.decodeFromString( http.get("/v1/mods/featured") { @@ -183,11 +184,11 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getModFiles( modId: Int, - gameVersion: String?, - modLoaderType: ModLoaderType?, - gameVersionTypeId: Int?, - index: Int?, - pageSize: Int? + gameVersion: String? = null, + modLoaderType: ModLoaderType? = null, + gameVersionTypeId: Int? = null, + index: Int? = null, + pageSize: Int? = null ): GetModFilesResponse { return json.decodeFromString( http.get("/v1/mods/$modId/files") { diff --git a/src/main/kotlin/top/jie65535/jcf/model/Category.kt b/src/main/kotlin/top/jie65535/jcf/model/Category.kt index 1d40c52..66935ce 100644 --- a/src/main/kotlin/top/jie65535/jcf/model/Category.kt +++ b/src/main/kotlin/top/jie65535/jcf/model/Category.kt @@ -6,16 +6,59 @@ import java.time.OffsetDateTime @Serializable class Category( + /** + * The category id + */ val id: Int, + + /** + * The game id related to the category + */ val gameId: Int, + + /** + * Category name + */ val name: String, + + /** + * The category slug as it appear in the URL + */ val slug: String, + + /** + * The category URL + */ val url: String, + + /** + * URL for the category icon + */ val iconUrl: String, + + /** + * Last modified date of the category + */ @Serializable(OffsetDateTimeSerializer::class) val dateModified: OffsetDateTime, + + /** + * A top level category for other categories + */ val isClass: Boolean?, + + /** + * The class id of the category, meaning - the class of which this category is under + */ val classId: Int?, + + /** + * The parent category for this category + */ val parentCategoryId: Int?, + + /** + * The display index for this category + */ val displayIndex: Int? ) diff --git a/src/main/kotlin/top/jie65535/jcf/model/Pagination.kt b/src/main/kotlin/top/jie65535/jcf/model/Pagination.kt index c21ecd2..09375e3 100644 --- a/src/main/kotlin/top/jie65535/jcf/model/Pagination.kt +++ b/src/main/kotlin/top/jie65535/jcf/model/Pagination.kt @@ -2,8 +2,23 @@ package top.jie65535.jcf.model @kotlinx.serialization.Serializable class Pagination( + /** + * A zero based index of the first item that is included in the response + */ val index: Int, + + /** + * The requested number of items to be included in the response + */ val pageSize: Int, + + /** + * The actual number of items that were included in the response + */ val resultCount: Int, + + /** + * The total number of items available by the request + */ val totalCount: Long, ) \ No newline at end of file diff --git a/src/main/kotlin/top/jie65535/jcf/model/SortableGameVersion.kt b/src/main/kotlin/top/jie65535/jcf/model/SortableGameVersion.kt index 0e63a0b..b3acd22 100644 --- a/src/main/kotlin/top/jie65535/jcf/model/SortableGameVersion.kt +++ b/src/main/kotlin/top/jie65535/jcf/model/SortableGameVersion.kt @@ -10,19 +10,23 @@ class SortableGameVersion( * Original version name (e.g. 1.5b) */ val gameVersionName: String, + /** * Used for sorting (e.g. 0000000001.0000000005) */ val gameVersionPadded: String, + /** * game version clean name (e.g. 1.5) */ val gameVersion: String, + /** * Game version release date */ @Serializable(OffsetDateTimeSerializer::class) val gameVersionReleaseDate: OffsetDateTime, + /** * Game version type id */ diff --git a/src/main/kotlin/top/jie65535/jcf/model/mod/Mod.kt b/src/main/kotlin/top/jie65535/jcf/model/mod/Mod.kt index 48e7db4..91d9110 100644 --- a/src/main/kotlin/top/jie65535/jcf/model/mod/Mod.kt +++ b/src/main/kotlin/top/jie65535/jcf/model/mod/Mod.kt @@ -7,108 +7,132 @@ import top.jie65535.jcf.model.file.FileIndex import top.jie65535.jcf.util.OffsetDateTimeSerializer import java.time.OffsetDateTime -@kotlinx.serialization.Serializable +@Serializable class Mod( /** * The mod id */ val id: Int, + /** * The game id this mod is for */ val gameId: Int, + /** * The name of the mod */ val name: String, + /** * The mod slug that would appear in the URL */ val slug: String, + /** * Relevant links for the mod such as Issue tracker and Wiki */ val links: ModLinks, + /** * Mod summary */ val summary: String, + /** * Current mod status */ val status: ModStatus, + /** * Number of downloads for the mod */ val downloadCount: Long, + /** * Whether the mod is included in the featured mods list */ val isFeatured: Boolean, + /** * The main category of the mod as it was chosen by the mod author */ val primaryCategoryId: Int, + /** * List of categories that this mod is related to */ val categories: Array, + /** * The class id this mod belongs to */ val classId: Int?, + /** * List of the mod's authors */ val authors: Array, + /** * The mod's logo asset */ val logo: ModAsset, + /** * List of screenshots assets */ val screenshots: Array, + /** * The id of the main file of the mod */ val mainFileId: Int, + /** * List of latest files of the mod */ val latestFiles: Array, + /** * List of file related details for the latest files of the mod */ val latestFilesIndexes: Array, + /** * The creation date of the mod */ @Serializable(OffsetDateTimeSerializer::class) val dateCreated: OffsetDateTime, + /** * The last time the mod was modified */ @Serializable(OffsetDateTimeSerializer::class) val dateModified: OffsetDateTime, + /** * The release date of the mod */ @Serializable(OffsetDateTimeSerializer::class) val dateReleased: OffsetDateTime, + /** * Is mod allowed to be distributed */ val allowModDistribution: Boolean?, + /** * The mod popularity rank for the game */ val gamePopularityRank: Int, + /** * Is the mod available for search. This can be false when a mod is experimental, * in a deleted state or has only alpha files */ val isAvailable: Boolean, + /** * The mod's thumbs up count */ diff --git a/src/main/kotlin/top/jie65535/jcf/model/response/SearchModsResponse.kt b/src/main/kotlin/top/jie65535/jcf/model/response/SearchModsResponse.kt index a12a702..a0fd25c 100644 --- a/src/main/kotlin/top/jie65535/jcf/model/response/SearchModsResponse.kt +++ b/src/main/kotlin/top/jie65535/jcf/model/response/SearchModsResponse.kt @@ -5,6 +5,6 @@ import top.jie65535.jcf.model.mod.Mod @kotlinx.serialization.Serializable class SearchModsResponse( - val data: Mod, + val data: Array, val pagination: Pagination, ) \ No newline at end of file