添加获取surl数量接口

This commit is contained in:
05412 2024-08-06 08:20:46 +08:00
parent 87ab3df17c
commit 1aa5f31694
2 changed files with 18 additions and 0 deletions

View File

@ -30,4 +30,10 @@ class SurlGetController(
return Msg(value = urls) return Msg(value = urls)
} }
@GetMapping(path = ["/api/surl/count/get"])
fun getUrlsCountByUser(@RequestHeader headers: HttpHeaders): Msg<Long> {
val username = jwtTokenUtil.getUsernameFromHeader(headers)
return Msg(value = surlService.getUrlsCountByUser(username))
}
} }

View File

@ -7,6 +7,7 @@ import dev.surl.surl.dsl.Users
import dev.surl.surl.util.* import dev.surl.surl.util.*
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.jetbrains.exposed.sql.batchInsert import org.jetbrains.exposed.sql.batchInsert
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import org.springframework.stereotype.Service 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()
}
} }