Skip to content

Commit

Permalink
Merge pull request #75 from Dapp-Learning-DAO/feature/arc_share
Browse files Browse the repository at this point in the history
去除
  • Loading branch information
arc0035 authored Dec 10, 2023
2 parents afeadbd + 29e9e09 commit 3ff23ed
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions interface/share.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
},
{
"url": "http://81.69.8.95:8080/share/usershare/update",
"url": "http:/43.135.22.107:8080/share/usershare/update",
"method": "POST",
"body": {
"id":"分享id,如111",
Expand Down Expand Up @@ -89,7 +89,7 @@
}
},
{
"url": "http://81.69.8.95:8080/share/usershare/{memberId}?pageNo=1&pageSize=10",
"url": "http://81.69.8.95:8080/share/usershare/byUser?memberId=1?pageNo=1&pageSize=10",
"method": "GET",
"response":
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class LoginFilter extends OncePerRequestFilter {
add("/login/logout");
add("/share/usershare/all");
add("/share/usershare/queryByShareId");
add("/share/usershare/byUser");
add("/share/usershare/create");
add("/share/usershare/update");
add("/share/usershare/delete");
}} ;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public BaseResponse updateSharing(UpdateSharingReq req){
* 删除分享
*/
@PostMapping("delete")
public BaseResponse deleteSharing(@RequestParam("shareId") long shareId){
this.userSharingService.deleteSharing(shareId);
public BaseResponse deleteSharing(@RequestParam("shareId") long shareId, @RequestParam("memberId") long memberId){
this.userSharingService.deleteSharing(shareId, memberId);
return BaseResponse.success();
}

Expand Down Expand Up @@ -76,8 +76,8 @@ public BaseResponse<SharingVo> querySharing(@RequestParam("shareId") long shareI
/**
* 查看用户的分享
*/
@GetMapping("{memberId}")
public BaseResponse<SharingByUserResp> loadSharingByUser(@PathVariable("memberId") long memberId,
@GetMapping("byUser")
public BaseResponse<SharingByUserResp> loadSharingByUser(@RequestParam("memberId") long memberId,
@RequestParam(value = "pageNo",defaultValue = "1") int pageNo,
@RequestParam(value = "pageSize",defaultValue = "20") int pageSize) {
return BaseResponse.successWithData(this.userSharingService.loadSharingByUser(memberId, pageNo, pageSize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public class CreateSharingReq {
@ApiModelProperty("标签类别")
//defi zk underlying
private String label;

/**
* 分享人memberId
*/
private long memberId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public class UpdateSharingReq {
*/
@ApiModelProperty("分享标签")
private String label;

/**
* 修改人id
*/
private String memberId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IUserSharingService {
/**
* 删除分享
*/
void deleteSharing(long shareId);
void deleteSharing(long shareId, long memberId);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public long createSharing(CreateSharingReq req) {
/**
* 登陆用户转member
*/
SessionUserInfo userInfo = HttpSessionUtils.getMember(request.getSession());
Preconditions.checkState(userInfo != null, "User info not null");
Optional<Member> memberOpt = this.memberRepository.findByAddress(userInfo.getAddress());
Member member = memberOpt.get();

// SessionUserInfo userInfo = HttpSessionUtils.getMember(request.getSession());
// Preconditions.checkState(userInfo != null, "User info not null");
// Optional<Member> memberOpt = this.memberRepository.findByAddress(userInfo.getAddress());
// Member member = memberOpt.get();
// if(member.getId() != req.)
/**
* 创建资料
*/
Expand All @@ -61,7 +61,7 @@ public long createSharing(CreateSharingReq req) {
entity.setPresenter(req.getPresenter());
entity.setOrg(req.getOrg());
entity.setTwitter(req.getTwitter());
entity.setMemberId(member.getId().longValue());
entity.setMemberId(req.getMemberId());
entity.setSharingDoc(req.getSharingDoc());
entity.setLabel(req.getLabel());
entity.setLockStatus(SharingLockStatus.UNLOCKED.getCode());
Expand All @@ -80,10 +80,14 @@ public void updateSharing(UpdateSharingReq req) {
TbShare sharing = existed.get();
SessionUserInfo userInfo = HttpSessionUtils.getMember(request.getSession());
Member member = this.memberRepository.findByAddress(userInfo.getAddress()).get();
if(!Objects.equals(sharing.getMemberId(), member.getId())){
throw new BizException(CodeEnums.SHARING_NOT_FOUND);
}

// if(!Objects.equals(sharing.getMemberId(), member.getId())){
// throw new BizException(CodeEnums.SHARING_NOT_FOUND);
// }

if(!Objects.equals(sharing.getMemberId(), req.getMemberId())){
throw new BizException(CodeEnums.SHARING_NOT_OWNER);
}
if(sharing.getLockStatus() == SharingLockStatus.LOCKED.getCode()){
throw new BizException(CodeEnums.SHARING_LOCKED);
}
Expand All @@ -101,19 +105,18 @@ public void updateSharing(UpdateSharingReq req) {
}

@Override
public void deleteSharing(long shareId) {
public void deleteSharing(long shareId, long memberId) {
//Verify
Optional<TbShare> existed = this.sharingRepository.findById(shareId);
if(!existed.isPresent()){
throw new BizException(CodeEnums.SHARING_NOT_FOUND);
}
TbShare sharing = existed.get();
SessionUserInfo userInfo = HttpSessionUtils.getMember(request.getSession());
Member member = this.memberRepository.findByAddress(userInfo.getAddress()).get();
if(!Objects.equals(sharing.getMemberId(), member.getId())){
throw new BizException(CodeEnums.SHARING_NOT_FOUND);
// SessionUserInfo userInfo = HttpSessionUtils.getMember(request.getSession());
// Member member = this.memberRepository.findByAddress(userInfo.getAddress()).get();
if(!Objects.equals(sharing.getMemberId(), memberId)){
throw new BizException(CodeEnums.SHARING_NOT_OWNER);
}

//Delete
this.sharingRepository.deleteById(shareId);
}
Expand Down

0 comments on commit 3ff23ed

Please sign in to comment.