This commit is contained in:
YoVinchen 2023-06-21 08:19:31 +08:00
parent c7aeaf2b63
commit 15107a23cc
96 changed files with 32 additions and 201 deletions

View File

@ -22,7 +22,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Api(tags = "帖子管理接口") @Api(tags = "文章管理接口")
@RestController @RestController
@RequestMapping("/post") @RequestMapping("/post")
public class BmsPostController extends BaseController { public class BmsPostController extends BaseController {
@ -32,7 +32,7 @@ public class BmsPostController extends BaseController {
@Resource @Resource
private IUmsUserService umsUserService; private IUmsUserService umsUserService;
@ApiOperation(value = "获取帖子列表", notes = "根据标签类型获取帖子列表") @ApiOperation(value = "获取文章列表", notes = "根据标签类型获取文章列表")
@GetMapping("/list") @GetMapping("/list")
public ApiResult<Page<PostVO>> list(@ApiParam(name = "tab", value = "标签类型", defaultValue = "latest") @RequestParam(value = "tab", defaultValue = "latest") String tab, @ApiParam(name = "pageNo", value = "页码", defaultValue = "1") @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @ApiParam(name = "pageSize", value = "每页显示数量", defaultValue = "10") @RequestParam(value = "size", defaultValue = "10") Integer pageSize) { public ApiResult<Page<PostVO>> list(@ApiParam(name = "tab", value = "标签类型", defaultValue = "latest") @RequestParam(value = "tab", defaultValue = "latest") String tab, @ApiParam(name = "pageNo", value = "页码", defaultValue = "1") @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @ApiParam(name = "pageSize", value = "每页显示数量", defaultValue = "10") @RequestParam(value = "size", defaultValue = "10") Integer pageSize) {
Page<PostVO> list = iBmsPostService.getList(new Page<>(pageNo, pageSize), tab); Page<PostVO> list = iBmsPostService.getList(new Page<>(pageNo, pageSize), tab);
@ -40,32 +40,32 @@ public class BmsPostController extends BaseController {
} }
@ApiOperation(value = "创建帖子", notes = "通过传入参数来创建一个新的帖子") @ApiOperation(value = "创建文章", notes = "通过传入参数来创建一个新的文章")
@RequestMapping(value = "/create", method = RequestMethod.POST) @RequestMapping(value = "/create", method = RequestMethod.POST)
public ApiResult<BmsPost> create(@RequestHeader(value = JwtUtil.USER_NAME) String userName, @ApiParam(name = "dto", value = "帖子内容", required = true) @RequestBody CreateTopicDTO dto) { public ApiResult<BmsPost> create(@RequestHeader(value = JwtUtil.USER_NAME) String userName, @ApiParam(name = "dto", value = "文章内容", required = true) @RequestBody CreateTopicDTO dto) {
UmsUser user = umsUserService.getUserByUsername(userName); UmsUser user = umsUserService.getUserByUsername(userName);
BmsPost topic = iBmsPostService.create(dto, user); BmsPost topic = iBmsPostService.create(dto, user);
return ApiResult.success(topic); return ApiResult.success(topic);
} }
@ApiOperation(value = "查看帖子详情", notes = "通过ID查看帖子详情") @ApiOperation(value = "查看文章详情", notes = "通过ID查看文章详情")
@GetMapping() @GetMapping()
public ApiResult<Map<String, Object>> view(@ApiParam(name = "id", value = "帖子ID", required = true) @RequestParam("id") String id) { public ApiResult<Map<String, Object>> view(@ApiParam(name = "id", value = "文章ID", required = true) @RequestParam("id") String id) {
Map<String, Object> map = iBmsPostService.viewTopic(id); Map<String, Object> map = iBmsPostService.viewTopic(id);
return ApiResult.success(map); return ApiResult.success(map);
} }
@ApiOperation(value = "获取帖子推荐列表", notes = "通过当前帖子 ID 获取相关的推荐帖子列表") @ApiOperation(value = "获取文章推荐列表", notes = "通过当前文章 ID 获取相关的推荐文章列表")
@GetMapping("/recommend") @GetMapping("/recommend")
public ApiResult<List<BmsPost>> getRecommend(@ApiParam(name = "id", value = "当前帖子ID", required = true) @RequestParam("topicId") String id) { public ApiResult<List<BmsPost>> getRecommend(@ApiParam(name = "id", value = "当前文章ID", required = true) @RequestParam("topicId") String id) {
List<BmsPost> topics = iBmsPostService.getRecommend(id); List<BmsPost> topics = iBmsPostService.getRecommend(id);
return ApiResult.success(topics); return ApiResult.success(topics);
} }
@ApiOperation(value = "更新帖子信息", notes = "用户可以通过该接口修改自己的帖子信息") @ApiOperation(value = "更新文章信息", notes = "用户可以通过该接口修改自己的文章信息")
@PostMapping("/update") @PostMapping("/update")
public ApiResult<BmsPost> update(@ApiParam(name = "userName", value = "用户名", required = true) @RequestHeader(value = JwtUtil.USER_NAME) String userName, @Valid @RequestBody BmsPost post) { public ApiResult<BmsPost> update(@ApiParam(name = "userName", value = "用户名", required = true) @RequestHeader(value = JwtUtil.USER_NAME) String userName, @Valid @RequestBody BmsPost post) {
UmsUser umsUser = umsUserService.getUserByUsername(userName); UmsUser umsUser = umsUserService.getUserByUsername(userName);
@ -77,9 +77,9 @@ public class BmsPostController extends BaseController {
} }
@ApiOperation(value = "删除帖子", notes = "用户可以通过该接口删除自己的帖子") @ApiOperation(value = "删除文章", notes = "用户可以通过该接口删除自己的文章")
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public ApiResult<String> delete(@ApiParam(name = "userName", value = "用户名", required = true) @RequestHeader(value = JwtUtil.USER_NAME) String userName, @ApiParam(name = "id", value = "帖子ID", required = true) @PathVariable("id") String id) { public ApiResult<String> delete(@ApiParam(name = "userName", value = "用户名", required = true) @RequestHeader(value = JwtUtil.USER_NAME) String userName, @ApiParam(name = "id", value = "文章ID", required = true) @PathVariable("id") String id) {
UmsUser umsUser = umsUserService.getUserByUsername(userName); UmsUser umsUser = umsUserService.getUserByUsername(userName);
BmsPost byId = iBmsPostService.getById(id); BmsPost byId = iBmsPostService.getById(id);
Assert.notNull(byId, "来晚一步,话题已不存在"); Assert.notNull(byId, "来晚一步,话题已不存在");

View File

@ -23,7 +23,7 @@ public class BmsSearchController extends BaseController {
private IBmsPostService postService; private IBmsPostService postService;
@GetMapping @GetMapping
@ApiOperation(value = "根据关键字搜索帖子列表", notes = "根据指定关键字,分页查询帖子列表") @ApiOperation(value = "根据关键字搜索文章列表", notes = "根据指定关键字,分页查询文章列表")
public ApiResult<Page<PostVO>> searchList(@ApiParam(name = "keyword", value = "搜索关键字", required = true) @RequestParam("keyword") String keyword, @ApiParam(name = "pageNum", value = "页码", defaultValue = "1") @RequestParam("pageNum") Integer pageNum, @ApiParam(name = "pageSize", value = "每页显示条数", defaultValue = "10") @RequestParam("pageSize") Integer pageSize) { public ApiResult<Page<PostVO>> searchList(@ApiParam(name = "keyword", value = "搜索关键字", required = true) @RequestParam("keyword") String keyword, @ApiParam(name = "pageNum", value = "页码", defaultValue = "1") @RequestParam("pageNum") Integer pageNum, @ApiParam(name = "pageSize", value = "每页显示条数", defaultValue = "10") @RequestParam("pageSize") Integer pageSize) {
Page<PostVO> results = postService.searchByKey(keyword, new Page<>(pageNum, pageSize)); Page<PostVO> results = postService.searchByKey(keyword, new Page<>(pageNum, pageSize));
return ApiResult.success(results); return ApiResult.success(results);

View File

@ -22,7 +22,7 @@ public class BmsTagController extends BaseController {
@Resource @Resource
private IBmsTagService bmsTagService; private IBmsTagService bmsTagService;
@ApiOperation(value = "根据标签名获取帖子列表", notes = "通过标签名获取帖子列表") @ApiOperation(value = "根据标签名获取文章列表", notes = "通过标签名获取文章列表")
@ApiImplicitParams({@ApiImplicitParam(name = "name", value = "标签名", required = true, dataType = "String", paramType = "path"), @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "Integer", paramType = "query"), @ApiImplicitParam(name = "size", value = "每页大小", defaultValue = "10", dataType = "Integer", paramType = "query")}) @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "标签名", required = true, dataType = "String", paramType = "path"), @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "Integer", paramType = "query"), @ApiImplicitParam(name = "size", value = "每页大小", defaultValue = "10", dataType = "Integer", paramType = "query")})
@GetMapping("/{name}") @GetMapping("/{name}")
public ApiResult<Map<String, Object>> getTopicsByTag(@ApiParam(name = "name", value = "标签名", required = true) @PathVariable("name") String tagName, @ApiParam(name = "page", value = "页码", defaultValue = "1") @RequestParam(value = "page", defaultValue = "1") Integer page, @ApiParam(name = "size", value = "每页大小", defaultValue = "10") @RequestParam(value = "size", defaultValue = "10") Integer size) { public ApiResult<Map<String, Object>> getTopicsByTag(@ApiParam(name = "name", value = "标签名", required = true) @PathVariable("name") String tagName, @ApiParam(name = "page", value = "页码", defaultValue = "1") @RequestParam(value = "page", defaultValue = "1") Integer page, @ApiParam(name = "size", value = "每页大小", defaultValue = "10") @RequestParam(value = "size", defaultValue = "10") Integer size) {

View File

@ -18,7 +18,6 @@ public class BmsTipController extends BaseController {
@Resource @Resource
private IBmsTipService bmsTipService; private IBmsTipService bmsTipService;
/** /**
* 获取一条随机的每日一言 * 获取一条随机的每日一言
* *

View File

@ -70,7 +70,7 @@ public class UmsUserController extends BaseController {
return ApiResult.success(null, "注销成功"); return ApiResult.success(null, "注销成功");
} }
@ApiOperation(value = "根据用户名获取该用户发布的帖子列表", notes = "通过用户名获取帖子列表") @ApiOperation(value = "根据用户名获取该用户发布的文章列表", notes = "通过用户名获取文章列表")
@GetMapping("/{username}") @GetMapping("/{username}")
public ApiResult<Map<String, Object>> getUserByName(@ApiParam(name = "username", value = "用户名", required = true) @PathVariable("username") String username, @ApiParam(name = "pageNo", value = "页码", defaultValue = "1") @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @ApiParam(name = "size", value = "每页大小", defaultValue = "10") @RequestParam(value = "size", defaultValue = "10") Integer size) { public ApiResult<Map<String, Object>> getUserByName(@ApiParam(name = "username", value = "用户名", required = true) @PathVariable("username") String username, @ApiParam(name = "pageNo", value = "页码", defaultValue = "1") @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @ApiParam(name = "size", value = "每页大小", defaultValue = "10") @RequestParam(value = "size", defaultValue = "10") Integer size) {
Map<String, Object> map = new HashMap<>(16); Map<String, Object> map = new HashMap<>(16);

View File

@ -20,9 +20,9 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
try { try {
if(isProtectedUrl(request)) { if (isProtectedUrl(request)) {
// System.out.println(request.getMethod()); // System.out.println(request.getMethod());
if(!request.getMethod().equals("OPTIONS")) if (!request.getMethod().equals("OPTIONS"))
request = JwtUtil.validateTokenAndAddUserIdToHeader(request); request = JwtUtil.validateTokenAndAddUserIdToHeader(request);
} }
} catch (Exception e) { } catch (Exception e) {
@ -45,9 +45,9 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
protectedPaths.add("/relationship/validate/*"); protectedPaths.add("/relationship/validate/*");
boolean bFind = false; boolean bFind = false;
for( String passedPath : protectedPaths ) { for (String passedPath : protectedPaths) {
bFind = pathMatcher.match(passedPath, request.getServletPath()); bFind = pathMatcher.match(passedPath, request.getServletPath());
if( bFind ) { if (bFind) {
break; break;
} }
} }

View File

@ -10,12 +10,12 @@ import javax.servlet.http.HttpServletRequestWrapper;
import java.util.*; import java.util.*;
public class JwtUtil { public class JwtUtil {
private static final Logger logger = LoggerFactory.getLogger(JwtUtil.class);
public static final long EXPIRATION_TIME = 3600_000_000L; // 1000 hour public static final long EXPIRATION_TIME = 3600_000_000L; // 1000 hour
public static final String SECRET = "ThisIsASecret";//please change to your own encryption secret. public static final String SECRET = "ThisIsASecret";//please change to your own encryption secret.
public static final String TOKEN_PREFIX = "Bearer "; public static final String TOKEN_PREFIX = "Bearer ";
public static final String HEADER_STRING = "Authorization"; public static final String HEADER_STRING = "Authorization";
public static final String USER_NAME = "userName"; public static final String USER_NAME = "userName";
private static final Logger logger = LoggerFactory.getLogger(JwtUtil.class);
public static String generateToken(String userId) { public static String generateToken(String userId) {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();

View File

@ -4,11 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yovinchen.forum.model.entity.UmsUser; import com.yovinchen.forum.model.entity.UmsUser;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/**
* 用户
*
* @author Knox 2020/11/7
*/
@Repository @Repository
public interface UmsUserMapper extends BaseMapper<UmsUser> { public interface UmsUserMapper extends BaseMapper<UmsUser> {

View File

@ -15,7 +15,7 @@ import java.util.Date;
@Data @Data
@Builder @Builder
@ApiModel("帖子评论") @ApiModel("文章评论")
@TableName("bms_comment") @TableName("bms_comment")
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor

View File

@ -15,7 +15,7 @@ import java.util.Date;
@Data @Data
@Builder @Builder
@ApiModel("帖子") @ApiModel("文章")
@TableName("bms_post") @TableName("bms_post")
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor

View File

@ -13,7 +13,7 @@ import java.io.Serializable;
@Data @Data
@ApiModel("小贴士") @ApiModel("小贴士")
@NoArgsConstructor @NoArgsConstructor
@TableName("bms_tip") @TableName("bms_ti45p")
public class BmsTip implements Serializable { public class BmsTip implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -44,7 +44,7 @@ public class UmsUser implements Serializable {
@ApiModelProperty("头像url") @ApiModelProperty("头像url")
@Builder.Default @Builder.Default
@TableField("avatar") @TableField("avatar")
private String avatar = "https://s3.ax1x.com/2020/12/01/DfHNo4.jpg"; private String avatar = "https://api.multiavatar.com/1.png";
@ApiModelProperty("邮箱") @ApiModelProperty("邮箱")
@TableField("email") @TableField("email")

View File

@ -9,8 +9,7 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
public class IBmsTipServiceImpl extends ServiceImpl<BmsTipMapper public class IBmsTipServiceImpl extends ServiceImpl<BmsTipMapper, BmsTip> implements IBmsTipService {
, BmsTip> implements IBmsTipService {
@Override @Override
public BmsTip getRandomTip() { public BmsTip getRandomTip() {

View File

@ -1,15 +1,12 @@
server: server:
port: 8080 port: 8383
web:
domain: http://localhost
spring: spring:
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
username: root username: doubao
password: root password: LfSK4cHRfc2yByfE
url: jdbc:mysql://localhost:3306/doubao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8 url: jdbc:mysql://43.143.164.194:3306/doubao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8
type: com.zaxxer.hikari.HikariDataSource type: com.zaxxer.hikari.HikariDataSource
logging: logging:

View File

@ -1,15 +1,12 @@
server: server:
port: 8088 port: 8383
web:
domain: http://localhost
spring: spring:
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
username: root username: doubao
password: 123456 password: LfSK4cHRfc2yByfE
url: jdbc:mysql://localhost:3306/ssm_db?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8 url: jdbc:mysql://43.143.164.194:3306/doubao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8
type: com.zaxxer.hikari.HikariDataSource type: com.zaxxer.hikari.HikariDataSource
logging: logging:

View File

@ -1,18 +0,0 @@
server:
port: 8080
web:
domain: http://localhost
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
url: jdbc:mysql://localhost:3306/doubao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8
type: com.zaxxer.hikari.HikariDataSource
logging:
level:
root: info
com.yovinchen.forum: debug

View File

@ -1,18 +0,0 @@
server:
port: 8088
web:
domain: http://localhost
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/ssm_db?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8
type: com.zaxxer.hikari.HikariDataSource
logging:
level:
root: info
com.yovinchen.forum: info

View File

@ -1,3 +0,0 @@
spring:
profiles:
active: dev

View File

@ -1,20 +0,0 @@
<?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.yovinchen.forum.mapper.BmsCommentMapper">
<resultMap id="topicVO" type="com.yovinchen.forum.model.vo.CommentVO">
<id column="id" property="id"/>
<result column="content" property="content"/>
<result column="user_id" property="userId"/>
<result column="topic_id" property="topicId"/>
<result column="username" property="username"/>
<result column="create_time" property="createTime"/>
</resultMap>
<select id="getCommentsByTopicID" resultMap="topicVO">
select bms_comment.*,ums_user.username
from bms_comment
join ums_user on ums_user.id = bms_comment.user_id
where topic_id = #{topicid}
order by create_time desc
</select>
</mapper>

View File

@ -1,78 +0,0 @@
<?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.yovinchen.forum.mapper.BmsTopicMapper">
<resultMap id="topicVO" type="com.yovinchen.forum.model.vo.PostVO">
<id column="id" property="id"/>
<result column="title" property="title"/>
<result column="user_id" property="userId"/>
<result column="comments" property="comments"/>
<result column="view" property="view"/>
<result column="collects" property="collects"/>
<result column="top" property="top"/>
<result column="essence" property="essence"/>
<result column="create_time" property="createTime"/>
<result column="modify_time" property="modifyTime"/>
<result column="username" property="username"/>
<result column="alias" property="alias"/>
<result column="avatar" property="avatar"/>
</resultMap>
<select id="selectListAndPage" resultMap="topicVO">
SELECT
t.id,t.title,t.user_id,t.comments,
t.view,t.collects,t.top,t.essence,
t.create_time ,t.modify_time ,
u.username,u.alias, u.avatar
FROM bms_post t
LEFT JOIN ums_user u
ON t.user_id = u.id
<!-- <where>-->
<!-- <if test="tab == 'hot'">-->
<!-- date(t.create_time) &lt;= date_add(curdate(), interval 1 day)-->
<!-- and date(t.create_time) &gt;= date_sub(curdate(), interval 7 day)-->
<!-- </if>-->
<!-- </where>-->
<if test="tab != 'hot'">
order by t.create_time desc
</if>
<if test="tab == 'hot'">
order by t.view desc, t.create_time desc
</if>
</select>
<select id="selectRecommend" resultType="com.yovinchen.forum.model.entity.BmsPost">
select *
from bms_post t
where t.id != #{id}
order by rand(), t.view
limit 10
</select>
<select id="searchByKey" resultMap="topicVO">
SELECT t.id,
t.title,
t.user_id,
t.comments,
t.view,
t.collects,
t.top,
t.essence,
t.create_time,
t.modify_time,
u.username,
u.alias,
u.avatar
FROM bms_post t
LEFT JOIN ums_user u
ON t.user_id = u.id
<where>
<if test="keyword!=null">
and t.title like CONCAT('%','${keyword}')
or t.title like CONCAT('${keyword}','%')
or t.title like CONCAT('%','${keyword}','%')
or t.title = #{keyword}
</if>
</where>
order by t.view desc, t.create_time desc
</select>
</mapper>

View File

@ -1,9 +0,0 @@
<?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.yovinchen.forum.mapper.BmsTopicTagMapper">
<select id="getTopicIdsByTagId" resultType="java.lang.String">
SELECT t.topic_id
from bms_post_tag t
where t.tag_id = #{id}
</select>
</mapper>

View File

@ -1,10 +0,0 @@
<?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.yovinchen.forum.mapper.BmsTipMapper">
<select id="getRandomTip" resultType="com.yovinchen.forum.model.entity.BmsTip">
select *
from bms_tip
order by rand()
limit 1
</select>
</mapper>