Skip to content

Commit

Permalink
feat: related legislator core module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Feb 3, 2024
1 parent c5e86f7 commit 3447eb3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<LegislateVote, Long> {

@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<LegislateVote> findLegislateVotesByLegislateLawName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Vote> votes = voteRepository.findVotesByLawName(lawName);
Expand Down

0 comments on commit 3447eb3

Please sign in to comment.