forked from proxer/ProxerLibJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
library/src/main/kotlin/me/proxer/library/api/list/CharacterSearchEndpoint.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,51 @@ | ||
package me.proxer.library.api.list | ||
|
||
import me.proxer.library.ProxerCall | ||
import me.proxer.library.api.PagingLimitEndpoint | ||
import me.proxer.library.entity.list.CharacterListEntry | ||
import me.proxer.library.enums.DescriptionType | ||
|
||
/** | ||
* Search for all available characters. Features various filter and uses paging. | ||
* | ||
* @author TrueMB | ||
*/ | ||
class CharacterSearchEndpoint internal constructor( | ||
private val internalApi: InternalApi | ||
) : PagingLimitEndpoint<List<CharacterListEntry>> { | ||
|
||
private var page: Int? = null | ||
private var limit: Int? = null | ||
|
||
private var start: String? = null | ||
private var contains: String? = null | ||
private var search: String? = null | ||
private var subject: DescriptionType? = null | ||
|
||
override fun page(page: Int?) = this.apply { this.page = page } | ||
override fun limit(limit: Int?) = this.apply { this.limit = limit } | ||
|
||
/** | ||
* Sets the start String to search for. | ||
*/ | ||
fun start(start: String?) = this.apply { this.start = start } | ||
|
||
/** | ||
* Sets the contains String to search for. | ||
*/ | ||
fun contains(contains: String?) = this.apply { this.contains = contains } | ||
|
||
/** | ||
* Sets the search String to search for in the descriptions. | ||
*/ | ||
fun search(search: String?) = this.apply { this.search = search } | ||
|
||
/** | ||
* Sets the subject that should be looked in. | ||
*/ | ||
fun subject(subject: DescriptionType?) = this.apply { this.subject = subject } | ||
|
||
override fun build(): ProxerCall<List<CharacterListEntry>> { | ||
return internalApi.characterSearch(start, contains, search, subject, page, limit) | ||
} | ||
} |
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
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
20 changes: 20 additions & 0 deletions
20
library/src/main/kotlin/me/proxer/library/entity/list/CharacterListEntry.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 me.proxer.library.entity.list | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import me.proxer.library.entity.ProxerIdItem | ||
|
||
/** | ||
* Entity holding all relevant info about a single entry of the character list. | ||
* | ||
* @property name The name. | ||
* @property description The description. | ||
* | ||
* @author TrueMB | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class CharacterListEntry( | ||
@Json(name = "id") override val id: String, | ||
@Json(name = "name") val name: String, | ||
@Json(name = "text") val description: String | ||
) : ProxerIdItem |
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
55 changes: 55 additions & 0 deletions
55
library/src/test/kotlin/me/proxer/library/api/list/CharacterSearchEndpointTest.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,55 @@ | ||
package me.proxer.library.api.list | ||
|
||
import me.proxer.library.ProxerTest | ||
import me.proxer.library.entity.list.CharacterListEntry | ||
import me.proxer.library.enums.DescriptionType | ||
import me.proxer.library.runRequest | ||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.jupiter.api.Test | ||
|
||
/** | ||
* @author TrueMB | ||
*/ | ||
class CharacterSearchEndpointTest : ProxerTest() { | ||
|
||
private val expectedEntry = CharacterListEntry( | ||
id = "108", | ||
name = "Asuna Yuuki", | ||
description = "[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." | ||
) | ||
|
||
@Test | ||
fun testDefault() { | ||
val (result, _) = server.runRequest("character_list_entry.json") { | ||
api.list | ||
.characterSearch() | ||
.build() | ||
.safeExecute() | ||
} | ||
|
||
result.first() shouldBeEqualTo expectedEntry | ||
} | ||
|
||
@Test | ||
fun testPath() { | ||
val (_, request) = server.runRequest("character_list_entry.json") { | ||
api.list.characterSearch() | ||
.start("Asu") | ||
.contains("na") | ||
.search("hellbraunes") | ||
.subject(DescriptionType.APPEARANCE) | ||
.limit(10) | ||
.page(3) | ||
.build() | ||
.execute() | ||
} | ||
|
||
request.path shouldBeEqualTo """ | ||
/api/v1/list/characters?start=Asu&contains=na&search=hellbraunes&subject=appearance&page=3&limit=10 | ||
""".trimIndent().replace("\n", "") | ||
} | ||
} |
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,41 @@ | ||
{ | ||
"error": 0, | ||
"message": "Abfrage erfolgreich", | ||
"data": [ | ||
{ | ||
"id": "108", | ||
"name": "Asuna Yuuki", | ||
"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." | ||
}, | ||
{ | ||
"id": "3576", | ||
"name": "Asuka Kudou", | ||
"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]." | ||
}, | ||
{ | ||
"id": "2033", | ||
"name": "Asuka Kurashina", | ||
"text": "[b]Asuka Kurashina[/b] ist gerade erst auf die Insel [i]Kunashima[/i] und geht dort auf die [i]Kunahama Akademie[/i]." | ||
}, | ||
{ | ||
"id": "882", | ||
"name": "Asuka Langley Soryuu", | ||
"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." | ||
}, | ||
{ | ||
"id": "2105", | ||
"name": "Asukai Katsu", | ||
"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." | ||
}, | ||
{ | ||
"id": "4161", | ||
"name": "Asuma Mutsumi", | ||
"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." | ||
}, | ||
{ | ||
"id": "4046", | ||
"name": "Asura", | ||
"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." | ||
} | ||
] | ||
} |