refactor application configuration and update user model with new fields
This commit is contained in:
@@ -3,7 +3,11 @@
|
|||||||
"allow": [
|
"allow": [
|
||||||
"Bash(mkdir:*)",
|
"Bash(mkdir:*)",
|
||||||
"Bash(rmdir:*)",
|
"Bash(rmdir:*)",
|
||||||
"Bash(rm:*)"
|
"Bash(rm:*)",
|
||||||
|
"Bash(mvn:*)",
|
||||||
|
"Bash(./mvnw clean compile)",
|
||||||
|
"Bash(cd:*)",
|
||||||
|
"Bash(ls:*)"
|
||||||
],
|
],
|
||||||
"deny": []
|
"deny": []
|
||||||
}
|
}
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<mybatis-flex.version>1.8.6</mybatis-flex.version>
|
<mybatis-flex.version>1.9.3</mybatis-flex.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package com.yundage.chat;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class})
|
||||||
@MapperScan("com.yundage.chat.mapper")
|
@MapperScan("com.yundage.chat.mapper")
|
||||||
public class ChatApplication {
|
public class ChatApplication {
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ public class UserController {
|
|||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public User createUser(@RequestBody User user) {
|
public User createUser(@RequestBody User user) {
|
||||||
user.setCreateTime(LocalDateTime.now());
|
user.setCreatedAt(LocalDateTime.now());
|
||||||
user.setUpdateTime(LocalDateTime.now());
|
user.setUpdatedAt(LocalDateTime.now());
|
||||||
userMapper.insert(user);
|
userMapper.insert(user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ public class UserController {
|
|||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public User updateUser(@PathVariable Long id, @RequestBody User user) {
|
public User updateUser(@PathVariable Long id, @RequestBody User user) {
|
||||||
user.setId(id);
|
user.setId(id);
|
||||||
user.setUpdateTime(LocalDateTime.now());
|
user.setUpdatedAt(LocalDateTime.now());
|
||||||
userMapper.update(user);
|
userMapper.update(user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.yundage.chat.entity;
|
|||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.KeyType;
|
import com.mybatisflex.annotation.KeyType;
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@@ -12,10 +13,17 @@ public class PasswordResetToken {
|
|||||||
@Id(keyType = KeyType.Auto)
|
@Id(keyType = KeyType.Auto)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column("user_id")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
|
@Column("expires_at")
|
||||||
private LocalDateTime expiresAt;
|
private LocalDateTime expiresAt;
|
||||||
|
|
||||||
private Boolean used;
|
private Boolean used;
|
||||||
|
|
||||||
|
@Column("created_at")
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
public PasswordResetToken() {
|
public PasswordResetToken() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.yundage.chat.entity;
|
|||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.KeyType;
|
import com.mybatisflex.annotation.KeyType;
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.yundage.chat.enums.UserType;
|
import com.yundage.chat.enums.UserType;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
@@ -19,15 +20,31 @@ public class User implements UserDetails {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
@Column("password_hash")
|
||||||
private String passwordHash;
|
private String passwordHash;
|
||||||
|
|
||||||
private String phone;
|
private String phone;
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
|
@Column("avatar_url")
|
||||||
private String avatarUrl;
|
private String avatarUrl;
|
||||||
|
|
||||||
|
@Column("user_type")
|
||||||
private UserType userType;
|
private UserType userType;
|
||||||
|
|
||||||
|
@Column("membership_level_id")
|
||||||
private Integer membershipLevelId;
|
private Integer membershipLevelId;
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
@Column("created_at")
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Column("updated_at")
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
@Column("last_login_at")
|
||||||
private LocalDateTime lastLoginAt;
|
private LocalDateTime lastLoginAt;
|
||||||
|
|
||||||
public User() {
|
public User() {
|
||||||
|
|||||||
@@ -4,12 +4,6 @@ spring:
|
|||||||
url: jdbc:mysql://101.200.154.78:3306/yunda_qa?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://101.200.154.78:3306/yunda_qa?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||||
username: root
|
username: root
|
||||||
password: mysql_Jt3yzh
|
password: mysql_Jt3yzh
|
||||||
|
|
||||||
# JPA configuration (optional, if you need JPA alongside MyBatis-Flex)
|
|
||||||
jpa:
|
|
||||||
show-sql: true
|
|
||||||
hibernate:
|
|
||||||
ddl-auto: update
|
|
||||||
|
|
||||||
# Mail configuration
|
# Mail configuration
|
||||||
mail:
|
mail:
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/chat?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://101.200.154.78:3306/yunda_qa?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||||
username: root
|
username: root
|
||||||
password: password
|
password: mysql_Jt3yzh
|
||||||
|
|
||||||
# JPA configuration (optional, if you need JPA alongside MyBatis-Flex)
|
# Mail configuration
|
||||||
jpa:
|
mail:
|
||||||
show-sql: true
|
host: smtp.gmail.com
|
||||||
hibernate:
|
port: 587
|
||||||
ddl-auto: update
|
username: your-email@gmail.com
|
||||||
|
password: your-app-password
|
||||||
|
properties:
|
||||||
|
mail:
|
||||||
|
smtp:
|
||||||
|
auth: true
|
||||||
|
starttls:
|
||||||
|
enable: true
|
||||||
|
|
||||||
# MyBatis-Flex configuration
|
# MyBatis-Flex configuration
|
||||||
mybatis-flex:
|
mybatis-flex:
|
||||||
@@ -19,6 +26,15 @@ mybatis-flex:
|
|||||||
# Mapper XML location (optional)
|
# Mapper XML location (optional)
|
||||||
mapper-locations: classpath*:mapper/*.xml
|
mapper-locations: classpath*:mapper/*.xml
|
||||||
|
|
||||||
|
# JWT configuration
|
||||||
|
jwt:
|
||||||
|
secret: mySecretKeyForJWTTokenGenerationAndValidation
|
||||||
|
expiration: 86400000 # 24 hours in milliseconds
|
||||||
|
|
||||||
|
# App configuration
|
||||||
|
app:
|
||||||
|
reset-password-url: http://localhost:3000/reset-password
|
||||||
|
|
||||||
# Server configuration
|
# Server configuration
|
||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8080
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.yundage.chat.entity.table;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
|
import com.mybatisflex.core.table.TableDef;
|
||||||
|
|
||||||
|
// Auto generate by mybatis-flex, do not modify it.
|
||||||
|
public class PasswordResetTokenTableDef extends TableDef {
|
||||||
|
|
||||||
|
public static final PasswordResetTokenTableDef PASSWORD_RESET_TOKEN = new PasswordResetTokenTableDef();
|
||||||
|
|
||||||
|
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||||
|
|
||||||
|
public final QueryColumn USED = new QueryColumn(this, "used");
|
||||||
|
|
||||||
|
public final QueryColumn TOKEN = new QueryColumn(this, "token");
|
||||||
|
|
||||||
|
public final QueryColumn USER_ID = new QueryColumn(this, "user_id");
|
||||||
|
|
||||||
|
public final QueryColumn CREATED_AT = new QueryColumn(this, "created_at");
|
||||||
|
|
||||||
|
public final QueryColumn EXPIRES_AT = new QueryColumn(this, "expires_at");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, USED, TOKEN, USER_ID, CREATED_AT, EXPIRES_AT};
|
||||||
|
|
||||||
|
public PasswordResetTokenTableDef() {
|
||||||
|
super("", "password_reset_tokens");
|
||||||
|
}
|
||||||
|
|
||||||
|
private PasswordResetTokenTableDef(String schema, String name, String alisa) {
|
||||||
|
super(schema, name, alisa);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PasswordResetTokenTableDef as(String alias) {
|
||||||
|
String key = getNameWithSchema() + "." + alias;
|
||||||
|
return getCache(key, k -> new PasswordResetTokenTableDef("", "password_reset_tokens", alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.yundage.chat.entity.table;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
|
import com.mybatisflex.core.table.TableDef;
|
||||||
|
|
||||||
|
// Auto generate by mybatis-flex, do not modify it.
|
||||||
|
public class UserTableDef extends TableDef {
|
||||||
|
|
||||||
|
public static final UserTableDef USER = new UserTableDef();
|
||||||
|
|
||||||
|
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||||
|
|
||||||
|
public final QueryColumn EMAIL = new QueryColumn(this, "email");
|
||||||
|
|
||||||
|
public final QueryColumn PHONE = new QueryColumn(this, "phone");
|
||||||
|
|
||||||
|
public final QueryColumn STATUS = new QueryColumn(this, "status");
|
||||||
|
|
||||||
|
public final QueryColumn USER_TYPE = new QueryColumn(this, "user_type");
|
||||||
|
|
||||||
|
public final QueryColumn USERNAME = new QueryColumn(this, "username");
|
||||||
|
|
||||||
|
public final QueryColumn AVATAR_URL = new QueryColumn(this, "avatar_url");
|
||||||
|
|
||||||
|
public final QueryColumn CREATED_AT = new QueryColumn(this, "created_at");
|
||||||
|
|
||||||
|
public final QueryColumn UPDATED_AT = new QueryColumn(this, "updated_at");
|
||||||
|
|
||||||
|
public final QueryColumn LAST_LOGIN_AT = new QueryColumn(this, "last_login_at");
|
||||||
|
|
||||||
|
public final QueryColumn PASSWORD_HASH = new QueryColumn(this, "password_hash");
|
||||||
|
|
||||||
|
public final QueryColumn MEMBERSHIP_LEVEL_ID = new QueryColumn(this, "membership_level_id");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, EMAIL, PHONE, STATUS, USER_TYPE, USERNAME, AVATAR_URL, CREATED_AT, UPDATED_AT, LAST_LOGIN_AT, PASSWORD_HASH, MEMBERSHIP_LEVEL_ID};
|
||||||
|
|
||||||
|
public UserTableDef() {
|
||||||
|
super("", "users");
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserTableDef(String schema, String name, String alisa) {
|
||||||
|
super(schema, name, alisa);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserTableDef as(String alias) {
|
||||||
|
String key = getNameWithSchema() + "." + alias;
|
||||||
|
return getCache(key, k -> new UserTableDef("", "users", alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user