Skip to content

Commit

Permalink
feat: mypage query service
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Feb 3, 2024
1 parent 50a501a commit 43687d2
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 @@ -18,6 +18,14 @@ public class LawQueryService {
private final LawRepository lawRepository;
private final LegislateLawRepository legislateLawRepository;

public Law findLaw(Long lawId) {
return lawRepository.findLawById(lawId);
}

public LegislateLaw findLegislatorLaw(Long lawId) {
return legislateLawRepository.findLegislateLawById(lawId);
}

public void saveLaw(String lawName) {

final Law law = Law.builder().name(lawName).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.congress.coremodule.member.domain.entity.Member;
import com.congress.coremodule.member.domain.repository.MemberRepository;
import com.congress.coremodule.vote.domain.entity.HashTag;
import com.congress.coremodule.vote.domain.entity.LegislateVote;
import com.congress.coremodule.vote.domain.entity.Vote;
import com.congress.coremodule.vote.domain.repository.HashTagRepository;
import com.congress.coremodule.vote.domain.repository.LegislateVoteRepository;
import com.congress.coremodule.vote.domain.repository.VoteRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -18,13 +20,26 @@ public class MyPageQueryService {
private final MemberRepository memberRepository;
private final HashTagRepository hashTagRepository;
private final VoteRepository voteRepository;
private final LegislateVoteRepository legislateVoteRepository;

public Long getMemberId(String userId) {

Member member = memberRepository.findMemberByUserId(userId);
return member.getId();
}

public Long getLawId(Long memberId) {

HashTag hashTag = hashTagRepository.findHashTagByMemberId(memberId);
return hashTag.getLaw().getId();
}

public Long getLegislatorId(Long memberId) {

LegislateVote vote = legislateVoteRepository.findLegislateVoteByMemberId(memberId);
return vote.getLegislateLaw().getId();
}

public String getHashTagName(Long memberId) {

HashTag hashTag = hashTagRepository.findHashTagByMemberId(memberId);
Expand All @@ -36,4 +51,10 @@ public Integer getVoteScore(Long memberId) {
Vote vote = voteRepository.findVoteByMemberId(memberId);
return vote.getScore();
}

public Integer getLegislatorVoteScore(Long memberId) {

LegislateVote vote = legislateVoteRepository.findLegislateVoteByMemberId(memberId);
return vote.getScore();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.congress.coremodule.vote.domain.repository;

import com.congress.coremodule.law.domain.entity.LegislateLaw;
import com.congress.coremodule.vote.domain.entity.LegislateVote;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -13,4 +14,6 @@ public interface LegislateVoteRepository extends JpaRepository<LegislateVote, Lo
long countByUserIdAndLegislatorName(@Param("userId") String userId, @Param("legislatorName") String legislatorName);

List<LegislateVote> findLegislateVotesByLegislateLawName(String name);

LegislateVote findLegislateVoteByMemberId(Long memberId);
}

0 comments on commit 43687d2

Please sign in to comment.