Changes
This commit is contained in:
parent
c7aeaf2b63
commit
15107a23cc
@ -22,7 +22,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Api(tags = "帖子管理接口")
|
||||
@Api(tags = "文章管理接口")
|
||||
@RestController
|
||||
@RequestMapping("/post")
|
||||
public class BmsPostController extends BaseController {
|
||||
@ -32,7 +32,7 @@ public class BmsPostController extends BaseController {
|
||||
@Resource
|
||||
private IUmsUserService umsUserService;
|
||||
|
||||
@ApiOperation(value = "获取帖子列表", notes = "根据标签类型获取帖子列表")
|
||||
@ApiOperation(value = "获取文章列表", notes = "根据标签类型获取文章列表")
|
||||
@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) {
|
||||
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)
|
||||
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);
|
||||
BmsPost topic = iBmsPostService.create(dto, user);
|
||||
return ApiResult.success(topic);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "查看帖子详情", notes = "通过ID查看帖子详情")
|
||||
@ApiOperation(value = "查看文章详情", notes = "通过ID查看文章详情")
|
||||
@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);
|
||||
return ApiResult.success(map);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "获取帖子推荐列表", notes = "通过当前帖子 ID 获取相关的推荐帖子列表")
|
||||
@ApiOperation(value = "获取文章推荐列表", notes = "通过当前文章 ID 获取相关的推荐文章列表")
|
||||
@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);
|
||||
return ApiResult.success(topics);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "更新帖子信息", notes = "用户可以通过该接口修改自己的帖子信息")
|
||||
@ApiOperation(value = "更新文章信息", notes = "用户可以通过该接口修改自己的文章信息")
|
||||
@PostMapping("/update")
|
||||
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);
|
||||
@ -77,9 +77,9 @@ public class BmsPostController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "删除帖子", notes = "用户可以通过该接口删除自己的帖子")
|
||||
@ApiOperation(value = "删除文章", notes = "用户可以通过该接口删除自己的文章")
|
||||
@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);
|
||||
BmsPost byId = iBmsPostService.getById(id);
|
||||
Assert.notNull(byId, "来晚一步,话题已不存在");
|
||||
|
@ -23,7 +23,7 @@ public class BmsSearchController extends BaseController {
|
||||
private IBmsPostService postService;
|
||||
|
||||
@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) {
|
||||
Page<PostVO> results = postService.searchByKey(keyword, new Page<>(pageNum, pageSize));
|
||||
return ApiResult.success(results);
|
||||
|
@ -22,7 +22,7 @@ public class BmsTagController extends BaseController {
|
||||
@Resource
|
||||
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")})
|
||||
@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) {
|
||||
|
@ -18,7 +18,6 @@ public class BmsTipController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private IBmsTipService bmsTipService;
|
||||
|
||||
/**
|
||||
* 获取一条随机的每日一言
|
||||
*
|
||||
|
@ -70,7 +70,7 @@ public class UmsUserController extends BaseController {
|
||||
return ApiResult.success(null, "注销成功");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据用户名获取该用户发布的帖子列表", notes = "通过用户名获取帖子列表")
|
||||
@ApiOperation(value = "根据用户名获取该用户发布的文章列表", notes = "通过用户名获取文章列表")
|
||||
@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) {
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
|
@ -10,12 +10,12 @@ import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import java.util.*;
|
||||
|
||||
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 String SECRET = "ThisIsASecret";//please change to your own encryption secret.
|
||||
public static final String TOKEN_PREFIX = "Bearer ";
|
||||
public static final String HEADER_STRING = "Authorization";
|
||||
public static final String USER_NAME = "userName";
|
||||
private static final Logger logger = LoggerFactory.getLogger(JwtUtil.class);
|
||||
|
||||
public static String generateToken(String userId) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
|
@ -4,11 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yovinchen.forum.model.entity.UmsUser;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*
|
||||
* @author Knox 2020/11/7
|
||||
*/
|
||||
@Repository
|
||||
public interface UmsUserMapper extends BaseMapper<UmsUser> {
|
||||
|
||||
|
@ -15,7 +15,7 @@ import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ApiModel("帖子评论")
|
||||
@ApiModel("文章评论")
|
||||
@TableName("bms_comment")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
@ -15,7 +15,7 @@ import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ApiModel("帖子")
|
||||
@ApiModel("文章")
|
||||
@TableName("bms_post")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
@ -13,7 +13,7 @@ import java.io.Serializable;
|
||||
@Data
|
||||
@ApiModel("小贴士")
|
||||
@NoArgsConstructor
|
||||
@TableName("bms_tip")
|
||||
@TableName("bms_ti45p")
|
||||
public class BmsTip implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -44,7 +44,7 @@ public class UmsUser implements Serializable {
|
||||
@ApiModelProperty("头像url")
|
||||
@Builder.Default
|
||||
@TableField("avatar")
|
||||
private String avatar = "https://s3.ax1x.com/2020/12/01/DfHNo4.jpg";
|
||||
private String avatar = "https://api.multiavatar.com/1.png";
|
||||
|
||||
@ApiModelProperty("邮箱")
|
||||
@TableField("email")
|
||||
|
@ -9,8 +9,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class IBmsTipServiceImpl extends ServiceImpl<BmsTipMapper
|
||||
, BmsTip> implements IBmsTipService {
|
||||
public class IBmsTipServiceImpl extends ServiceImpl<BmsTipMapper, BmsTip> implements IBmsTipService {
|
||||
|
||||
@Override
|
||||
public BmsTip getRandomTip() {
|
||||
|
@ -1,15 +1,12 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
web:
|
||||
domain: http://localhost
|
||||
port: 8383
|
||||
|
||||
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
|
||||
username: doubao
|
||||
password: LfSK4cHRfc2yByfE
|
||||
url: jdbc:mysql://43.143.164.194:3306/doubao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
|
||||
logging:
|
||||
|
@ -1,15 +1,12 @@
|
||||
server:
|
||||
port: 8088
|
||||
|
||||
web:
|
||||
domain: http://localhost
|
||||
port: 8383
|
||||
|
||||
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
|
||||
username: doubao
|
||||
password: LfSK4cHRfc2yByfE
|
||||
url: jdbc:mysql://43.143.164.194:3306/doubao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
|
||||
logging:
|
||||
|
@ -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
|
@ -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
|
@ -1,3 +0,0 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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>
|
@ -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) <= date_add(curdate(), interval 1 day)-->
|
||||
<!-- and date(t.create_time) >= 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>
|
@ -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>
|
@ -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>
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user