feat(admin-backend): add user avatar upload endpoint for admins
This commit is contained in:
@@ -207,6 +207,27 @@ public class UserController {
|
||||
return Result.success("更新成功", userDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员上传指定用户头像
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @param file 头像文件
|
||||
* @return 响应结果
|
||||
*/
|
||||
@Operation(summary = "管理员上传用户头像", description = "管理员上传指定用户头像并更新用户信息,需要管理员权限")
|
||||
@SaCheckRole("admin")
|
||||
@PostMapping("/{id}/upload/avatar")
|
||||
public Result<String> adminUploadUserAvatar(
|
||||
@Parameter(description = "用户ID", example = "1") @PathVariable Long id,
|
||||
@Parameter(description = "头像文件") @RequestParam("file") MultipartFile file) {
|
||||
String avatarPhysicalPath = fileService.uploadImage(file);
|
||||
String avatarUrl = avatarPhysicalPath.replace(System.getProperty("user.dir") + File.separator + "music-houduan", "").replace(File.separator, "/");
|
||||
|
||||
userService.adminUpdateUserAvatar(id, avatarUrl);
|
||||
|
||||
return Result.success("上传成功", avatarUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user