feat(user): 新增用户注册、登录和删除功能
- 新增用户实体类和相关控制器、服务类 - 实现用户注册、登录和删除功能 - 添加用户token生成和验证逻辑 -优化密码存储,使用加密算法
This commit is contained in:
@@ -3,13 +3,19 @@ package com.test.bijihoudaun.controller;
|
||||
|
||||
import com.test.bijihoudaun.entity.Image;
|
||||
import com.test.bijihoudaun.service.ImageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Tag(name = "markdown接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/images")
|
||||
public class ImageController {
|
||||
@@ -17,6 +23,12 @@ public class ImageController {
|
||||
@Autowired
|
||||
private ImageService imageService;
|
||||
|
||||
@Operation(summary = "上传图片")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id", required = true),
|
||||
@Parameter(name = "markdownId", description = "markdownid", required = true),
|
||||
@Parameter(name = "file", description = "图片文件", required = true)
|
||||
})
|
||||
@PostMapping
|
||||
public ResponseEntity<Image> uploadImage(
|
||||
@RequestParam Integer userId,
|
||||
|
||||
@@ -2,10 +2,14 @@ package com.test.bijihoudaun.controller;
|
||||
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.service.MarkdownFileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "markdown接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/markdown")
|
||||
public class MarkdownController {
|
||||
@@ -13,6 +17,13 @@ public class MarkdownController {
|
||||
@Autowired
|
||||
private MarkdownFileService markdownFileService;
|
||||
|
||||
@Operation(summary = "创建markdown文件")
|
||||
@Parameters({
|
||||
@Parameter(name = "userId", description = "用户id",required = true),
|
||||
@Parameter(name = "title", description = "标题",required = true),
|
||||
@Parameter(name = "fileName", description = "文件名",required = true),
|
||||
@Parameter(name = "content", description = "内容",required = true)
|
||||
})
|
||||
@PostMapping
|
||||
public ResponseEntity<MarkdownFile> createMarkdown(
|
||||
@RequestParam Integer userId,
|
||||
@@ -26,7 +37,12 @@ public class MarkdownController {
|
||||
return ResponseEntity.ok(file);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@Operation(summary = "更新Markdown文件")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "Markdown文件ID", required = true),
|
||||
@Parameter(name = "content", description = "Markdown文件内容", required = true)
|
||||
})
|
||||
@PostMapping("/{id}")
|
||||
public ResponseEntity<MarkdownFile> updateMarkdown(
|
||||
@PathVariable Integer id,
|
||||
@RequestBody String content) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.test.bijihoudaun.controller;
|
||||
|
||||
import com.test.bijihoudaun.common.response.R;
|
||||
import com.test.bijihoudaun.entity.User;
|
||||
import com.test.bijihoudaun.service.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@Tag(name = "用户接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Operation(summary = "用户注册")
|
||||
@Parameters({
|
||||
@Parameter(name = "username", description = "用户名",required = true),
|
||||
@Parameter(name = "password", description = "密码",required = true),
|
||||
@Parameter(name = "email", description = "邮箱",required = true)
|
||||
})
|
||||
@PostMapping("/register")
|
||||
public R<User> register(String username, String password, String email){
|
||||
return R.success(userService.register(username,password,email));
|
||||
}
|
||||
|
||||
@Operation(summary = "用户登录")
|
||||
@Parameters({
|
||||
@Parameter(name = "username", description = "用户名",required = true),
|
||||
@Parameter(name = "password", description = "密码",required = true)
|
||||
})
|
||||
@PostMapping("/login")
|
||||
public R<User> login(String username, String password){
|
||||
return R.success(userService.login(username,password));
|
||||
}
|
||||
|
||||
@Operation(summary = "用户删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "用户id",required = true)
|
||||
})
|
||||
@DeleteMapping("/deleteUser")
|
||||
public R<String> deleteUser(Integer id){
|
||||
userService.deleteUser(id);
|
||||
return R.success("删除成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user