feat: 个人信息修改
This commit is contained in:
@@ -10,6 +10,7 @@ import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 用户控制器
|
||||
@@ -54,4 +55,29 @@ public class UserController {
|
||||
userService.updateStatus(accountId, request);
|
||||
return ApiResponse.ok(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
*
|
||||
* 接收裁剪后的图片文件(JPEG/PNG/WebP/GIF,≤2MB),保存后返回更新后的用户信息。
|
||||
* 旧头像文件会被自动删除。
|
||||
*/
|
||||
@PostMapping("/avatar")
|
||||
public ApiResponse<UserInfoResponse> uploadAvatar(@RequestParam("file") MultipartFile file) {
|
||||
String accountId = StpUtil.getLoginIdAsString();
|
||||
UserInfoResponse result = userService.uploadAvatar(accountId, file);
|
||||
return ApiResponse.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户头像
|
||||
*
|
||||
* 删除磁盘文件并将 DB 中 avatar 置空,前端会回退显示默认头像。
|
||||
*/
|
||||
@DeleteMapping("/avatar")
|
||||
public ApiResponse<UserInfoResponse> deleteAvatar() {
|
||||
String accountId = StpUtil.getLoginIdAsString();
|
||||
UserInfoResponse result = userService.deleteAvatar(accountId);
|
||||
return ApiResponse.ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user