From 554bb95837bebf4d4d0c510651cac1d2ca156afa Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Fri, 15 Dec 2023 15:28:52 +0800 Subject: [PATCH] refactor the share code --- .../com/dl/officialsite/sharing/SharingController.java | 10 +++++----- .../com/dl/officialsite/sharing/SharingRepository.java | 8 ++++---- .../com/dl/officialsite/sharing/SharingService.java | 6 +++--- .../sharing/model/req/InitSharingRewardsReq.java | 4 ---- .../sharing/reward/DefaultRewardServiceImpl.java | 2 -- .../dl/officialsite/sharing/reward/IRewardService.java | 1 - .../sharing/reward/InitSharingRewardsReq.java | 4 ++++ .../req => reward}/PreCheckSharingRewardReq.java | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 src/main/java/com/dl/officialsite/sharing/model/req/InitSharingRewardsReq.java create mode 100644 src/main/java/com/dl/officialsite/sharing/reward/InitSharingRewardsReq.java rename src/main/java/com/dl/officialsite/sharing/{model/req => reward}/PreCheckSharingRewardReq.java (59%) diff --git a/src/main/java/com/dl/officialsite/sharing/SharingController.java b/src/main/java/com/dl/officialsite/sharing/SharingController.java index 23661e19..ffd93003 100644 --- a/src/main/java/com/dl/officialsite/sharing/SharingController.java +++ b/src/main/java/com/dl/officialsite/sharing/SharingController.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*; @RestController -@RequestMapping("share/usershare") +@RequestMapping("/share") @Slf4j public class SharingController { @@ -66,7 +66,7 @@ public BaseResponse loadSharing(@RequestParam(value = "pageNo",defaultValue = "1 * @param shareId * @return */ - @GetMapping("queryByShareId") + @GetMapping("query") public BaseResponse querySharing(@RequestParam("shareId") long shareId){ return BaseResponse.successWithData(this.sharingService.querySharing(shareId)); } @@ -74,10 +74,10 @@ public BaseResponse querySharing(@RequestParam("shareId") long shareId){ /** * 查看用户的分享 */ - @GetMapping("byUser") - public BaseResponse loadSharingByUser(@RequestParam("memberId") long memberId, + @GetMapping("user") + public BaseResponse loadSharingByUser(@RequestParam("memberAddress") String memberAddress, @RequestParam(value = "pageNo",defaultValue = "1") int pageNo, @RequestParam(value = "pageSize",defaultValue = "20") int pageSize) { - return BaseResponse.successWithData(this.sharingService.loadSharingByUser(memberId, pageNo, pageSize)); + return BaseResponse.successWithData(this.sharingService.loadSharingByUser(memberAddress, pageNo, pageSize)); } } diff --git a/src/main/java/com/dl/officialsite/sharing/SharingRepository.java b/src/main/java/com/dl/officialsite/sharing/SharingRepository.java index b8fe29b8..cd5d5b23 100644 --- a/src/main/java/com/dl/officialsite/sharing/SharingRepository.java +++ b/src/main/java/com/dl/officialsite/sharing/SharingRepository.java @@ -15,11 +15,11 @@ public interface SharingRepository extends JpaRepository, JpaSpecif @Query(value = "select count(*) from share", nativeQuery = true) int loadAllCount(); - @Query(value = "select * from share where member_id = :memberId limit :offset, :limit", nativeQuery = true) - List findAllSharesByUidPaged(@Param("memberId") long memberId, @Param("offset") int offset, @Param("limit") int limit); + @Query(value = "select * from share where member_address = :memberAddress limit :offset, :limit", nativeQuery = true) + List findAllSharesByUidPaged(@Param("memberAddress") String memberAddress, @Param("offset") int offset, @Param("limit") int limit); - @Query(value = "select count(*) from share where member_id = :memberId", nativeQuery = true) - int loadCountByUid(@Param("memberId") long memberId); + @Query(value = "select count(*) from share where member_address = :memberAddress", nativeQuery = true) + int loadCountByUid(@Param("memberAddress") String memberAddress); } diff --git a/src/main/java/com/dl/officialsite/sharing/SharingService.java b/src/main/java/com/dl/officialsite/sharing/SharingService.java index 7125699a..5184455e 100644 --- a/src/main/java/com/dl/officialsite/sharing/SharingService.java +++ b/src/main/java/com/dl/officialsite/sharing/SharingService.java @@ -117,11 +117,11 @@ public Share querySharing(long shareId) { } - public PagedList loadSharingByUser(long memberId, int pageNo, int pageSize) { + public PagedList loadSharingByUser(String memberAddress, int pageNo, int pageSize) { int offset = (pageNo - 1)*pageSize; - int totalCount = this.sharingRepository.loadCountByUid(memberId); + int totalCount = this.sharingRepository.loadCountByUid(memberAddress); int totalPages =(totalCount + pageSize - 1) / pageSize; - List items = this.sharingRepository.findAllSharesByUidPaged(memberId, offset, pageSize); + List items = this.sharingRepository.findAllSharesByUidPaged(memberAddress, offset, pageSize); // SharingByUserResp resp = new SharingByUserResp(); PagedList resp = new PagedList(items ,new Pagination(totalCount, totalPages, pageNo, items.size(), pageNo < totalPages)); diff --git a/src/main/java/com/dl/officialsite/sharing/model/req/InitSharingRewardsReq.java b/src/main/java/com/dl/officialsite/sharing/model/req/InitSharingRewardsReq.java deleted file mode 100644 index c20978b4..00000000 --- a/src/main/java/com/dl/officialsite/sharing/model/req/InitSharingRewardsReq.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.dl.officialsite.sharing.model.req; - -public class InitSharingRewardsReq { -} diff --git a/src/main/java/com/dl/officialsite/sharing/reward/DefaultRewardServiceImpl.java b/src/main/java/com/dl/officialsite/sharing/reward/DefaultRewardServiceImpl.java index b6eda460..6f2e2cda 100644 --- a/src/main/java/com/dl/officialsite/sharing/reward/DefaultRewardServiceImpl.java +++ b/src/main/java/com/dl/officialsite/sharing/reward/DefaultRewardServiceImpl.java @@ -1,10 +1,8 @@ package com.dl.officialsite.sharing.reward; -import com.dl.officialsite.sharing.model.req.InitSharingRewardsReq; import com.dl.officialsite.sharing.model.resp.ClaimSharingRewardResp; import com.dl.officialsite.sharing.model.resp.PreCheckSharingRewardResp; import com.dl.officialsite.sharing.model.resp.PrepareSharingRewardsResp; -import com.dl.officialsite.sharing.reward.IRewardService; import org.springframework.stereotype.Service; @Service diff --git a/src/main/java/com/dl/officialsite/sharing/reward/IRewardService.java b/src/main/java/com/dl/officialsite/sharing/reward/IRewardService.java index 3927f2a7..c6b0b201 100644 --- a/src/main/java/com/dl/officialsite/sharing/reward/IRewardService.java +++ b/src/main/java/com/dl/officialsite/sharing/reward/IRewardService.java @@ -1,6 +1,5 @@ package com.dl.officialsite.sharing.reward; -import com.dl.officialsite.sharing.model.req.InitSharingRewardsReq; import com.dl.officialsite.sharing.model.resp.ClaimSharingRewardResp; import com.dl.officialsite.sharing.model.resp.PreCheckSharingRewardResp; import com.dl.officialsite.sharing.model.resp.PrepareSharingRewardsResp; diff --git a/src/main/java/com/dl/officialsite/sharing/reward/InitSharingRewardsReq.java b/src/main/java/com/dl/officialsite/sharing/reward/InitSharingRewardsReq.java new file mode 100644 index 00000000..78d25987 --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/reward/InitSharingRewardsReq.java @@ -0,0 +1,4 @@ +package com.dl.officialsite.sharing.reward; + +public class InitSharingRewardsReq { +} diff --git a/src/main/java/com/dl/officialsite/sharing/model/req/PreCheckSharingRewardReq.java b/src/main/java/com/dl/officialsite/sharing/reward/PreCheckSharingRewardReq.java similarity index 59% rename from src/main/java/com/dl/officialsite/sharing/model/req/PreCheckSharingRewardReq.java rename to src/main/java/com/dl/officialsite/sharing/reward/PreCheckSharingRewardReq.java index d6c4d954..75cd13f9 100644 --- a/src/main/java/com/dl/officialsite/sharing/model/req/PreCheckSharingRewardReq.java +++ b/src/main/java/com/dl/officialsite/sharing/reward/PreCheckSharingRewardReq.java @@ -1,4 +1,4 @@ -package com.dl.officialsite.sharing.model.req; +package com.dl.officialsite.sharing.reward; import lombok.Data;