fix GET /user/purchase
Change-Id: I09ae5c51e446a6cab135ab4552e5a0726bc0f629
diff --git a/src/main/java/com/g9/g9backend/controller/UserController.java b/src/main/java/com/g9/g9backend/controller/UserController.java
index 49dbd21..aa05ff7 100644
--- a/src/main/java/com/g9/g9backend/controller/UserController.java
+++ b/src/main/java/com/g9/g9backend/controller/UserController.java
@@ -46,7 +46,15 @@
private final ThreadService threadService;
- public UserController(UserService userService, InvitationService invitationService, SubscriptionService subscriptionService, SearchHistoryService searchHistoryService, RewardService rewardService, UserCollectionService userCollectionService, UserUploadService userUploadService, UserPurchaseService userPurchaseService, ResourceService resourceService, ThreadService threadService) {
+ private final GameplayService gameplayService;
+
+ private final ResourceVersionService resourceVersionService;
+
+ private final GameVersionService gameVersionService;
+
+ private final TorrentRecordService torrentRecordService;
+
+ public UserController(UserService userService, InvitationService invitationService, SubscriptionService subscriptionService, SearchHistoryService searchHistoryService, RewardService rewardService, UserCollectionService userCollectionService, UserUploadService userUploadService, UserPurchaseService userPurchaseService, ResourceService resourceService, ThreadService threadService, GameplayService gameplayService, ResourceVersionService resourceVersionService, GameVersionService gameVersionService, TorrentRecordService torrentRecordService) {
this.userService = userService;
this.invitationService = invitationService;
this.subscriptionService = subscriptionService;
@@ -57,6 +65,10 @@
this.userPurchaseService = userPurchaseService;
this.resourceService = resourceService;
this.threadService = threadService;
+ this.gameplayService = gameplayService;
+ this.resourceVersionService = resourceVersionService;
+ this.gameVersionService = gameVersionService;
+ this.torrentRecordService = torrentRecordService;
}
@@ -364,7 +376,7 @@
* @return 获取用户购买资源结果
*/
@GetMapping("/purchase")
- public ResponseEntity<GetUserResourceListDTO> getUserPurchase(@RequestParam int userId, @RequestParam int pageNumber, @RequestParam int rows) {
+ public ResponseEntity<GetUserPurchaseDTO> getUserPurchase(@RequestParam int userId, @RequestParam int pageNumber, @RequestParam int rows) {
IPage<UserPurchase> page = new Page<>(pageNumber, rows);
QueryWrapper<UserPurchase> userPurchaseQuery = new QueryWrapper<>();
userPurchaseQuery.eq("user_id", userId);
@@ -375,13 +387,46 @@
Resource resource = resourceService.getById(userPurchase.getResourceId());
purchaseList.add(resource);
}
+ List<Resource> resources = purchaseList;
+ List<List<Gameplay>> gameplays = new ArrayList<>();
+ List<List<ResourceVersion>> resourceVersions = new ArrayList<>();
+ List<List<List<GameVersion>>> gameVersion = new ArrayList<>();
+ List<List<List<TorrentRecord>>> torrentRecord = new ArrayList<>();
+
+ for (Resource resource : purchaseList) {
+ int resourceId = resource.getResourceId();
+ // 获取Gameplay列表
+ List<Gameplay> gameplayList = gameplayService.list(new QueryWrapper<Gameplay>().eq("resource_id", resourceId));
+
+ // 获取ResourceVersion列表
+ List<ResourceVersion> resourceVersionList = resourceVersionService.list(new QueryWrapper<ResourceVersion>().eq("resource_id", resourceId));
+
+ // 获取GameVersion二维列表
+ List<List<GameVersion>> gameVersionLists = new ArrayList<>();
+ for (ResourceVersion resourceVersion : resourceVersionList) {
+ List<GameVersion> gameVersionList = gameVersionService.list(new QueryWrapper<GameVersion>().eq("resource_version_id", resourceVersion.getResourceVersionId()));
+ gameVersionLists.add(gameVersionList);
+ }
+
+ // 获取TorrentRecord二维列表
+ List<List<TorrentRecord>> torrentRecordLists = new ArrayList<>();
+ for (ResourceVersion resourceVersion : resourceVersionList) {
+ List<TorrentRecord> torrentRecordList = torrentRecordService.list(new QueryWrapper<TorrentRecord>().eq("resource_version_id", resourceVersion.getResourceVersionId()));
+ torrentRecordLists.add(torrentRecordList);
+ }
+
+ gameplays.add(gameplayList);
+ resourceVersions.add(resourceVersionList);
+ gameVersion.add(gameVersionLists);
+ torrentRecord.add(torrentRecordLists);
+ }
long total = userPurchasePage.getTotal();
long pages = userPurchasePage.getPages();
long current = userPurchasePage.getCurrent();
long size = userPurchasePage.getSize();
- GetUserResourceListDTO getUserResourceListDTO = new GetUserResourceListDTO(purchaseList, total, pages, current, size);
- return ResponseEntity.ok(getUserResourceListDTO);
+ GetUserPurchaseDTO getUserPurchaseDTO = new GetUserPurchaseDTO(resources, gameplays, resourceVersions, gameVersion, torrentRecord, total, pages, current, size);
+ return ResponseEntity.ok(getUserPurchaseDTO);
}
/**