feat-完成数据库对user_data表的检查
This commit is contained in:
parent
ae22a1db53
commit
fe91e5aba8
@ -27,4 +27,15 @@ public class LoggingAspect {
|
|||||||
|
|
||||||
log.info("[CONTROLLER] 获取 {} 类的 {} 方法", targetClass.getName(), methodName);
|
log.info("[CONTROLLER] 获取 {} 类的 {} 方法", targetClass.getName(), methodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Before("execution(* cn.dcsy.stsy.service.impl.*.*(..))")
|
||||||
|
// public void serviceAspect(JoinPoint joinPoint) {
|
||||||
|
// Signature signature = joinPoint.getSignature();
|
||||||
|
// String methodName = signature.getName();
|
||||||
|
//
|
||||||
|
// Object targetObject = joinPoint.getTarget();
|
||||||
|
// Class<?> targetClass = targetObject.getClass();
|
||||||
|
//
|
||||||
|
// log.info("[SERVICE] 获取 {} 类的 {} 方法", targetClass.getName(), methodName);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
63
src/main/java/cn/dcsy/stsy/config/StartupConfiguration.java
Normal file
63
src/main/java/cn/dcsy/stsy/config/StartupConfiguration.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package cn.dcsy.stsy.config;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.sql.SQLSyntaxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DC_DC
|
||||||
|
* Date: 2024/4/23/20:37
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class StartupConfiguration {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(StartupConfiguration.class);
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Order(1)
|
||||||
|
public CommandLineRunner sqlPreparation(JdbcTemplate jdbcTemplate) {
|
||||||
|
log.info("[Runner]执行数据库初始化语句");
|
||||||
|
return args -> {
|
||||||
|
// 创建数据表
|
||||||
|
// MySQL默认不支持在单个语句或批次中执行多个命令,需要分割SQL语句
|
||||||
|
log.info("\t->创建 userdata 数据表");
|
||||||
|
jdbcTemplate.execute(
|
||||||
|
"""
|
||||||
|
create table if not exists user_data
|
||||||
|
(
|
||||||
|
uid bigint unsigned not null comment '用户表序号'
|
||||||
|
primary key,
|
||||||
|
uuid char(36) not null comment '用户唯一识别码',
|
||||||
|
name varchar(100) not null comment '用户名',
|
||||||
|
gender varchar(10) null comment '用户性别',
|
||||||
|
email varchar(100) not null comment '用户邮箱',
|
||||||
|
password varchar(255) not null comment '用户密码',
|
||||||
|
avatar text null comment '用户头像',
|
||||||
|
create_at timestamp not null comment '用户创建时间',
|
||||||
|
deleted_at timestamp null comment '用户删除时间',
|
||||||
|
update_at timestamp null comment '用户更新时间',
|
||||||
|
all_stories json null comment '与用户相关的所有故事',
|
||||||
|
constraint user_data_email_uindex
|
||||||
|
unique (email));
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
jdbcTemplate.execute("CREATE INDEX uuid_index ON user_data (uuid)");
|
||||||
|
} catch (DataAccessException ex) {
|
||||||
|
SQLSyntaxErrorException sqlSyntaxErrorException = (SQLSyntaxErrorException) ex.getCause();
|
||||||
|
if (sqlSyntaxErrorException.getMessage().contains("Duplicate key name")) {
|
||||||
|
log.info("\t->索引已经存在");
|
||||||
|
} else {
|
||||||
|
log.error(String.valueOf(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package cn.dcsy.stsy.controllers;
|
package cn.dcsy.stsy.controllers;
|
||||||
|
|
||||||
import cn.dcsy.stsy.models.voData.BasicLoginVO;
|
import cn.dcsy.stsy.models.voData.BasicLoginVO;
|
||||||
|
import cn.dcsy.stsy.models.voData.BasicRegisterVO;
|
||||||
import cn.dcsy.stsy.service.UserService;
|
import cn.dcsy.stsy.service.UserService;
|
||||||
import cn.dcsy.stsy.utils.BaseResponse;
|
import cn.dcsy.stsy.utils.BaseResponse;
|
||||||
import cn.dcsy.stsy.utils.ErrorCode;
|
import cn.dcsy.stsy.utils.ErrorCode;
|
||||||
@ -37,22 +38,44 @@ public class BasicController {
|
|||||||
return ResultUtil.success("访问成功");
|
return ResultUtil.success("访问成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/basic/register")
|
||||||
|
public ResponseEntity<BaseResponse> register(
|
||||||
|
@RequestBody @Validated BasicRegisterVO basicRegisterVO,
|
||||||
|
@NotNull BindingResult bindingResult,
|
||||||
|
HttpServletRequest request
|
||||||
|
) {
|
||||||
|
// 注册账号和发送验证码分了两个控制器,因为输入邮箱注册,旁边会有一个按钮,点击发送之后,调用邮件控制器进行发送邮件,所以在注册控制器中,只需要提取用户填入的验证码信息进行校验就好了
|
||||||
|
log.info("\t->尝试注册账号 邮箱: {}", basicRegisterVO.getEmail());
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
return ResultUtil.error("RequestBodyError", ErrorCode.REQUEST_BODY_ERROR, bindingResult.getAllErrors());
|
||||||
|
}
|
||||||
|
return ResultUtil.success("注册成功");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录
|
||||||
* */
|
* */
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public ResponseEntity<BaseResponse> login(
|
public ResponseEntity<BaseResponse> login(
|
||||||
|
// 使用@RequestBody注解接受前端返回的json数据,一般我们都是使用json传递数据
|
||||||
@RequestBody @Validated BasicLoginVO basicLoginVO,
|
@RequestBody @Validated BasicLoginVO basicLoginVO,
|
||||||
@NotNull BindingResult bindingResult,
|
@NotNull BindingResult bindingResult,
|
||||||
HttpServletRequest request
|
HttpServletRequest request
|
||||||
) {
|
) {
|
||||||
log.info("\t尝试登录 用户名: {}", basicLoginVO.getUsername());
|
log.info("\t->尝试登录 用户名: {}", basicLoginVO.getUsername());
|
||||||
if (bindingResult.hasErrors()) {
|
if (bindingResult.hasErrors()) {
|
||||||
return ResultUtil.error("RequestBodyError", ErrorCode.REQUEST_BODY_ERROR, bindingResult.getAllErrors());
|
return ResultUtil.error("RequestBodyError", ErrorCode.REQUEST_BODY_ERROR, bindingResult.getAllErrors());
|
||||||
}
|
}
|
||||||
return userService.login(request, basicLoginVO);
|
return userService.login(request, basicLoginVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/user/{userId}")
|
@GetMapping("/user/{userId}")
|
||||||
public ResponseEntity<BaseResponse> getUserCurrent(@PathVariable String userId) {
|
public ResponseEntity<BaseResponse> getUserCurrent(@PathVariable String userId) {
|
||||||
log.info("获取用户 {}", userId);
|
log.info("获取用户 {}", userId);
|
||||||
|
37
src/main/java/cn/dcsy/stsy/controllers/MailController.java
Normal file
37
src/main/java/cn/dcsy/stsy/controllers/MailController.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package cn.dcsy.stsy.controllers;
|
||||||
|
|
||||||
|
import cn.dcsy.stsy.models.voData.MailSendCodeVO;
|
||||||
|
import cn.dcsy.stsy.utils.BaseResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DC_DC
|
||||||
|
* Date: 2024/4/23/20:26
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MailController {
|
||||||
|
/**
|
||||||
|
* sendMailCode
|
||||||
|
* <hr/>
|
||||||
|
* 用于发送邮件验证码,用户可以通过该接口发送邮件验证码
|
||||||
|
*
|
||||||
|
* @param mailSendCodeVO 邮件发送验证码的请求参数
|
||||||
|
* @param request 请求对象
|
||||||
|
* @param bindingResult 请求参数的校验结果
|
||||||
|
* @return 返回发送邮件验证码的结果
|
||||||
|
* */
|
||||||
|
@PostMapping("/send")
|
||||||
|
public ResponseEntity<BaseResponse> sendMailCode(
|
||||||
|
@RequestBody @Validated MailSendCodeVO mailSendCodeVO,
|
||||||
|
@NotNull BindingResult bindingResult,
|
||||||
|
@NotNull HttpServletRequest request
|
||||||
|
){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package cn.dcsy.stsy.models.voData;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DC_DC
|
||||||
|
* Date: 2024/4/23/20:17
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class BasicRegisterVO {
|
||||||
|
private String email;
|
||||||
|
private String code;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
}
|
17
src/main/java/cn/dcsy/stsy/models/voData/MailSendCodeVO.java
Normal file
17
src/main/java/cn/dcsy/stsy/models/voData/MailSendCodeVO.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package cn.dcsy.stsy.models.voData;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DC_DC
|
||||||
|
* Date: 2024/4/23/20:35
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MailSendCodeVO {
|
||||||
|
@Email(message = "邮箱格式不正确")
|
||||||
|
public String email;
|
||||||
|
@NotBlank(message = "模板不能为空")
|
||||||
|
public String template;
|
||||||
|
}
|
@ -3,6 +3,6 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3305
|
url: jdbc:mysql://localhost:3305/stories_system
|
||||||
username: "root"
|
username: "root"
|
||||||
password: "123456"
|
password: "123456"
|
Loading…
x
Reference in New Issue
Block a user