修改评论列表

This commit is contained in:
zhao 2024-07-23 19:40:35 +08:00
parent 36fc2d5cd4
commit 81a7a0e5fd
3 changed files with 29 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import net.maku.framework.common.exception.ServerException;
import net.maku.framework.common.utils.PageResult; import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result; import net.maku.framework.common.utils.Result;
import net.maku.maku.convert.TBookCommentConvert; import net.maku.maku.convert.TBookCommentConvert;
import net.maku.maku.dao.TBookCommentDao;
import net.maku.maku.entity.TBookCommentEntity; import net.maku.maku.entity.TBookCommentEntity;
import net.maku.maku.entity.TUserEntity; import net.maku.maku.entity.TUserEntity;
import net.maku.maku.service.TBookCommentService; import net.maku.maku.service.TBookCommentService;
@ -41,6 +42,7 @@ import java.util.List;
public class TBookCommentController { public class TBookCommentController {
private final TBookCommentService tBookCommentService; private final TBookCommentService tBookCommentService;
private final RedisCache redisCache; private final RedisCache redisCache;
private final TBookCommentDao tBookCommentDao;
@PostMapping("/manout") @PostMapping("/manout")
@Operation(summary = "评论") @Operation(summary = "评论")
@ -112,11 +114,17 @@ public class TBookCommentController {
return Result.ok(); return Result.ok();
} }
@GetMapping("/list/{bookId}") @GetMapping("/list")
@Operation(summary = "查看评论列表") @Operation(summary = "查看评论列表")
public Result<List<TBookCommentEntity>> list(@PathVariable Integer bookId){ public List<TBookCommentEntity> list(HttpServletRequest request){
String token = request.getHeader("token");
return Result.ok(tBookCommentService.getByBookId(bookId)); TUserEntity entity = (TUserEntity) redisCache.get(token);
if(ObjectUtils.isNull(entity)){
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
}
TUserEntity tUserEntity = (TUserEntity) redisCache.get(token);
Integer userId=tUserEntity.getId();
return tBookCommentDao.findAll(Long.valueOf(userId));
} }
} }

View File

@ -4,6 +4,8 @@ import net.maku.framework.mybatis.dao.BaseDao;
import net.maku.maku.entity.TBookCommentEntity; import net.maku.maku.entity.TBookCommentEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* *
* *
@ -12,5 +14,5 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface TBookCommentDao extends BaseDao<TBookCommentEntity> { public interface TBookCommentDao extends BaseDao<TBookCommentEntity> {
List<TBookCommentEntity> findAll(Long bookId);
} }

View File

@ -8,9 +8,22 @@
<result property="userId" column="user_id"/> <result property="userId" column="user_id"/>
<result property="bookId" column="book_id"/> <result property="bookId" column="book_id"/>
<result property="comment" column="comment"/> <result property="comment" column="comment"/>
<result property="parentId" column="parent_id"/>
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time"/>
</resultMap> </resultMap>
<select id="findAll" parameterType="map" resultType="map">
SELECT
tb.book_name,
tu.username,
tb.book_cover,
tc.comment
FROM
t_book_comment tc
LEFT JOIN t_book tb ON tc.book_id = tb.id
LEFT JOIN t_user tu ON tc.user_id = tu.id
WHERE
tc.user_id = #{id}
</select>
</mapper> </mapper>