diff --git a/core-module/src/main/java/com/congress/coremodule/vote/application/service/VoteQueryUseCase.java b/core-module/src/main/java/com/congress/coremodule/vote/application/service/VoteQueryUseCase.java index 1706cb2..c671c6a 100644 --- a/core-module/src/main/java/com/congress/coremodule/vote/application/service/VoteQueryUseCase.java +++ b/core-module/src/main/java/com/congress/coremodule/vote/application/service/VoteQueryUseCase.java @@ -2,6 +2,7 @@ import com.congress.coremodule.vote.application.dto.HashTagInfo; import com.congress.coremodule.vote.application.dto.HashTagRank; +import com.congress.coremodule.vote.application.dto.LegislatorVoteInfo; import com.congress.coremodule.vote.application.dto.VoteInfo; import com.congress.coremodule.vote.domain.service.VoteQueryService; import lombok.RequiredArgsConstructor; @@ -30,8 +31,18 @@ public void saveRenewalScore(VoteInfo voteInfo) { voteQueryService.saveVote(voteInfo); } + public void saveLegislatorRenewalScore(LegislatorVoteInfo voteInfo) { + + voteQueryService.saveLegislatorVote(voteInfo); + } + public Integer getTotalScore(String lawName) { return voteQueryService.getTotalScore(lawName); } + + public Integer getLegislatorTotalScore(String legislatorName) { + + return voteQueryService.getLegislatorTotalScore(legislatorName); + } } diff --git a/core-module/src/main/java/com/congress/coremodule/vote/domain/repository/LegislateVoteRepository.java b/core-module/src/main/java/com/congress/coremodule/vote/domain/repository/LegislateVoteRepository.java index c0f2275..697eb2d 100644 --- a/core-module/src/main/java/com/congress/coremodule/vote/domain/repository/LegislateVoteRepository.java +++ b/core-module/src/main/java/com/congress/coremodule/vote/domain/repository/LegislateVoteRepository.java @@ -2,10 +2,15 @@ import com.congress.coremodule.vote.domain.entity.LegislateVote; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; public interface LegislateVoteRepository extends JpaRepository { + @Query("SELECT COUNT(*) FROM LegislateVote v WHERE v.member.userId = :userId AND v.legislateLaw.name = :legislatorName") + long countByUserIdAndLegislatorName(@Param("userId") String userId, @Param("legislatorName") String legislatorName); + List findLegislateVotesByLegislateLawName(String name); } diff --git a/core-module/src/main/java/com/congress/coremodule/vote/domain/service/VoteQueryService.java b/core-module/src/main/java/com/congress/coremodule/vote/domain/service/VoteQueryService.java index fbbc2b3..ceca638 100644 --- a/core-module/src/main/java/com/congress/coremodule/vote/domain/service/VoteQueryService.java +++ b/core-module/src/main/java/com/congress/coremodule/vote/domain/service/VoteQueryService.java @@ -2,12 +2,14 @@ import com.congress.commonmodule.exception.Error; import com.congress.coremodule.law.domain.entity.Law; +import com.congress.coremodule.law.domain.entity.LegislateLaw; import com.congress.coremodule.law.domain.repository.LawRepository; import com.congress.coremodule.law.domain.repository.LegislateLawRepository; import com.congress.coremodule.member.domain.entity.Member; import com.congress.coremodule.member.domain.repository.MemberRepository; import com.congress.coremodule.vote.application.dto.HashTagInfo; import com.congress.coremodule.vote.application.dto.HashTagRank; +import com.congress.coremodule.vote.application.dto.LegislatorVoteInfo; import com.congress.coremodule.vote.application.dto.VoteInfo; import com.congress.coremodule.vote.application.mapper.HashTagMapper; import com.congress.coremodule.vote.domain.entity.HashTag; @@ -66,6 +68,20 @@ public void saveVote(VoteInfo voteInfo) { } } + public void saveLegislatorVote(LegislatorVoteInfo voteInfo) { + + if (legislateVoteRepository.countByUserIdAndLegislatorName(voteInfo.getUserId(), voteInfo.getLegislatorName()) >= 1) { + throw new VoteException(Error.VOTE_DUPLICATE); + } else { + + Member member = memberRepository.findMemberByUserId(voteInfo.getUserId()); + LegislateLaw law = legislateLawRepository.findLegislateLawByName(voteInfo.getLegislatorName()); + + LegislateVote vote = HashTagMapper.toLegislatorVote(voteInfo.getScore(), member, law); + legislateVoteRepository.save(vote); + } + } + public Integer getTotalScore(String lawName) { List votes = voteRepository.findVotesByLawName(lawName);