Skip to content

Commit

Permalink
Merge pull request #147 from minseok1015/dev
Browse files Browse the repository at this point in the history
null 추가
  • Loading branch information
minseok1015 authored Aug 19, 2024
2 parents 6e9e96b + ed272bc commit 4335b51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/main/java/store/itpick/backend/controller/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.web.bind.annotation.RestController;
import store.itpick.backend.model.rank.CommunityType;
import store.itpick.backend.model.rank.PeriodType;
import store.itpick.backend.service.AlarmService;
import store.itpick.backend.service.DebateService;
import store.itpick.backend.util.Redis;

import java.util.*;
Expand All @@ -18,6 +20,12 @@ public class TestController {
@Autowired
private Redis redis;

@Autowired
private DebateService debateService;

@Autowired
private AlarmService alarmService;

@GetMapping("/*.ico")
void pathMatch() {
System.out.println("favicon.ico.");
Expand All @@ -40,6 +48,11 @@ public void totalTest() {
redis.saveTotalRanking(PeriodType.BY_WEEK);
}

@GetMapping("/trend")
public void updateHotDebate(){
alarmService.createAlarmTrend(debateService.updateHotDebate());
}

@GetMapping("/save-day-manually")
public String saveDayManually() {
List<String> dateList = new ArrayList<>(Arrays.asList("240805", "240806", "240807", "240808", "240809", "240810", "240811", "240812", "240813", "240814", "240815"));
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/store/itpick/backend/service/DebateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ public GetDebateResponse getDebate(Long debateId, long userId) {
boolean userVoted = false;
String userVoteOptionText = null;

for (VoteOption voteOption : debate.getVote().getVoteOptions()) {
List<UserVoteChoice> userVoteChoices = userVoteChoiceRepository.findByVoteOptionAndUser(voteOption, user);
if (!userVoteChoices.isEmpty()) {
userVoted = true;
// 여러 선택지 중 첫 번째 선택된 옵션의 텍스트를 가져옴 (필요에 따라 조정 가능)
userVoteOptionText = userVoteChoices.get(0).getVoteOption().getOptionText();
break;
// 투표가 존재할 경우, 사용자의 투표 여부 확인
if (debate.getVote() != null) {
for (VoteOption voteOption : debate.getVote().getVoteOptions()) {
List<UserVoteChoice> userVoteChoices = userVoteChoiceRepository.findByVoteOptionAndUser(voteOption, user);
if (!userVoteChoices.isEmpty()) {
userVoted = true;
userVoteOptionText = userVoteChoices.get(0).getVoteOption().getOptionText();
break;
}
}
}

Expand Down Expand Up @@ -197,7 +199,7 @@ public GetDebateResponse getDebate(Long debateId, long userId) {
return GetDebateResponse.builder()
.debateId(debate.getDebateId())
.debateImgUrl(debate.getImageUrl())
.multipleChoice(debate.getVote().isMultipleChoice())
.multipleChoice(debate.getVote() != null && debate.getVote().isMultipleChoice()) // Vote가 있을 경우만 처리
.title(debate.getTitle())
.content(debate.getContent())
.hits(debate.getHits())
Expand Down

0 comments on commit 4335b51

Please sign in to comment.