Compare commits
8 Commits
feature-Po
...
2cb8ae5c3c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cb8ae5c3c | ||
|
|
7abd6fe27d | ||
|
|
dfc9508827 | ||
|
|
4c70bd3c6f | ||
|
|
d3c069967e | ||
| 4a2aff888a | |||
| 0b0959fa80 | |||
|
|
4401a8a44a |
@@ -25,9 +25,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
// 忽略的接口
|
// 忽略的接口
|
||||||
.excludePathPatterns(
|
.excludePathPatterns(
|
||||||
"/user/login",
|
"/user/login"
|
||||||
"/user/userRegister"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class PostController {
|
|||||||
* @param postDTO 动态信息
|
* @param postDTO 动态信息
|
||||||
* @return 发布的动态对象
|
* @return 发布的动态对象
|
||||||
*/
|
*/
|
||||||
@PostMapping(consumes = "application/json")
|
@PostMapping( "/createPost")
|
||||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
|
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
|
||||||
// 调用 Service 层处理发布动态业务逻辑
|
// 调用 Service 层处理发布动态业务逻辑
|
||||||
Post result = postService.createPost(postDTO);
|
Post result = postService.createPost(postDTO);
|
||||||
@@ -49,8 +49,8 @@ public class PostController {
|
|||||||
* @param postIds 动态ID
|
* @param postIds 动态ID
|
||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
*/
|
*/
|
||||||
@DeleteMapping
|
@PostMapping("/deletePost")
|
||||||
public Result<String> deleteById(@RequestParam List<Long> postIds){
|
public Result<String> deleteById(@RequestBody List<Long> postIds){
|
||||||
int deletedCount = postService.deletePostById(postIds);
|
int deletedCount = postService.deletePostById(postIds);
|
||||||
return Result.success(ResultCode.SUCCESS_DELETE, deletedCount > 0 ? "成功删除" : "删除失败,该动态不存在", null);
|
return Result.success(ResultCode.SUCCESS_DELETE, deletedCount > 0 ? "成功删除" : "删除失败,该动态不存在", null);
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ public class PostController {
|
|||||||
* @param postId 动态ID
|
* @param postId 动态ID
|
||||||
* @return 动态对象
|
* @return 动态对象
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{postId}")
|
@PostMapping("/{postId}")
|
||||||
public Result<PostEditVO> getPostById(@PathVariable Long postId) {
|
public Result<PostEditVO> getPostById(@PathVariable Long postId) {
|
||||||
PostEditVO postEditVO = postService.getPostForEdit(postId);
|
PostEditVO postEditVO = postService.getPostForEdit(postId);
|
||||||
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
|
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
|
||||||
@@ -72,7 +72,7 @@ public class PostController {
|
|||||||
* @param postRequestDTO 动态信息
|
* @param postRequestDTO 动态信息
|
||||||
* @return 更新后的动态对象
|
* @return 更新后的动态对象
|
||||||
*/
|
*/
|
||||||
@PutMapping("/{postId}")
|
@PostMapping("/{postId}/updatePost")
|
||||||
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
|
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
|
||||||
PostEditVO result = postService.updatePost(postId, postRequestDTO);
|
PostEditVO result = postService.updatePost(postId, postRequestDTO);
|
||||||
return Result.success(ResultCode.SUCCESS_REVIEW, "动态更新成功", result);
|
return Result.success(ResultCode.SUCCESS_REVIEW, "动态更新成功", result);
|
||||||
|
|||||||
@@ -2,15 +2,12 @@ package com.bao.dating.controller;
|
|||||||
|
|
||||||
import com.bao.dating.common.Result;
|
import com.bao.dating.common.Result;
|
||||||
import com.bao.dating.common.ResultCode;
|
import com.bao.dating.common.ResultCode;
|
||||||
import com.bao.dating.pojo.entity.Post;
|
|
||||||
import com.bao.dating.pojo.entity.PostFavorite;
|
|
||||||
import com.bao.dating.pojo.entity.User;
|
import com.bao.dating.pojo.entity.User;
|
||||||
import com.bao.dating.service.PostFavoriteService;
|
import com.bao.dating.service.PostFavoriteService;
|
||||||
import com.bao.dating.service.PostService;
|
import com.bao.dating.service.PostService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -34,11 +31,4 @@ public class PostFavoriteController {
|
|||||||
Long userId = user.getUserId();
|
Long userId = user.getUserId();
|
||||||
return postFavoriteService.deletePostFavorite(userId, postId);
|
return postFavoriteService.deletePostFavorite(userId, postId);
|
||||||
}
|
}
|
||||||
@GetMapping("/{user_id}/favorites")
|
|
||||||
public Result<List<Post>> getFavorites(@PathVariable("user_id")Long postId){
|
|
||||||
if (postId == null){
|
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
}
|
|
||||||
return postFavoriteService.getAllFavoritePost(postId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,25 +24,4 @@ public class UserController {
|
|||||||
UserLoginVO userloginVO = userService.userLogin(userLoginDTO);
|
UserLoginVO userloginVO = userService.userLogin(userLoginDTO);
|
||||||
return Result.success(ResultCode.SUCCESS, "登录成功", userloginVO);
|
return Result.success(ResultCode.SUCCESS, "登录成功", userloginVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户注册
|
|
||||||
* @param userAccount 用户名称
|
|
||||||
* @param userPassword 用户密码
|
|
||||||
* @return 用户id
|
|
||||||
*/
|
|
||||||
@PostMapping("/userRegister")
|
|
||||||
public Result userRegister(String userAccount, String userPassword){
|
|
||||||
long result = userService.userRegister(userAccount, userPassword);
|
|
||||||
if (result == -1){
|
|
||||||
return Result.error(ResultCode.SYSTEM_ERROR);
|
|
||||||
}
|
|
||||||
if (result==-2){
|
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
}
|
|
||||||
if (result == -3){
|
|
||||||
return Result.error(ResultCode.FAIL,"用户名称相同");
|
|
||||||
}
|
|
||||||
return Result.success(ResultCode.SUCCESS,"注册成功",result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.bao.dating.mapper;
|
package com.bao.dating.mapper;
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.Post;
|
|
||||||
import com.bao.dating.pojo.entity.PostFavorite;
|
import com.bao.dating.pojo.entity.PostFavorite;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
@@ -13,5 +12,4 @@ public interface PostFavoriteMapper {
|
|||||||
List<Long> selectUserIDByPostID(@Param("postId") Long postId);
|
List<Long> selectUserIDByPostID(@Param("postId") Long postId);
|
||||||
int addPostFavorite(PostFavorite postFavorite);
|
int addPostFavorite(PostFavorite postFavorite);
|
||||||
int deletePostFavorite(@Param("postId") Long postId);
|
int deletePostFavorite(@Param("postId") Long postId);
|
||||||
List<Post> getAllPost(@Param("userId") Long userId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,4 @@ public interface UserMapper {
|
|||||||
* @return 用户
|
* @return 用户
|
||||||
*/
|
*/
|
||||||
User getByUsername(String username);
|
User getByUsername(String username);
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加用户
|
|
||||||
* @param user 用户对象
|
|
||||||
* @return 受影响行数
|
|
||||||
*/
|
|
||||||
Long insertUser(User user);
|
|
||||||
long getMaxUserId();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.bao.dating.service;
|
package com.bao.dating.service;
|
||||||
|
|
||||||
import com.bao.dating.common.Result;
|
import com.bao.dating.common.Result;
|
||||||
import com.bao.dating.pojo.entity.Post;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface PostFavoriteService {
|
public interface PostFavoriteService {
|
||||||
Result<Map<String,Long>> postFavorite(Long userid,Long postId);
|
Result<Map<String,Long>> postFavorite(Long userid,Long postId);
|
||||||
Result<?> deletePostFavorite(Long userid,Long postId);
|
Result<?> deletePostFavorite(Long userid,Long postId);
|
||||||
Result<List<Post>> getAllFavoritePost(Long userId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,4 @@ public interface UserService {
|
|||||||
* @return 登录结果
|
* @return 登录结果
|
||||||
*/
|
*/
|
||||||
UserLoginVO userLogin(UserLoginDTO userLoginDTO);
|
UserLoginVO userLogin(UserLoginDTO userLoginDTO);
|
||||||
long userRegister(String userAccount, String userPassword);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.bao.dating.common.Result;
|
|||||||
import com.bao.dating.common.ResultCode;
|
import com.bao.dating.common.ResultCode;
|
||||||
import com.bao.dating.mapper.PostFavoriteMapper;
|
import com.bao.dating.mapper.PostFavoriteMapper;
|
||||||
import com.bao.dating.mapper.PostMapper;
|
import com.bao.dating.mapper.PostMapper;
|
||||||
import com.bao.dating.pojo.entity.Post;
|
|
||||||
import com.bao.dating.pojo.entity.PostFavorite;
|
import com.bao.dating.pojo.entity.PostFavorite;
|
||||||
import com.bao.dating.service.PostFavoriteService;
|
import com.bao.dating.service.PostFavoriteService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -59,10 +58,4 @@ public class PostFavoriteServiceImpl implements PostFavoriteService {
|
|||||||
postMapper.decreaseFavoriteCount(postId);
|
postMapper.decreaseFavoriteCount(postId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<List<Post>> getAllFavoritePost(Long userId) {
|
|
||||||
List<Post> result = postFavoriteMapper.getAllPost(userId);
|
|
||||||
return Result.success(ResultCode.SUCCESS,"查询成功",result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,9 +225,8 @@ public class PostServiceImpl implements PostService {
|
|||||||
throw new RuntimeException("无权限修改此动态");
|
throw new RuntimeException("无权限修改此动态");
|
||||||
}
|
}
|
||||||
post.setContent(postRequestDTO.getContent());
|
post.setContent(postRequestDTO.getContent());
|
||||||
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
// 如果请求中的mediaOssKeys不为null(即使是空列表),则更新为新值
|
||||||
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
|
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
|
||||||
}
|
|
||||||
|
|
||||||
// 1. 文本内容审核
|
// 1. 文本内容审核
|
||||||
Map textResult;
|
Map textResult;
|
||||||
@@ -239,11 +238,11 @@ public class PostServiceImpl implements PostService {
|
|||||||
// 文本审核结果
|
// 文本审核结果
|
||||||
String textSuggestion = (String) textResult.get("suggestion");
|
String textSuggestion = (String) textResult.get("suggestion");
|
||||||
|
|
||||||
// 2. 图片审核(如果有)
|
// 2. 图片审核(如果有媒体文件)
|
||||||
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
if (post.getMediaOssKeys() != null && !post.getMediaOssKeys().isEmpty()) {
|
||||||
Map imageResult;
|
Map imageResult;
|
||||||
try {
|
try {
|
||||||
imageResult = greenImageScan.imageScan(postRequestDTO.getMediaOssKeys());
|
imageResult = greenImageScan.imageScan(post.getMediaOssKeys());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import com.bao.dating.util.MD5Util;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
@@ -47,38 +45,4 @@ public class UserServiceImpl implements UserService {
|
|||||||
userLoginVO.setToken(token);
|
userLoginVO.setToken(token);
|
||||||
return userLoginVO;
|
return userLoginVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户注册
|
|
||||||
* @param userAccount 账户名称
|
|
||||||
* @param userPassword 密码
|
|
||||||
* @return 用户id
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public long userRegister(String userAccount, String userPassword) {
|
|
||||||
//验证非空
|
|
||||||
if (userAccount.isEmpty() ||userPassword.isEmpty()){
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
//校验账户不能重复
|
|
||||||
User resultUser = userMapper.getByUsername(userAccount);
|
|
||||||
if (resultUser!=null){
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
//对密码进行加密
|
|
||||||
String encryptPassword = MD5Util.encryptWithSalt(userPassword, "yujian");
|
|
||||||
long maxUserId = userMapper.getMaxUserId();
|
|
||||||
User user = new User();
|
|
||||||
user.setUserId(maxUserId+1);
|
|
||||||
user.setUserName(userAccount);
|
|
||||||
user.setSalt("yujian");
|
|
||||||
user.setPasswordHash(encryptPassword);
|
|
||||||
user.setCreatedAt(LocalDateTime.now());
|
|
||||||
user.setUpdatedAt(LocalDateTime.now());
|
|
||||||
Long result = userMapper.insertUser(user);
|
|
||||||
if (result < 0){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return user.getUserId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,4 @@
|
|||||||
<select id="selectUserIDByPostID" resultType="java.lang.Long">
|
<select id="selectUserIDByPostID" resultType="java.lang.Long">
|
||||||
SELECT user_id FROM post_favorite WHERE post_id = #{postId}
|
SELECT user_id FROM post_favorite WHERE post_id = #{postId}
|
||||||
</select>
|
</select>
|
||||||
<!--查询用户收藏的所有动态-->
|
|
||||||
<select id="getAllPost" resultType="com.bao.dating.pojo.entity.Post">
|
|
||||||
select * from post where post_id in (select post_id from post_favorite where user_id=#{userId})
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -3,15 +3,9 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
<mapper namespace="com.bao.dating.mapper.UserMapper">
|
<mapper namespace="com.bao.dating.mapper.UserMapper">
|
||||||
<insert id="insertUser" useGeneratedKeys="true" parameterType="com.bao.dating.pojo.entity.User">
|
|
||||||
insert into user(user_id,user_name,salt,password_hash,created_at,updated_at) values (#{userId},#{userName},#{salt},#{passwordHash},#{createdAt},#{updatedAt})
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
|
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
|
||||||
SELECT * FROM user WHERE user_name = #{userName}
|
SELECT * FROM user WHERE user_name = #{userName}
|
||||||
</select>
|
</select>
|
||||||
<select id="getMaxUserId" resultType="java.lang.Long">
|
|
||||||
SELECT IFNULL(MAX(user_id), 0) AS max_id FROM user;
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user