Oss上传文件(有bug)
This commit is contained in:
@@ -7,6 +7,7 @@ import com.bao.dating.pojo.entity.Post;
|
||||
import com.bao.dating.service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/posts")
|
||||
@@ -16,9 +17,9 @@ public class PostController {
|
||||
private PostService postService;
|
||||
|
||||
@PostMapping
|
||||
public Result<Post> createPost(Post post) {
|
||||
public Result<Post> createPost(@RequestBody Post post, MultipartFile file) {
|
||||
// 调用 Service 层处理发布动态业务逻辑
|
||||
Post result = postService.createPost(post);
|
||||
return Result.success(ResultCode.SUCCESS_REVIEW,"动态发布成功,等待审核。",result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,9 @@ import java.util.List;
|
||||
@Data
|
||||
public class Post {
|
||||
|
||||
private Long postId;
|
||||
private Integer postId;
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private String content;
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class PostFavorite {
|
||||
|
||||
private Long favoriteId;
|
||||
private Integer favoriteId;
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private Long postId;
|
||||
private Integer postId;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
@Data
|
||||
public class PostLike {
|
||||
private Long likeId;
|
||||
private Integer likeId;
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private Long postId;
|
||||
private Integer postId;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class User {
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private String userName;
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ public class PostServiceImpl implements PostService {
|
||||
|
||||
@Override
|
||||
public Post createPost(Post post) {
|
||||
// 检查并确保userId不为空,如果为空则设置默认值
|
||||
if (post.getUserId() == null) {
|
||||
post.setUserId(1); // 设置默认用户ID为1
|
||||
}
|
||||
|
||||
// 处理图片和视频上传到 OSS
|
||||
List<String> mediaOssKeys = new ArrayList<>();
|
||||
|
||||
@@ -62,4 +67,4 @@ public class PostServiceImpl implements PostService {
|
||||
postMapper.insert(post);
|
||||
return post;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user