From 1aa5f31694f728c816ca9b23d5df4fde84347dd7 Mon Sep 17 00:00:00 2001 From: 05412 Date: Tue, 6 Aug 2024 08:20:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96surl?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/surl/surl/controller/SurlGetController.kt | 6 ++++++ src/main/java/dev/surl/surl/service/SurlService.kt | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/dev/surl/surl/controller/SurlGetController.kt b/src/main/java/dev/surl/surl/controller/SurlGetController.kt index f0b55aa..dd0e6ee 100644 --- a/src/main/java/dev/surl/surl/controller/SurlGetController.kt +++ b/src/main/java/dev/surl/surl/controller/SurlGetController.kt @@ -30,4 +30,10 @@ class SurlGetController( return Msg(value = urls) } + + @GetMapping(path = ["/api/surl/count/get"]) + fun getUrlsCountByUser(@RequestHeader headers: HttpHeaders): Msg { + val username = jwtTokenUtil.getUsernameFromHeader(headers) + return Msg(value = surlService.getUrlsCountByUser(username)) + } } \ No newline at end of file diff --git a/src/main/java/dev/surl/surl/service/SurlService.kt b/src/main/java/dev/surl/surl/service/SurlService.kt index 988257b..bf185b8 100644 --- a/src/main/java/dev/surl/surl/service/SurlService.kt +++ b/src/main/java/dev/surl/surl/service/SurlService.kt @@ -7,6 +7,7 @@ import dev.surl.surl.dsl.Users import dev.surl.surl.util.* import kotlinx.coroutines.runBlocking import org.jetbrains.exposed.sql.batchInsert +import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction import org.springframework.stereotype.Service @@ -73,4 +74,15 @@ class SurlService { } } } + + /** + * 获取用户短链接数量 + * @param username 用户名 + * @return 短链接数量 + */ + fun getUrlsCountByUser(username: String) = transaction { + Users.innerJoin(Surls).selectAll().where { + Users.username eq username + }.count() + } } \ No newline at end of file