main1
2991692032 2 months ago
parent 68837be0cb
commit 283973c673

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ApifoxUploaderProjectSetting">
<option name="apiAccessToken" value="APS-Du6Eoh7CmJJcLtPBY40931ru8MEovCoV" />
</component>
</project>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="unilife-server" />
</profile>
</annotationProcessing>
</component>
</project>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/unilife-server/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/unilife-server/src/main/resources" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://maven.aliyun.com/repository/public" />
</remote-repository>
</component>
</project>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/backend/pom.xml" />
<option value="$PROJECT_DIR$/unilife-server/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/unilife.iml" filepath="$PROJECT_DIR$/.idea/unilife.iml" />
</modules>
</component>
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -0,0 +1,258 @@
## 一、API规范
### 1.1 基础信息
- **基础URL**: `http://localhost:8080`(本地测试)
- **接口格式**: RESTful API
- **数据格式**: JSON
- **字符编码**: UTF-8
- **认证方式**: JWT (JSON Web Token)
- **GET**: 获取资源
- **POST**: 创建资源
- **PUT**: 更新资源(全量更新)
- **PATCH**: 部分更新资源
- **DELETE**: 删除资源
### 1.2 响应规范
#### 响应状态码
- **200**: 成功
- **400**: 请求参数错误
- **401**: 未授权
- **403**: 禁止访问
- **404**: 资源不存在
- **500**: 服务器内部错误
#### 后端相应格式
成功响应:
```json
{
"code": 200, // 200表示成功
"message": "success",
"data": { // 实际返回数据
// ...
}
}
```
错误相应:
```json
{
"code": 400,
"message": "参数错误", // 错误信息
"data": null
}
```
## 二、 数据库设计
### 2.1用户表设计 (users)
| 字段名 | 类型 | 约束 | 说明 |
| ----------- | ------------ | ----------------------------------------------------- | ------------------------------------ |
| id | BIGINT | PRIMARY KEY, AUTO_INCREMENT | 用户ID |
| username | VARCHAR(50) | NOT NULL, UNIQUE | 用户名 |
| email | VARCHAR(100) | NOT NULL, UNIQUE | 邮箱地址(学校邮箱) |
| password | VARCHAR(255) | NOT NULL | 密码(加密存储) |
| nickname | VARCHAR(50) | NOT NULL | 昵称 |
| avatar | VARCHAR(255) | | 头像URL |
| bio | TEXT | | 个人简介 |
| gender | TINYINT | | 性别0-未知, 1-男, 2-女) |
| student_id | VARCHAR(20) | UNIQUE | 学号 |
| department | VARCHAR(100) | | 院系 |
| major | VARCHAR(100) | | 专业 |
| grade | VARCHAR(20) | | 年级 |
| points | INT | DEFAULT 0 | 积分 |
| role | TINYINT | DEFAULT 0 | 角色0-普通用户, 1-版主, 2-管理员) |
| status | TINYINT | DEFAULT 1 | 状态0-禁用, 1-启用) |
| is_verified | TINYINT | DEFAULT 0 | 是否验证0-未验证, 1-已验证) |
| login_ip | VARCHAR(50) | | 最近登录IP |
| login_time | DATETIME | | 最近登录时间 |
| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | 创建时间 |
| updated_at | DATETIME | DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | 更新时间 |
#### 建表语句
```sql
CREATE TABLE `users` (
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '用户ID',
`username` VARCHAR(50) NOT NULL UNIQUE COMMENT '用户名',
`email` VARCHAR(100) NOT NULL UNIQUE COMMENT '邮箱地址(学校邮箱)',
`password` VARCHAR(255) NOT NULL COMMENT '密码(加密存储)',
`nickname` VARCHAR(50) NOT NULL COMMENT '昵称',
`avatar` VARCHAR(255) DEFAULT NULL COMMENT '头像URL',
`bio` TEXT DEFAULT NULL COMMENT '个人简介',
`gender` TINYINT DEFAULT 0 COMMENT '性别0-未知, 1-男, 2-女)',
`student_id` VARCHAR(20) UNIQUE DEFAULT NULL COMMENT '学号',
`department` VARCHAR(100) DEFAULT NULL COMMENT '院系',
`major` VARCHAR(100) DEFAULT NULL COMMENT '专业',
`grade` VARCHAR(20) DEFAULT NULL COMMENT '年级',
`points` INT DEFAULT 0 COMMENT '积分',
`role` TINYINT DEFAULT 0 COMMENT '角色0-普通用户, 1-版主, 2-管理员)',
`status` TINYINT DEFAULT 1 COMMENT '状态0-禁用, 1-启用)',
`is_verified` TINYINT DEFAULT 0 COMMENT '是否验证0-未验证, 1-已验证)',
`login_ip` VARCHAR(50) DEFAULT NULL COMMENT '最近登录IP',
`login_time` DATETIME DEFAULT NULL COMMENT '最近登录时间',
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX `idx_email` (`email`),
INDEX `idx_username` (`username`),
INDEX `idx_student_id` (`student_id`),
INDEX `idx_role` (`role`),
INDEX `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户表';
```
## 三、Api功能实现
### 3.1用户认证模块
#### 3.1.1 用户注册
- **URL**: `/auth/register`
- **方法**: POST
- **描述**: 创建新用户账号
请求参数:
```json
{
"username": "student123",
"email": "student@school.edu",
"password": "Secure@Password123",
"nickname": "学生昵称",
"studentId": "20220101001",
"department": "计算机学院",
"major": "软件工程",
"grade": "2023级"
}
```
响应结果:
```json
{
"code": 200,
"message": "注册成功",
"data": {
"userId": 12345,
"username": "student123",
"nickname": "学生昵称"
}
}
```
#### 3.1.2 用户密码登录
- **URL**: `/auth/login`
- **方法**: POST
- **描述**: 用户登录
请求参数:
```json
{
"username": "student123", // 用户名或邮箱
"password": "Secure@Password123"
}
```
响应结果:
```json
{
"code": 200,
"message": "登录成功",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"userInfo": {
"userId": 12345,
"username": "student123",
"nickname": "学生昵称",
"avatar": "https://example.com/avatar.jpg",
"role": 0,
"isVerified": true,
"status": 1
}
}
}
```
#### 3.1.3 获取邮箱验证码
- **URL**: `/auth/email/code`
- **方法**: POST
- **描述**: 向指定邮箱发送登录验证码
请求参数
```json
{
"email": "student@school.edu"
}
```
响应结果:
```json
{
"code": 200,
"message": "验证码已发送",
"data": null
}
```
#### 3.1.4 邮箱验证码登录
- **URL**: `/auth/login/code`
- **方法**: POST
- **描述**: 使用邮箱和验证码进行登录
请求参数
```json
{
"email": "student@school.edu",
"code": "123456"
}
```
成功响应:
```json
{
"code": 200,
"message": "登录成功",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"userInfo": {
"userId": 12345,
"username": "student123",
"nickname": "学生昵称",
"avatar": "https://example.com/avatar.jpg",
"role": 0
}
}
}
```

@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>unilife-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>backend</name>
<description>backend</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.7.6</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.example.unilife.BackendApplication</mainClass>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,13 @@
package com.example.unilife;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class UniLifeApplication {
public static void main(String[] args) {
SpringApplication.run(UniLifeApplication.class, args);
}
}

@ -0,0 +1,8 @@
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/UniLife?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver

@ -0,0 +1,6 @@
<html>
<body>
<h1>hello word!!!</h1>
<p>this is a html page</p>
</body>
</html>

@ -0,0 +1,13 @@
package com.example.unilife;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class BackendApplicationTests {
@Test
void contextLoads() {
}
}
Loading…
Cancel
Save