historyviewUpdate
Change-Id: I1a333931b6c999a5b267a51287d745a369ee58a6
diff --git a/src/main/java/com/example/g8backend/controller/PostController.java b/src/main/java/com/example/g8backend/controller/PostController.java
index d53db64..68e0f95 100644
--- a/src/main/java/com/example/g8backend/controller/PostController.java
+++ b/src/main/java/com/example/g8backend/controller/PostController.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.g8backend.dto.PostCreateDTO;
+import com.example.g8backend.dto.PostHistoryDTO;
import com.example.g8backend.entity.PostView;
import com.example.g8backend.mapper.PostViewMapper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -115,17 +116,15 @@
@RequestParam(required = false) String author) {
return postService.searchPosts(keyword, tags, author);
}
+
@GetMapping("/history")
- public ResponseEntity<List<PostView>> getViewHistory() {
+ public ResponseEntity<List<PostHistoryDTO>> getViewHistory() {
// 获取当前用户ID
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
long userId = (long) authentication.getPrincipal();
- // 查询历史记录(按时间倒序)
- List<PostView> history = postViewMapper.selectList(
- new QueryWrapper<PostView>()
- .eq("user_id", userId)
- .orderByDesc("view_time")
- );
+
+ // 调用Service层
+ List<PostHistoryDTO> history = postService.getViewHistoryWithTitles(userId);
return ResponseEntity.ok(history);
}
@GetMapping("/recommended")
@@ -139,7 +138,6 @@
Page<Post> pageResult = postService.getRecommendedPosts(page, size, userId);
return ResponseEntity.ok(pageResult);
}
- // PostController.java - 新增标签推荐接口
@GetMapping("/recommended-by-tags")
public ResponseEntity<Page<Post>> getRecommendedByTags(
@RequestParam(defaultValue = "1") int page,