some debugs on Chisu playlist

This commit is contained in:
dalbodeule
2024-08-04 15:30:00 +09:00
parent f7953778e1
commit 590c1203bd
11 changed files with 248 additions and 36 deletions

View File

@@ -13,6 +13,7 @@ import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import kotlinx.serialization.json.Json
import space.mori.chzzk_bot.webserver.routes.apiRoutes
import space.mori.chzzk_bot.webserver.routes.apiSongRoutes
import space.mori.chzzk_bot.webserver.routes.wsSongRoutes
import space.mori.chzzk_bot.webserver.routes.wsTimerRoutes
import java.time.Duration
@@ -38,6 +39,7 @@ val server = embeddedServer(Netty, port = 8080) {
}
routing {
apiRoutes()
apiSongRoutes()
wsTimerRoutes()
wsSongRoutes()
swaggerUI("swagger-ui/index.html", "openapi/documentation.yaml") {

View File

@@ -4,10 +4,29 @@ import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.serialization.Serializable
import space.mori.chzzk_bot.common.models.SongList
import space.mori.chzzk_bot.common.services.SongListService
import space.mori.chzzk_bot.common.services.UserService
fun Routing.songRoutes() {
@Serializable
data class SongsDTO(
val url: String,
val name: String,
val author: String,
val time: Int,
val reqName: String
)
fun SongList.toDTO(): SongsDTO = SongsDTO(
this.url,
this.name,
this.author,
this.time,
this.reqName
)
fun Routing.apiSongRoutes() {
route("/songs/{uid}") {
get {
val uid = call.parameters["uid"]
@@ -18,7 +37,7 @@ fun Routing.songRoutes() {
}
val songs = SongListService.getSong(user)
call.respond(songs)
call.respond(HttpStatusCode.OK, songs.map { it.toDTO() })
}
}
route("/songs") {

View File

@@ -86,7 +86,7 @@ fun Routing.wsSongRoutes() {
ws.sendSerialized(SongResponse(
it.type.value,
it.uid,
it.req_uid,
it.reqUid,
it.name,
it.author,
it.time

View File

@@ -8,8 +8,7 @@ servers:
paths:
/:
get:
summary: "Webroot"
description: "Main page of this api"
description: ""
responses:
"200":
description: "OK"
@@ -22,7 +21,7 @@ paths:
value: "Hello World!"
/health:
get:
description: "Health Check endpoint"
description: ""
responses:
"200":
description: "OK"
@@ -32,4 +31,152 @@ paths:
type: "string"
examples:
Example#1:
value: "OK"
value: "OK"
/song/{uid}:
get:
description: ""
parameters:
- name: "uid"
in: "path"
required: true
schema:
type: "string"
- name: "Connection"
in: "header"
required: true
description: "Websocket Connection parameter"
schema:
type: "string"
- name: "Upgrade"
in: "header"
required: true
description: "Websocket Upgrade parameter"
schema:
type: "string"
- name: "Sec-WebSocket-Key"
in: "header"
required: true
description: "Websocket Sec-WebSocket-Key parameter"
schema:
type: "string"
responses:
"101":
description: "Switching Protocols"
headers:
Connection:
required: true
schema:
type: "string"
Upgrade:
required: true
schema:
type: "string"
Sec-WebSocket-Accept:
required: true
schema:
type: "string"
/songs:
get:
description: ""
responses:
"400":
description: "Bad Request"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "Require UID"
/songs/{uid}:
get:
description: ""
parameters:
- name: "uid"
in: "path"
required: true
schema:
type: "string"
responses:
"404":
description: "Not Found"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "No user found"
"200":
description: "OK"
content:
'*/*':
schema:
type: "array"
items:
$ref: "#/components/schemas/SongList"
/timer/{uid}:
get:
description: ""
parameters:
- name: "uid"
in: "path"
required: true
schema:
type: "string"
- name: "Connection"
in: "header"
required: true
description: "Websocket Connection parameter"
schema:
type: "string"
- name: "Upgrade"
in: "header"
required: true
description: "Websocket Upgrade parameter"
schema:
type: "string"
- name: "Sec-WebSocket-Key"
in: "header"
required: true
description: "Websocket Sec-WebSocket-Key parameter"
schema:
type: "string"
responses:
"101":
description: "Switching Protocols"
headers:
Connection:
required: true
schema:
type: "string"
Upgrade:
required: true
schema:
type: "string"
Sec-WebSocket-Accept:
required: true
schema:
type: "string"
components:
schemas:
Object:
type: "object"
properties: {}
ResultRow:
type: "object"
properties:
fieldIndex:
type: "object"
required:
- "fieldIndex"
SongList:
type: "object"
properties:
writeValues:
$ref: "#/components/schemas/Object"
_readValues:
$ref: "#/components/schemas/ResultRow"
required:
- "id"
- "writeValues"