Skip to content

Commit 099e48c

Browse files
committed
Added Character Search List
1 parent b4cee29 commit 099e48c

File tree

8 files changed

+189
-3
lines changed

8 files changed

+189
-3
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package me.proxer.library.api.list
2+
3+
import me.proxer.library.ProxerCall
4+
import me.proxer.library.api.PagingLimitEndpoint
5+
import me.proxer.library.entity.list.CharacterListEntry
6+
import me.proxer.library.enums.DescriptionType
7+
8+
/**
9+
* Search for all available characters. Features various filter and uses paging.
10+
*
11+
* @author TrueMB
12+
*/
13+
class CharacterSearchEndpoint internal constructor(
14+
private val internalApi: InternalApi
15+
) : PagingLimitEndpoint<List<CharacterListEntry>> {
16+
17+
private var page: Int? = null
18+
private var limit: Int? = null
19+
20+
private var start: String? = null
21+
private var contains: String? = null
22+
private var search: String? = null
23+
private var subject: DescriptionType? = null
24+
25+
override fun page(page: Int?) = this.apply { this.page = page }
26+
override fun limit(limit: Int?) = this.apply { this.limit = limit }
27+
28+
/**
29+
* Sets the start String to search for.
30+
*/
31+
fun start(start: String?) = this.apply { this.start = start }
32+
33+
/**
34+
* Sets the contains String to search for.
35+
*/
36+
fun contains(contains: String?) = this.apply { this.contains = contains }
37+
38+
/**
39+
* Sets the search String to search for in the descriptions.
40+
*/
41+
fun search(search: String?) = this.apply { this.search = search }
42+
43+
/**
44+
* Sets the subject that should be looked in.
45+
*/
46+
fun subject(subject: DescriptionType?) = this.apply { this.subject = subject }
47+
48+
override fun build(): ProxerCall<List<CharacterListEntry>> {
49+
return internalApi.characterSearch(start, contains, search, subject, page, limit)
50+
}
51+
}

library/src/main/kotlin/me/proxer/library/api/list/InternalApi.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.proxer.library.api.list
22

33
import me.proxer.library.ProxerCall
4+
import me.proxer.library.entity.list.CharacterListEntry
45
import me.proxer.library.entity.list.IndustryCore
56
import me.proxer.library.entity.list.IndustryProject
67
import me.proxer.library.entity.list.MediaListEntry
@@ -9,6 +10,7 @@ import me.proxer.library.entity.list.TranslatorGroupCore
910
import me.proxer.library.entity.list.TranslatorGroupProject
1011
import me.proxer.library.enums.Category
1112
import me.proxer.library.enums.Country
13+
import me.proxer.library.enums.DescriptionType
1214
import me.proxer.library.enums.IndustryType
1315
import me.proxer.library.enums.Language
1416
import me.proxer.library.enums.LengthBound
@@ -63,6 +65,16 @@ internal interface InternalApi {
6365
@Query("limit") limit: Int?
6466
): ProxerCall<List<MediaListEntry>>
6567

68+
@GET("list/characters")
69+
fun characterSearch(
70+
@Query("start") start: String?,
71+
@Query("contains") contains: String?,
72+
@Query("search") search: String?,
73+
@Query("subject") subject: DescriptionType?,
74+
@Query("page") page: Int?,
75+
@Query("limit") limit: Int?
76+
): ProxerCall<List<CharacterListEntry>>
77+
6678
@GET("list/translatorgroups")
6779
fun translatorGroupList(
6880
@Query("start") searchStart: String?,

library/src/main/kotlin/me/proxer/library/api/list/ListApi.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ class ListApi internal constructor(retrofit: Retrofit) {
1111

1212
private val internalApi = retrofit.create(InternalApi::class.java)
1313

14+
/**
15+
* Returns the respective endpoint.
16+
*/
17+
fun characterSearch(): CharacterSearchEndpoint {
18+
return CharacterSearchEndpoint(internalApi)
19+
}
20+
1421
/**
1522
* Returns the respective endpoint.
1623
*/

library/src/main/kotlin/me/proxer/library/entity/info/Character.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.util.Date
1717
* @property birthday The birthday.
1818
* @property height The height.
1919
* @property weight The weight.
20-
* @property description The description.
20+
* @property descriptions The description.
2121
* @property persons The persons in contact with the character
2222
*
2323
* @author Ruben Gees
@@ -33,6 +33,6 @@ data class Character(
3333
@Json(name = "birthday") val birthday: Date,
3434
@Json(name = "height") val height: String,
3535
@Json(name = "weight") val weight: String,
36-
@Json(name = "description") val description: Set<Description>,
36+
@Json(name = "description") val descriptions: Set<Description>,
3737
@Json(name = "persons") val persons: Set<PersonCore>
3838
) : ProxerIdItem
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package me.proxer.library.entity.list
2+
3+
import com.squareup.moshi.Json
4+
import com.squareup.moshi.JsonClass
5+
import me.proxer.library.entity.ProxerIdItem
6+
7+
/**
8+
* Entity holding all relevant info about a single entry of the character list.
9+
*
10+
* @property name The name.
11+
* @property description The description.
12+
*
13+
* @author TrueMB
14+
*/
15+
@JsonClass(generateAdapter = true)
16+
data class CharacterListEntry(
17+
@Json(name = "id") override val id: String,
18+
@Json(name = "name") val name: String,
19+
@Json(name = "text") val description: String
20+
) : ProxerIdItem

library/src/test/kotlin/me/proxer/library/api/info/CharacterCoreEndpointTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CharacterCoreEndpointTest : ProxerTest() {
2929
birthday = Date(709164000000L),
3030
height = "176",
3131
weight = "79",
32-
description = setOf(
32+
descriptions = setOf(
3333
Description(
3434
descriptionType = DescriptionType.INTRO,
3535
text = "Lorenor Zorro ist ein Pirat aus der Serie One Piece. Er ist Mitglied der Strohhutbande " +
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package me.proxer.library.api.list
2+
3+
import me.proxer.library.ProxerTest
4+
import me.proxer.library.entity.list.CharacterListEntry
5+
import me.proxer.library.enums.DescriptionType
6+
import me.proxer.library.runRequest
7+
import org.amshove.kluent.shouldBeEqualTo
8+
import org.junit.jupiter.api.Test
9+
10+
/**
11+
* @author TrueMB
12+
*/
13+
class CharacterSearchEndpointTest : ProxerTest() {
14+
15+
private val expectedEntry = CharacterListEntry(
16+
id = "108",
17+
name = "Asuna Yuuki",
18+
description = "[b]Asuna Yuuki[/b] ist die Freundin von [url=http://proxer.me/character?id=43#top][i]" +
19+
"Kirito[/i][/url] und bildet gemeinsam mit ihm den Kopf der Gilde [i]Ritter des Blutschwurs[/i]. " +
20+
"Es ist eine mittelgroße Gilde von etwa dreißig Spielern, die auch als die stärkste Gilde in " +
21+
"[i]Aincrad[/i] bekannt ist. Sie ist eine erfahrene Spielerin, welche den Titel [i]Flash[/i] " +
22+
"für ihre außergewöhnlichen schnellen Schwertfertigkeiten verdient hat."
23+
)
24+
25+
@Test
26+
fun testDefault() {
27+
val (result, _) = server.runRequest("character_list_entry.json") {
28+
api.list
29+
.characterSearch()
30+
.build()
31+
.safeExecute()
32+
}
33+
34+
result.first() shouldBeEqualTo expectedEntry
35+
}
36+
37+
@Test
38+
fun testPath() {
39+
val (_, request) = server.runRequest("character_list_entry.json") {
40+
api.list.characterSearch()
41+
.start("Asu")
42+
.contains("na")
43+
.search("hellbraunes")
44+
.subject(DescriptionType.APPEARANCE)
45+
.limit(10)
46+
.page(3)
47+
.build()
48+
.execute()
49+
}
50+
51+
request.path shouldBeEqualTo """
52+
/api/v1/list/characters?start=Asu&contains=na&search=hellbraunes&subject=appearance&page=3&limit=10
53+
""".trimIndent().replace("\n", "")
54+
}
55+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"error": 0,
3+
"message": "Abfrage erfolgreich",
4+
"data": [
5+
{
6+
"id": "108",
7+
"name": "Asuna Yuuki",
8+
"text": "[b]Asuna Yuuki[/b] ist die Freundin von [url=http://proxer.me/character?id=43#top][i]Kirito[/i][/url] und bildet gemeinsam mit ihm den Kopf der Gilde [i]Ritter des Blutschwurs[/i]. Es ist eine mittelgroße Gilde von etwa dreißig Spielern, die auch als die stärkste Gilde in [i]Aincrad[/i] bekannt ist. Sie ist eine erfahrene Spielerin, welche den Titel [i]Flash[/i] für ihre außergewöhnlichen schnellen Schwertfertigkeiten verdient hat."
9+
},
10+
{
11+
"id": "3576",
12+
"name": "Asuka Kudou",
13+
"text": "[B]Asuka Kudou[/B] ist das zweite Kind, das aus der anderen Welt herbeigerufen wird. Sie ist ein junges Mädchen aus einer reichen Familie zur Zeit des Zweiten Weltkrieges, zählt aber heute zu den Kernmitgliedern der [I]Gemeinschaft No Name[/I]."
14+
},
15+
{
16+
"id": "2033",
17+
"name": "Asuka Kurashina",
18+
"text": "[b]Asuka Kurashina[/b] ist gerade erst auf die Insel [i]Kunashima[/i] und geht dort auf die [i]Kunahama Akademie[/i]."
19+
},
20+
{
21+
"id": "882",
22+
"name": "Asuka Langley Soryuu",
23+
"text": "[b]Asuka Langley Soryu[/b] ist das Kind eines Amerikaners mit einer Japanisch-Deutschen Mutter. Sie ist das zweite Kind das den Evangelion Unit 02 steuert."
24+
},
25+
{
26+
"id": "2105",
27+
"name": "Asukai Katsu",
28+
"text": "[b]Asukai Katsu[/b] ist der König. Er gibt sich jedoch als ein Teil des inneren Kernes aus, um sich zu schützen."
29+
},
30+
{
31+
"id": "4161",
32+
"name": "Asuma Mutsumi",
33+
"text": "[B]Asuma Mutsumi[/B] ist im dritten Semester auf der gleichen Schule wie [URL=https://proxer.me/character?id=3495#top][I]Kae[/I][/URL], welche er, zusammen mit weiteren drei Jungen, umwirbt."
34+
},
35+
{
36+
"id": "4046",
37+
"name": "Asura",
38+
"text": "[B]Asura[/B] ist einer der zwölf Dämonen, mit denen [URL=https://proxer.me/character?id=3811#top][I]Kagemitsu Daigo[/I][/URL] einen Pakt geschlossen hat."
39+
}
40+
]
41+
}

0 commit comments

Comments
 (0)