From 87a01e12926440fa080f71842dfae78a232392fc Mon Sep 17 00:00:00 2001 From: 05412 <2738076308@qq.com> Date: Tue, 23 Jul 2024 11:38:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/dev/surl/surl/common/KeyValuePair.kt | 7 +++++++ .../dev/surl/surl/controller/SurlGetController.kt | 3 ++- src/main/java/dev/surl/surl/service/SurlService.kt | 11 ++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/main/java/dev/surl/surl/common/KeyValuePair.kt diff --git a/src/main/java/dev/surl/surl/common/KeyValuePair.kt b/src/main/java/dev/surl/surl/common/KeyValuePair.kt new file mode 100644 index 0000000..89c894c --- /dev/null +++ b/src/main/java/dev/surl/surl/common/KeyValuePair.kt @@ -0,0 +1,7 @@ +package dev.surl.surl.common + +@Suppress("UNUSED") +class KeyValuePair( + val key: K, + val value: V +) \ No newline at end of file diff --git a/src/main/java/dev/surl/surl/controller/SurlGetController.kt b/src/main/java/dev/surl/surl/controller/SurlGetController.kt index 9addb75..f0b55aa 100644 --- a/src/main/java/dev/surl/surl/controller/SurlGetController.kt +++ b/src/main/java/dev/surl/surl/controller/SurlGetController.kt @@ -1,5 +1,6 @@ package dev.surl.surl.controller +import dev.surl.surl.common.KeyValuePair import dev.surl.surl.common.Msg import dev.surl.surl.service.SurlService import dev.surl.surl.util.JwtTokenUtil @@ -19,7 +20,7 @@ class SurlGetController( * 获取用户名下短链接列表 */ @GetMapping(path = ["/api/surl/get"]) - fun getUrlsByUser(@RequestHeader headers: HttpHeaders): Msg> { + fun getUrlsByUser(@RequestHeader headers: HttpHeaders): Msg>> { // 从认证头获取用户名 val username = jwtTokenUtil.getUsernameFromHeader(headers) diff --git a/src/main/java/dev/surl/surl/service/SurlService.kt b/src/main/java/dev/surl/surl/service/SurlService.kt index 4d8a9b1..3314295 100644 --- a/src/main/java/dev/surl/surl/service/SurlService.kt +++ b/src/main/java/dev/surl/surl/service/SurlService.kt @@ -1,7 +1,9 @@ package dev.surl.surl.service +import dev.surl.surl.common.KeyValuePair import dev.surl.surl.dao.Surl import dev.surl.surl.dsl.Surls +import dev.surl.surl.dsl.Users import dev.surl.surl.util.* import kotlinx.coroutines.runBlocking import org.jetbrains.exposed.sql.batchInsert @@ -60,13 +62,12 @@ class SurlService { * 根据用户名获取短链接列表 * @param username 用户名 */ - fun getUrlsByUser(username: String): List { - val user = userService.getUserByUsername(username) ?: return emptyList() + fun getUrlsByUser(username: String): List> { return transaction { - Surl.find { - Surls.user eq user.id + Users.leftJoin(Surls).select(Surls.id, Surls.url).where { + Users.username eq username }.map { - it.url + KeyValuePair(numberToKey(it[Surls.id].value), it[Surls.url]) } } }