From c34d26af88d51f2822b3671b5e40858e18831814 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 16 Nov 2023 18:16:38 +0800 Subject: [PATCH] Temp AvatarController --- .../api/controller/api/v1/AvatarController.kt | 30 +++++++++++++++++++ .../api/service/api/v1/AvatarServiceImpl.kt | 18 +++++++++++ .../api/service/api/v1/IAvatarService.kt | 7 +++++ .../api/vo/api/v1/avatar/DefaultBase64Vo.kt | 9 ++++++ 4 files changed, 64 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/api/v1/AvatarServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/api/v1/IAvatarService.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/api/v1/avatar/DefaultBase64Vo.kt diff --git a/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt b/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt new file mode 100644 index 0000000..c8d0808 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt @@ -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 { + return ResponseResult.success(data = avatarService.getDefault()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/api/v1/AvatarServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/api/v1/AvatarServiceImpl.kt new file mode 100644 index 0000000..24ce514 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/api/v1/AvatarServiceImpl.kt @@ -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)) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/api/v1/IAvatarService.kt b/src/main/kotlin/top/fatweb/api/service/api/v1/IAvatarService.kt new file mode 100644 index 0000000..c07bd20 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/api/v1/IAvatarService.kt @@ -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 +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/api/v1/avatar/DefaultBase64Vo.kt b/src/main/kotlin/top/fatweb/api/vo/api/v1/avatar/DefaultBase64Vo.kt new file mode 100644 index 0000000..0ae5cb0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/api/v1/avatar/DefaultBase64Vo.kt @@ -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? +)