335942189@qq.com 3 days ago
commit fa3b1557f5

@ -93,8 +93,8 @@ public class PostController {
@ApiResponse(responseCode = "200", description = "获取成功"), @ApiResponse(responseCode = "200", description = "获取成功"),
@ApiResponse(responseCode = "500", description = "获取失败,帖子不存在或被删除") @ApiResponse(responseCode = "500", description = "获取失败,帖子不存在或被删除")
}) })
public PostInfoDTO getPostDetail(@RequestParam("id") Long id) { public Result<PostInfoDTO> getPostDetail(@RequestParam("id") Long id) {
return postService.getPostDetail(id); return Result.success(postService.getPostDetail(id));
} }
// 分页查询帖子 // 分页查询帖子

@ -27,6 +27,11 @@ public class PostBasicInfoDTO {
) )
private String title; private String title;
@Schema(
description = "帖子摘要显示帖子内容的前20个字"
)
private String summary;
@Schema( @Schema(
description = "点赞数" description = "点赞数"
) )
@ -43,7 +48,12 @@ public class PostBasicInfoDTO {
private Integer favoriteCount; private Integer favoriteCount;
@Schema( @Schema(
description = "是否点赞,1-已点赞,0-未点赞", description = "帖子浏览数"
)
private Integer viewCount;
@Schema(
description = "是否点赞,1-已点赞0-未点赞",
allowableValues = {"0", "1"}, allowableValues = {"0", "1"},
example = "1", example = "1",
implementation = Boolean.class implementation = Boolean.class

@ -51,6 +51,11 @@ public class PostInfoDTO {
) )
private Integer favoriteCount; private Integer favoriteCount;
@Schema(
description = "帖子浏览数"
)
private Integer viewCount;
@Schema( @Schema(
description = "是否点赞,1-已点赞0-未点赞", description = "是否点赞,1-已点赞0-未点赞",
allowableValues = {"0", "1"}, allowableValues = {"0", "1"},

@ -125,7 +125,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
@Override @Override
public PostInfoDTO getPostDetail(Long id) { public PostInfoDTO getPostDetail(Long id) {
// TODO // TODO 定时任务更新浏览数或消息队列解耦,懒得写了
Post oldPost = getById(id); Post oldPost = getById(id);
oldPost.setViewCount(oldPost.getViewCount() + 1); oldPost.setViewCount(oldPost.getViewCount() + 1);
updateById(oldPost); updateById(oldPost);
@ -147,7 +147,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
postInfoDTO.setIsLike(isLikedPost(post.getId())); postInfoDTO.setIsLike(isLikedPost(post.getId()));
return postInfoDTO; return postInfoDTO;
}, },
60, TimeUnit.MINUTES); 1, TimeUnit.MINUTES);
} }
@Override @Override
@ -191,6 +191,17 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
User user = userMap.getOrDefault(post.getUserId(), new User()); User user = userMap.getOrDefault(post.getUserId(), new User());
postBasicInfoDTO.setUserAvatar(user.getAvatar()); postBasicInfoDTO.setUserAvatar(user.getAvatar());
postBasicInfoDTO.setUserName(user.getUsername()); postBasicInfoDTO.setUserName(user.getUsername());
postBasicInfoDTO.setIsLike(isLikedPost(post.getId()));
String content = post.getContent();
if (content != null) {
content = content.trim();
String summary = content.substring(0, Math.min(content.length(), 15));
postBasicInfoDTO.setSummary(summary);
} else {
postBasicInfoDTO.setSummary("该帖子内容为空哦");
}
if (post.getStatus() == 1) { // 匿名帖子 if (post.getStatus() == 1) { // 匿名帖子
postBasicInfoDTO.setUserName(ANONYMOUS_NAME); postBasicInfoDTO.setUserName(ANONYMOUS_NAME);
postBasicInfoDTO.setUserAvatar(ANONYMOUS_AVATAR); postBasicInfoDTO.setUserAvatar(ANONYMOUS_AVATAR);
@ -250,6 +261,17 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
User user = userMap.getOrDefault(post.getUserId(), new User()); User user = userMap.getOrDefault(post.getUserId(), new User());
postBasicInfoDTO.setUserAvatar(user.getAvatar()); postBasicInfoDTO.setUserAvatar(user.getAvatar());
postBasicInfoDTO.setUserName(user.getUsername()); postBasicInfoDTO.setUserName(user.getUsername());
postBasicInfoDTO.setIsLike(isLikedPost(post.getId()));
String content = post.getContent();
if (content != null) {
content = content.trim();
String summary = content.substring(0, Math.min(content.length(), 15));
postBasicInfoDTO.setSummary(summary);
} else {
postBasicInfoDTO.setSummary("该帖子内容为空哦");
}
if (post.getStatus() == 1) { // 自己的匿名帖子 if (post.getStatus() == 1) { // 自己的匿名帖子
if(!userId.equals(user.getId())){ if(!userId.equals(user.getId())){
continue; continue;

@ -1,36 +1,36 @@
#本地开发环境 #本地开发环境
lj: # lj:
db: # db:
host: localhost # host: localhost
password: 123456 # password: 123456
redis: # redis:
host: localhost # host: localhost
port: 6379 # port: 6379
password: 123456 # password: 123456
rabbitmq: # rabbitmq:
host: localhost # host: localhost
port: 15672 # port: 15672
username: root # username: root
password: 123456 # password: 123456
minio: # minio:
endpoint: http://localhost:9000 # endpoint: http://localhost:9000
accessKey: minioadmin # accessKey: minioadmin
secretKey: minioadmin # secretKey: minioadmin
#lj: lj:
# db: db:
# host: 192.168.59.129 host: 192.168.59.129
# password: Forely123! password: Forely123!
# redis: redis:
# host: 192.168.59.129 host: 192.168.59.129
# port: 6379 port: 6379
# password: Forely123! password: Forely123!
# rabbitmq: rabbitmq:
# host: 192.168.59.129 host: 192.168.59.129
# port: 5672 port: 5672
# username: admin username: admin
# password: Forely123! password: Forely123!
# minio: minio:
# endpoint: http://192.168.59.129:9000 endpoint: http://192.168.59.129:9000
# accessKey: forely accessKey: forely
# secretKey: Forely123! secretKey: Forely123!

@ -1,36 +1,36 @@
#本地开发环境 #本地开发环境
lj: # lj:
db: # db:
host: localhost # host: localhost
password: 123456 # password: 123456
redis: # redis:
host: localhost # host: localhost
port: 6379 # port: 6379
password: 123456 # password: 123456
rabbitmq: # rabbitmq:
host: localhost # host: localhost
port: 15672 # port: 15672
username: root # username: root
password: 123456 # password: 123456
minio: # minio:
endpoint: http://localhost:9000 # endpoint: http://localhost:9000
accessKey: minioadmin # accessKey: minioadmin
secretKey: minioadmin # secretKey: minioadmin
#lj: lj:
# db: db:
# host: 192.168.59.129 host: 192.168.59.129
# password: Forely123! password: Forely123!
# redis: redis:
# host: 192.168.59.129 host: 192.168.59.129
# port: 6379 port: 6379
# password: Forely123! password: Forely123!
# rabbitmq: rabbitmq:
# host: 192.168.59.129 host: 192.168.59.129
# port: 5672 port: 5672
# username: admin username: admin
# password: Forely123! password: Forely123!
# minio: minio:
# endpoint: http://192.168.59.129:9000 endpoint: http://192.168.59.129:9000
# accessKey: forely accessKey: forely
# secretKey: Forely123! secretKey: Forely123!

Loading…
Cancel
Save