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