-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Style: ReviewVote 이름을 Vote 로 변경 (#189)
- Loading branch information
1 parent
5fe806d
commit 1e26ce4
Showing
16 changed files
with
376 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/java/com/goodseats/seatviewreviews/domain/review/mapper/ReviewVoteMapper.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/main/java/com/goodseats/seatviewreviews/domain/review/mapper/VoteMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.goodseats.seatviewreviews.domain.review.mapper; | ||
|
||
import com.goodseats.seatviewreviews.domain.member.model.entity.Member; | ||
import com.goodseats.seatviewreviews.domain.review.model.dto.response.VotesResponse; | ||
import com.goodseats.seatviewreviews.domain.review.model.entity.Review; | ||
import com.goodseats.seatviewreviews.domain.review.model.entity.Vote; | ||
import com.goodseats.seatviewreviews.domain.review.model.vo.VoteChoice; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class VoteMapper { | ||
|
||
public static Vote toEntity(Member member, Review review, VoteChoice voteChoice) { | ||
return new Vote(voteChoice, member, review); | ||
} | ||
|
||
public static VotesResponse toClickedVotesResponse(Review review, Vote vote) { | ||
return new VotesResponse(review.getLikeCount(), review.getDislikeCount(), vote.isLike(), vote.isDislike()); | ||
} | ||
|
||
public static VotesResponse toNotClickedVotesResponse(Review review) { | ||
return new VotesResponse(review.getLikeCount(), review.getDislikeCount(), false, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...del/dto/response/ReviewVotesResponse.java → ...iew/model/dto/response/VotesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/main/java/com/goodseats/seatviewreviews/domain/review/service/ReviewVoteRedisFacade.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
src/main/java/com/goodseats/seatviewreviews/domain/review/service/VoteRedisFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.goodseats.seatviewreviews.domain.review.service; | ||
|
||
import static com.goodseats.seatviewreviews.common.constant.RedisConstant.*; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.redisson.api.RLock; | ||
import org.redisson.api.RedissonClient; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.goodseats.seatviewreviews.domain.review.model.dto.request.VoteCreateRequest; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class VoteRedisFacade { | ||
|
||
private final RedissonClient redissonClient; | ||
private final VoteService voteService; | ||
|
||
public Long createVote(VoteCreateRequest voteCreateRequest, Long memberId) { | ||
RLock voteLock = redissonClient.getLock(VOTE_LOCK + voteCreateRequest.reviewId()); | ||
|
||
try { | ||
tryLock(voteLock); | ||
return voteService.createVote(voteCreateRequest, memberId); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} finally { | ||
if (voteLock.isHeldByCurrentThread()) { | ||
voteLock.unlock(); | ||
} | ||
} | ||
} | ||
|
||
public void deleteVote(Long voteId, Long memberId) { | ||
RLock voteLock = redissonClient.getLock(VOTE_LOCK + voteId); | ||
|
||
try { | ||
tryLock(voteLock); | ||
voteService.deleteVote(voteId, memberId); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} finally { | ||
if (voteLock.isHeldByCurrentThread()) { | ||
voteLock.unlock(); | ||
} | ||
} | ||
} | ||
|
||
private void tryLock(RLock voteLock) throws InterruptedException { | ||
boolean available = voteLock.tryLock(LOCK_WAIT_TIME, LEASE_TIME, TimeUnit.SECONDS); | ||
|
||
if (!available) { | ||
throw new InterruptedException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.