Compare commits
11 Commits
feature-Po
...
3485577874
| Author | SHA1 | Date | |
|---|---|---|---|
| 3485577874 | |||
| dbf303c03d | |||
| 2c4504090c | |||
| ee708724ab | |||
| 17877753d5 | |||
| 8d9f2285e4 | |||
| e5f411e342 | |||
| 80ede2ad2f | |||
| 088e5612d3 | |||
| 2d3ac68886 | |||
| bc3ffac3db |
@@ -21,7 +21,7 @@ public class PostController {
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 上传媒体文件接口
|
||||
* 上传媒体文件接口 like
|
||||
* @param files 媒体文件数组
|
||||
* @return 上传后的文件URL列表
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.bao.dating.controller;
|
||||
|
||||
import com.bao.dating.common.Result;
|
||||
import com.bao.dating.common.ResultCode;
|
||||
import com.bao.dating.pojo.entity.User;
|
||||
import com.bao.dating.service.PostFavoriteService;
|
||||
import com.bao.dating.service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/posts")
|
||||
public class PostFavoriteController {
|
||||
@Autowired
|
||||
private PostFavoriteService postFavoriteService;
|
||||
@PostMapping("/{post_id}/favorites")
|
||||
public Result<Map<String,Long>> addPostFavorite(@PathVariable("post_id")Long postId, User user){
|
||||
if (user == null){
|
||||
return Result.error(ResultCode.PARAM_ERROR);
|
||||
}
|
||||
Long userId = user.getUserId();
|
||||
return postFavoriteService.postFavorite(userId,postId);
|
||||
}
|
||||
@DeleteMapping("/{post_id}/favorites")
|
||||
public Result<?> deletePostFavorite(@PathVariable("post_id")Long postId, User user){
|
||||
if (user == null){
|
||||
return Result.error(ResultCode.PARAM_ERROR);
|
||||
}
|
||||
Long userId = user.getUserId();
|
||||
return postFavoriteService.deletePostFavorite(userId, postId);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,12 @@ public class PostLikeController {
|
||||
@Autowired
|
||||
private PostLikeService postLikeService;
|
||||
|
||||
/**
|
||||
* 点赞接口
|
||||
* @param postId
|
||||
* @param body
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/{postId}/likes")
|
||||
public Result<?> likePost(@PathVariable Long postId, @RequestBody Map<String, Long> body){
|
||||
// 从请求体中取出 user_id
|
||||
@@ -27,6 +33,11 @@ public class PostLikeController {
|
||||
return postLikeService.likePost(postId,userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消点赞接口
|
||||
* @param postId
|
||||
* @param body
|
||||
*/
|
||||
@DeleteMapping("/{postId}/likes")
|
||||
public void unlike(@PathVariable Long postId, @RequestBody Map<String, Long> body){
|
||||
// 从请求体中获取 user_id
|
||||
|
||||
4
src/main/java/com/bao/dating/controller/text.java
Normal file
4
src/main/java/com/bao/dating/controller/text.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.bao.dating.controller;
|
||||
|
||||
public class text {
|
||||
}
|
||||
15
src/main/java/com/bao/dating/mapper/PostFavoriteMapper.java
Normal file
15
src/main/java/com/bao/dating/mapper/PostFavoriteMapper.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.bao.dating.mapper;
|
||||
|
||||
import com.bao.dating.pojo.entity.PostFavorite;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PostFavoriteMapper {
|
||||
//查询当前已收藏所有用户
|
||||
List<Long> selectUserIDByPostID(@Param("postId") Long postId);
|
||||
int addPostFavorite(PostFavorite postFavorite);
|
||||
int deletePostFavorite(@Param("postId") Long postId);
|
||||
}
|
||||
@@ -59,4 +59,34 @@ public interface PostMapper {
|
||||
* @return 影响行数
|
||||
*/
|
||||
int decreaseLikeCount(Long postId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前动态属于哪个用户id
|
||||
* @param postId 动态id
|
||||
* @return 用户id
|
||||
*/
|
||||
Long selectUserIdByPostId(@Param("post_id") Long postId);
|
||||
|
||||
/**
|
||||
* 查询点赞数
|
||||
*
|
||||
* @param postId
|
||||
* @return
|
||||
*/
|
||||
int selectFavoriteCount(Long postId);
|
||||
|
||||
/**
|
||||
* 收藏数+1
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 影响行数
|
||||
*/
|
||||
int increaseFavoriteCount(Long postId);
|
||||
/**
|
||||
* 收藏数-1
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 影响行数
|
||||
*/
|
||||
int decreaseFavoriteCount(Long postId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.bao.dating.service;
|
||||
|
||||
import com.bao.dating.common.Result;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PostFavoriteService {
|
||||
Result<Map<String,Long>> postFavorite(Long userid,Long postId);
|
||||
Result<?> deletePostFavorite(Long userid,Long postId);
|
||||
}
|
||||
@@ -30,6 +30,8 @@ public interface PostService {
|
||||
*/
|
||||
void deletePostById(Long postId);
|
||||
|
||||
void deletePostById(Integer postId);
|
||||
|
||||
/**
|
||||
* 查询动态详情(用于编辑)
|
||||
* @param postId 动态ID
|
||||
@@ -43,4 +45,11 @@ public interface PostService {
|
||||
* @return 修改后的动态对象
|
||||
*/
|
||||
PostEditVO updatePost(Long postId, PostRequestDTO postRequestDTO);
|
||||
|
||||
/**
|
||||
* 查询
|
||||
* @param postId 动态id
|
||||
* @return 用户id
|
||||
*/
|
||||
Long selectUserIdByPostId(Long postId);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.bao.dating.service.impl;
|
||||
|
||||
import com.bao.dating.common.Result;
|
||||
import com.bao.dating.common.ResultCode;
|
||||
import com.bao.dating.mapper.PostFavoriteMapper;
|
||||
import com.bao.dating.mapper.PostMapper;
|
||||
import com.bao.dating.pojo.entity.PostFavorite;
|
||||
import com.bao.dating.service.PostFavoriteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class PostFavoriteServiceImpl implements PostFavoriteService {
|
||||
@Autowired
|
||||
private PostFavoriteMapper postFavoriteMapper;
|
||||
@Autowired
|
||||
private PostMapper postMapper;
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<Map<String, Long>> postFavorite(Long userid, Long postId) {
|
||||
Long userId = postMapper.selectUserIdByPostId(postId);
|
||||
if (userid.equals(userId)){
|
||||
return Result.error(ResultCode.FORBIDDEN,"无法收藏自己发布动态");
|
||||
}
|
||||
List<Long> allUserId = postFavoriteMapper.selectUserIDByPostID(postId);
|
||||
if (allUserId.contains(userid)){
|
||||
return Result.error(ResultCode.FORBIDDEN,"已收藏");
|
||||
}
|
||||
PostFavorite postFavorite = new PostFavorite();
|
||||
postFavorite.setPostId(postId);
|
||||
postFavorite.setUserId(userid);
|
||||
postFavorite.setCreatedAt(LocalDateTime.now());
|
||||
postFavoriteMapper.addPostFavorite(postFavorite);
|
||||
postMapper.increaseFavoriteCount(postId);
|
||||
Long count = (long) postMapper.selectFavoriteCount(postId);
|
||||
Map<String, Long> data = new HashMap<>();
|
||||
data.put("favorite_id",postFavorite.getFavoriteId());
|
||||
data.put("post_id",postId);
|
||||
data.put("user_id",userid);
|
||||
data.put("current_favorites_count",count);
|
||||
return Result.success(ResultCode.SUCCESS_REVIEW,"收藏成功",data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<?> deletePostFavorite(Long userid, Long postId) {
|
||||
List<Long> allUserId = postFavoriteMapper.selectUserIDByPostID(postId);
|
||||
if (! allUserId.contains(userid)){
|
||||
return Result.error(ResultCode.FORBIDDEN,"请先收藏");
|
||||
}
|
||||
postFavoriteMapper.deletePostFavorite(postId);
|
||||
postMapper.decreaseFavoriteCount(postId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -104,8 +104,11 @@ public class PostServiceImpl implements PostService {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("文本审核失败");
|
||||
}
|
||||
// 文本审核结果
|
||||
|
||||
String textSuggestion = (String) textResult.get("suggestion");
|
||||
if ("block".equals(textSuggestion)) {
|
||||
throw new RuntimeException("动态内容违规,禁止发布");
|
||||
}
|
||||
|
||||
// 2. 图片审核(如果有)
|
||||
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
||||
@@ -117,7 +120,7 @@ public class PostServiceImpl implements PostService {
|
||||
}
|
||||
// 图片审核结果
|
||||
String imageSuggestion = (String) imageResult.get("suggestion");
|
||||
|
||||
|
||||
// 根据审核结果设置状态
|
||||
if ("block".equals(textSuggestion) || "block".equals(imageSuggestion)) {
|
||||
// 审核未通过,允许用户修改
|
||||
@@ -142,7 +145,6 @@ public class PostServiceImpl implements PostService {
|
||||
post.setIsPublic(0);
|
||||
}
|
||||
}
|
||||
|
||||
post.setUpdatedAt(LocalDateTime.now());
|
||||
post.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
@@ -151,6 +153,11 @@ public class PostServiceImpl implements PostService {
|
||||
return post;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePostById(Long postId) {
|
||||
postMapper.deletePostById(postId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
*
|
||||
@@ -158,7 +165,7 @@ public class PostServiceImpl implements PostService {
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
@Override
|
||||
public void deletePostById(Long postId) {
|
||||
public void deletePostById(Integer postId) {
|
||||
postMapper.deletePostById(postId);
|
||||
}
|
||||
|
||||
@@ -249,4 +256,15 @@ public class PostServiceImpl implements PostService {
|
||||
return postEditVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据动态ID查询用户ID
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 用户ID
|
||||
*/
|
||||
@Override
|
||||
public Long selectUserIdByPostId(Long postId) {
|
||||
return postMapper.selectUserIdByPostId(postId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,9 +20,9 @@ mybatis:
|
||||
aliyun:
|
||||
oss:
|
||||
endpoint: oss-cn-beijing.aliyuncs.com
|
||||
access-key-id: LTAI5tKo9TpWH1aW6JxWm1Gp
|
||||
access-key-secret: LHk9DdHECKCwIdaIM9fkGgEuowt18W
|
||||
bucket-name: heimato
|
||||
access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
|
||||
access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||
bucket-name: heimatoo
|
||||
accessKeyId: LTAI5t5vpcbCZwweNHEDDDaF
|
||||
secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||
scenes: antispam
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bao.dating.mapper.PostFavoriteMapper">
|
||||
<!--添加动态收藏-->
|
||||
<insert id="addPostFavorite">
|
||||
insert into post_favorite values (null,#{userId},#{postId},#{createdAt})
|
||||
</insert>
|
||||
<!--删除动态收藏-->
|
||||
<delete id="deletePostFavorite">
|
||||
delete from post_favorite where post_id = #{postId}
|
||||
</delete>
|
||||
<!--查询当前已收藏所有用户-->
|
||||
<select id="selectUserIDByPostID" resultType="java.lang.Long">
|
||||
SELECT user_id FROM post_favorite WHERE post_id = #{postId}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -92,10 +92,26 @@
|
||||
<update id="decreaseLikeCount">
|
||||
update dating.post set like_count= like_count - 1 where post.post_id = #{postId}
|
||||
</update>
|
||||
<!--增加收藏数量-->
|
||||
<update id="increaseFavoriteCount">
|
||||
update post set favorite_count = favorite_count + 1 where post_id = #{post_id}
|
||||
</update>
|
||||
<!--减少收藏数量-->
|
||||
<update id="decreaseFavoriteCount">
|
||||
update post set favorite_count = favorite_count - 1 where post_id = #{post_id}
|
||||
</update>
|
||||
|
||||
<!--查询点赞当前数量-->
|
||||
<select id="selectLikeCount" resultType="java.lang.Integer">
|
||||
select dating.post.like_count from dating.post where post.post_id = #{postId}
|
||||
</select>
|
||||
<!--查询当前动态的用户id-->
|
||||
<select id="selectUserIdByPostId" resultType="java.lang.Long">
|
||||
SELECT user_id FROM post WHERE post_id = #{post_id}
|
||||
</select>
|
||||
<!--查询当前收藏数量-->
|
||||
<select id="selectFavoriteCount" resultType="java.lang.Integer">
|
||||
select dating.post.favorite_count from dating.post where post.post_id = #{postId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -31,10 +31,7 @@ public class DatingApplicationTests {
|
||||
public void testUploadAndScanImageFromUrl() {
|
||||
try {
|
||||
// 阿里oss图片url
|
||||
String imageUrl = "https://heimato.oss-cn-beijing.aliyuncs.com/75d067b3-8605-494a-a839-b0a9d32c993a.jpg" +
|
||||
"?x-oss-credential=LTAI5tKo9TpWH1aW6JxWm1Gp%2F20251218%2Fcn-beijing%2Foss%2Faliyun_v4_request" +
|
||||
"&x-oss-date=20251218T164128Z&x-oss-expires=32400&x-oss-signature-version=OSS4-HMAC-SHA256" +
|
||||
"&x-oss-signature=e9c46381a5d33e5c541fe2e838ff3ebeeb5dbc51f792ed31ae992aa0a4109d8a";
|
||||
String imageUrl = "https://heimatoo.oss-cn-beijing.aliyuncs.com/ScreenShot_2025-12-01_135624_491.png?x-oss-credential=LTAI5t5vpcbCZwweNHEDDDaF%2F20251222%2Fcn-beijing%2Foss%2Faliyun_v4_request&x-oss-date=20251222T092951Z&x-oss-expires=32400&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-signature=c06742a4e530c7a095aa4c376c3c88e605dddcd232d0ee07da76988e5ccb7727";
|
||||
|
||||
// 将图片URL添加到列表中进行检测
|
||||
List<String> imageUrls = Arrays.asList(imageUrl);
|
||||
|
||||
Reference in New Issue
Block a user