Compare commits
5 Commits
feature-Po
...
4c70bd3c6f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c70bd3c6f | ||
|
|
d3c069967e | ||
| 4a2aff888a | |||
| 0b0959fa80 | |||
|
|
4401a8a44a |
@@ -25,9 +25,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
// 忽略的接口
|
// 忽略的接口
|
||||||
.excludePathPatterns(
|
.excludePathPatterns(
|
||||||
"/user/login",
|
"/user/login"
|
||||||
"/user/userRegister"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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