feat(admin): 新增博客设置及文件上传功能
- 新增博客设置数据库表结构及实体类定义 - 实现博客设置的查询与更新接口及服务层逻辑 - 实现管理端博客设置控制器,支持修改和查询博客设置详情 - 实现文件上传接口和服务,支持通过Rustfs上传文件 - 集成Rustfs客户端配置,支持与Rustfs存储系统交互 - 新增统一响应及异常处理,文件上传异常抛出自定义业务异常 - 更新错误码枚举,添加文件上传失败的错误码定义 - 增加请求参数校验,确保博客设置更新接口数据有效性 - 添加日志记录,跟踪文件上传流程及错误信息
This commit is contained in:
@@ -13,6 +13,7 @@ dependencies {
|
||||
api("org.springframework.boot:spring-boot-starter-web")
|
||||
api("org.springframework.boot:spring-boot-starter-security")
|
||||
api("org.springframework.boot:spring-boot-starter-aop")
|
||||
api("software.amazon.awssdk:s3:2.40.1")
|
||||
|
||||
runtimeOnly("org.postgresql:postgresql")
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.hanserwei.common.config;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@Component
|
||||
public class RustfsClientConfig {
|
||||
|
||||
@Resource
|
||||
private RustfsProperties rustfsProperties;
|
||||
|
||||
@Bean
|
||||
public S3Client s3Client() {
|
||||
return S3Client.builder()
|
||||
.endpointOverride(URI.create(rustfsProperties.getEndpoint()))
|
||||
.region(Region.US_EAST_1)
|
||||
.credentialsProvider(
|
||||
StaticCredentialsProvider.create(
|
||||
AwsBasicCredentials.create(rustfsProperties.getAccessKey(), rustfsProperties.getSecretKey())
|
||||
)
|
||||
)
|
||||
.forcePathStyle(true)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.hanserwei.common.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "rustfs")
|
||||
public class RustfsProperties {
|
||||
private String endpoint;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
private String bucketName;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.hanserwei.common.domain.dataobject;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 博客设置表
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Entity
|
||||
@Table(name = "t_blog_settings")
|
||||
public class BlogSettings implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 博客Logo
|
||||
* 数据库类型为 TEXT,Java中映射为 String 即可
|
||||
*/
|
||||
@Column(name = "logo", nullable = false, columnDefinition = "TEXT")
|
||||
@Builder.Default
|
||||
private String logo = "";
|
||||
|
||||
/**
|
||||
* 博客名称
|
||||
*/
|
||||
@Column(name = "name", length = 60, nullable = false)
|
||||
@Builder.Default
|
||||
private String name = "";
|
||||
|
||||
/**
|
||||
* 作者名
|
||||
*/
|
||||
@Column(name = "author", length = 20, nullable = false)
|
||||
@Builder.Default
|
||||
private String author = "";
|
||||
|
||||
/**
|
||||
* 介绍语
|
||||
*/
|
||||
@Column(name = "introduction", nullable = false, columnDefinition = "TEXT")
|
||||
@Builder.Default
|
||||
private String introduction = "";
|
||||
|
||||
/**
|
||||
* 作者头像
|
||||
*/
|
||||
@Column(name = "avatar", nullable = false, columnDefinition = "TEXT")
|
||||
@Builder.Default
|
||||
private String avatar = "";
|
||||
|
||||
/**
|
||||
* GitHub 主页访问地址
|
||||
*/
|
||||
@Column(name = "github_homepage", nullable = false, columnDefinition = "TEXT")
|
||||
@Builder.Default
|
||||
private String githubHomepage = "";
|
||||
|
||||
/**
|
||||
* CSDN 主页访问地址
|
||||
*/
|
||||
@Column(name = "csdn_homepage", nullable = false, columnDefinition = "TEXT")
|
||||
@Builder.Default
|
||||
private String csdnHomepage = "";
|
||||
|
||||
/**
|
||||
* Gitee 主页访问地址
|
||||
*/
|
||||
@Column(name = "gitee_homepage", nullable = false, columnDefinition = "TEXT")
|
||||
@Builder.Default
|
||||
private String giteeHomepage = "";
|
||||
|
||||
/**
|
||||
* 知乎主页访问地址
|
||||
*/
|
||||
@Column(name = "zhihu_homepage", nullable = false, columnDefinition = "TEXT")
|
||||
@Builder.Default
|
||||
private String zhihuHomepage = "";
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.hanserwei.common.domain.repository;
|
||||
|
||||
import com.hanserwei.common.domain.dataobject.BlogSettings;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface BlogSettingsRepository extends JpaRepository<BlogSettings, Long> {
|
||||
|
||||
}
|
||||
@@ -20,7 +20,8 @@ public enum ResponseCodeEnum implements BaseExceptionInterface {
|
||||
USER_NOT_EXIST("2005", "有户不存在!"),
|
||||
CATEGORY_NAME_IS_EXISTED("20005", "该分类已存在,请勿重复添加!"),
|
||||
TAG_NOT_EXIST("20006", "标签不存在!"),
|
||||
CATEGORY_NOT_EXIST("20007", "分类不存在!" );
|
||||
CATEGORY_NOT_EXIST("20007", "分类不存在!"),
|
||||
FILE_UPLOAD_FAILED("20008", "上传文件失败!");
|
||||
|
||||
// 异常码
|
||||
private final String errorCode;
|
||||
|
||||
Reference in New Issue
Block a user