diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 1d5a132..5e89e00 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,6 +2,7 @@ + diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..5e22704 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,17 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306/unilife + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/UniLife开发文档.md b/UniLife开发文档.md index 984a740..fbfdd20 100644 --- a/UniLife开发文档.md +++ b/UniLife开发文档.md @@ -124,7 +124,7 @@ CREATE TABLE `users` ( #### 3.1.1 用户注册 -- **URL**: `/auth/register` +- **URL**: `/users/register` - **方法**: POST @@ -162,7 +162,7 @@ CREATE TABLE `users` ( #### 3.1.2 用户密码登录 -- **URL**: `/auth/login` +- **URL**: `/users/login` - **方法**: POST - **描述**: 用户登录 @@ -198,7 +198,7 @@ CREATE TABLE `users` ( #### 3.1.3 获取邮箱验证码 -- **URL**: `/auth/email/code` +- **URL**: `/users/code` - **方法**: POST @@ -224,7 +224,7 @@ CREATE TABLE `users` ( #### 3.1.4 邮箱验证码登录 -- **URL**: `/auth/login/code` +- **URL**: `/users/login/code` - **方法**: POST - **描述**: 使用邮箱和验证码进行登录 diff --git a/unilife-server/pom.xml b/unilife-server/pom.xml index d2f2315..dc2290b 100644 --- a/unilife-server/pom.xml +++ b/unilife-server/pom.xml @@ -39,6 +39,16 @@ spring-boot-starter-test test + + com.github.xiaoymin + knife4j-openapi2-spring-boot-starter + 4.4.0 + + + cn.hutool + hutool-all + 5.8.16 + diff --git a/unilife-server/src/main/java/com/example/unilife/UniLifeApplication.java b/unilife-server/src/main/java/com/unilife/UniLifeApplication.java similarity index 91% rename from unilife-server/src/main/java/com/example/unilife/UniLifeApplication.java rename to unilife-server/src/main/java/com/unilife/UniLifeApplication.java index 70ebbe4..3cfbd02 100644 --- a/unilife-server/src/main/java/com/example/unilife/UniLifeApplication.java +++ b/unilife-server/src/main/java/com/unilife/UniLifeApplication.java @@ -1,4 +1,4 @@ -package com.example.unilife; +package com.unilife; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/unilife-server/src/main/java/com/unilife/common/result/Result.java b/unilife-server/src/main/java/com/unilife/common/result/Result.java new file mode 100644 index 0000000..ebcc627 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/common/result/Result.java @@ -0,0 +1,51 @@ +package com.unilife.common.result; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Result{ + /*** + * 状态码 + */ + private Integer code; + /*** + * 消息 + */ + private String message; + /*** + *数据 + */ + private T data; + + /*** + * + * @param data 数据 + * @return 结果对象 + * @param 数据类型 + */ + public static Resultsuccess(T data){ + return new Result(200, "success", data); + } + + /** + * 成功返回结果 + * @return 结果对象 + */ + public static Result success() { + return new Result<>(200, "success", null); + } + + /** + * 失败返回结果 + * @param code 状态码 + * @param message 消息 + * @return 结果对象 + */ + public static Result error(Integer code, String message) { + return new Result<>(code, message, null); + } +} diff --git a/unilife-server/src/main/java/com/unilife/controller/UserController.java b/unilife-server/src/main/java/com/unilife/controller/UserController.java new file mode 100644 index 0000000..435b499 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/controller/UserController.java @@ -0,0 +1,27 @@ +package com.unilife.controller; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.LoginDTO; +import com.unilife.service.UserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "用户管理") +@RestController +@RequestMapping("/users") +public class UserController { + + @Autowired + private UserService userService; + + @ApiOperation(value = "用户注册") + @PostMapping("register") + public Result register(@RequestBody LoginDTO loginDTO) { + return userService.register(loginDTO); + } +} diff --git a/unilife-server/src/main/java/com/unilife/mapper/UserMapper.java b/unilife-server/src/main/java/com/unilife/mapper/UserMapper.java new file mode 100644 index 0000000..5d58437 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/mapper/UserMapper.java @@ -0,0 +1,9 @@ +package com.unilife.mapper; + +import com.unilife.model.entity.User; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface UserMapper { + public void insert(User user) ; +} diff --git a/unilife-server/src/main/java/com/unilife/model/dto/LoginDTO.java b/unilife-server/src/main/java/com/unilife/model/dto/LoginDTO.java new file mode 100644 index 0000000..d593c47 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/dto/LoginDTO.java @@ -0,0 +1,19 @@ +package com.unilife.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class LoginDTO { + private String username; + private String email; + private String password; + private String nickname; + private String studentId; + private String department; + private String major; + private String grade; +} diff --git a/unilife-server/src/main/java/com/unilife/model/entity/User.java b/unilife-server/src/main/java/com/unilife/model/entity/User.java new file mode 100644 index 0000000..4495243 --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/entity/User.java @@ -0,0 +1,56 @@ +package com.unilife.model.entity; + +import lombok.*; + +import java.io.Serializable; +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class User implements Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + + private String username; + + private String email; + + private String password; + + private String nickname; + + private String avatar; + + private String bio; + + private Byte gender; + + private String studentId; + + private String department; + + private String major; + + private String grade; + + private Integer points = 0; + + private Byte role = 0; + + private Byte status = 1; + + private Byte isVerified = 0; + + private String loginIp; + + private LocalDateTime loginTime; + + private LocalDateTime createdAt; + + private LocalDateTime updatedAt; + +} diff --git a/unilife-server/src/main/java/com/unilife/model/vo/LoginVO.java b/unilife-server/src/main/java/com/unilife/model/vo/LoginVO.java new file mode 100644 index 0000000..6df92df --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/model/vo/LoginVO.java @@ -0,0 +1,10 @@ +package com.unilife.model.vo; + +import lombok.Data; + +@Data +public class LoginVO { + private Integer id; + private String username; + private String nickname; +} diff --git a/unilife-server/src/main/java/com/unilife/service/UserService.java b/unilife-server/src/main/java/com/unilife/service/UserService.java new file mode 100644 index 0000000..11c74dd --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/UserService.java @@ -0,0 +1,9 @@ +package com.unilife.service; + +import com.unilife.common.result.Result; +import com.unilife.model.dto.LoginDTO; + + +public interface UserService { + Result register(LoginDTO loginDTO); +} diff --git a/unilife-server/src/main/java/com/unilife/service/impl/UserServiceImpl.java b/unilife-server/src/main/java/com/unilife/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..75f3fde --- /dev/null +++ b/unilife-server/src/main/java/com/unilife/service/impl/UserServiceImpl.java @@ -0,0 +1,27 @@ +package com.unilife.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.unilife.common.result.Result; +import com.unilife.mapper.UserMapper; +import com.unilife.model.dto.LoginDTO; +import com.unilife.model.entity.User; +import com.unilife.model.vo.LoginVO; +import com.unilife.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl implements UserService { + + @Autowired + private UserMapper userMapper; + + @Override + public Result register(LoginDTO loginDTO) { + User user = new User(); + BeanUtil.copyProperties(loginDTO,user); + userMapper.insert(user); + LoginVO loginVO = new LoginVO(); + return Result.success(loginVO); + } +} diff --git a/unilife-server/src/main/resources/application.yml b/unilife-server/src/main/resources/application.yml index b1bc0ad..a28359d 100644 --- a/unilife-server/src/main/resources/application.yml +++ b/unilife-server/src/main/resources/application.yml @@ -6,3 +6,25 @@ spring: username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver +knife4j: + enable: true + openapi: + title: Knife4j官方文档 + description: "测试" + email: xiaoymin@foxmail.com + concat: 八一菜刀 + url: https://docs.xiaominfo.com + version: v4.0 + license: Apache 2.0 + license-url: https://stackoverflow.com/ + terms-of-service-url: https://stackoverflow.com/ + group: + test1: + group-name: 分组名称 + api-rule: package + api-rule-resources: + - com.unilife +mybatis: + mapper-locations: classpath:mappers/*.xml + configuration: + map-underscore-to-camel-case: true diff --git a/unilife-server/src/main/resources/mappers/UserMapper.xml b/unilife-server/src/main/resources/mappers/UserMapper.xml new file mode 100644 index 0000000..26face9 --- /dev/null +++ b/unilife-server/src/main/resources/mappers/UserMapper.xml @@ -0,0 +1,43 @@ + + + + + INSERT INTO users ( + username, + email, + password, + nickname, + avatar, + bio, + gender, + student_id, + department, + major, + grade, + points, + role, + status, + is_verified, + login_ip, + login_time + ) VALUES ( + #{username}, + #{email}, + #{password}, + #{nickname}, + #{avatar}, + #{bio}, + #{gender}, + #{studentId}, + #{department}, + #{major}, + #{grade}, + #{points}, + #{role}, + #{status}, + #{isVerified}, + #{loginIp}, + #{loginTime} + ) + + \ No newline at end of file diff --git a/unilife-server/src/test/java/com/example/unilife/BackendApplicationTests.java b/unilife-server/src/test/java/com/unilife/BackendApplicationTests.java similarity index 86% rename from unilife-server/src/test/java/com/example/unilife/BackendApplicationTests.java rename to unilife-server/src/test/java/com/unilife/BackendApplicationTests.java index df4e504..afe129e 100644 --- a/unilife-server/src/test/java/com/example/unilife/BackendApplicationTests.java +++ b/unilife-server/src/test/java/com/unilife/BackendApplicationTests.java @@ -1,4 +1,4 @@ -package com.example.unilife; +package com.unilife; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;