Complete core functions #9

Merged
FatttSnake merged 171 commits from FatttSnake into dev 2024-02-23 11:56:35 +08:00
4 changed files with 64 additions and 0 deletions
Showing only changes of commit c34d26af88 - Show all commits

View File

@@ -0,0 +1,30 @@
package top.fatweb.api.controller.api.v1
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import top.fatweb.api.entity.common.ResponseResult
import top.fatweb.api.service.api.v1.IAvatarService
import top.fatweb.api.vo.api.v1.avatar.DefaultBase64Vo
/**
* Avatar controller
*
* @author FatttSnake
* @since 1.0.0
*/
@Tag(name = "随机头像", description = "随机头像相关接口")
@RestController
@RequestMapping("/api/{apiVersion}/avatar")
class AvatarController(
private val avatarService: IAvatarService
) {
@Operation(summary = "获取默认随机头像")
@GetMapping
fun getDefault(@PathVariable apiVersion: String): ResponseResult<DefaultBase64Vo> {
return ResponseResult.success(data = avatarService.getDefault())
}
}

View File

@@ -0,0 +1,18 @@
package top.fatweb.api.service.api.v1
import com.talanlabs.avatargenerator.GitHubAvatar
import org.springframework.stereotype.Service
import top.fatweb.api.vo.api.v1.avatar.DefaultBase64Vo
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
@Service
class AvatarServiceImpl : IAvatarService {
@OptIn(ExperimentalEncodingApi::class)
override fun getDefault(): DefaultBase64Vo {
val avatar = GitHubAvatar.newAvatarBuilder(396, 5).build()
val bytes = avatar.createAsPngBytes(1232132134543L)
return DefaultBase64Vo(Base64.encode(bytes))
}
}

View File

@@ -0,0 +1,7 @@
package top.fatweb.api.service.api.v1
import top.fatweb.api.vo.api.v1.avatar.DefaultBase64Vo
interface IAvatarService {
fun getDefault(): DefaultBase64Vo
}

View File

@@ -0,0 +1,9 @@
package top.fatweb.api.vo.api.v1.avatar
import io.swagger.v3.oas.annotations.media.Schema
@Schema(description = "默认随机头像 Base64 返回参数")
data class DefaultBase64Vo(
@Schema(description = "base64")
val base64: String?
)