Skip to content

Commit b59c69c

Browse files
committed
Resolve merge conflicts in controller and service
1 parent 264d1c4 commit b59c69c

File tree

2 files changed

+3
-79
lines changed

2 files changed

+3
-79
lines changed

polling-app-server/src/main/java/com/example/polls/controller/GroupPollController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ResponseEntity<PagedResponse<PollResponse>> getAllPollInGroup(@PathVariab
4040
return ResponseEntity.ok(response);
4141
}
4242

43-
<<<<<<< HEAD
43+
4444
@GetMapping("/{pollId}")
4545
public ResponseEntity<PollResponse> getPollByIdInGroup(@PathVariable Long groupId,
4646
@PathVariable Long pollId,
@@ -49,6 +49,4 @@ public ResponseEntity<PollResponse> getPollByIdInGroup(@PathVariable Long groupI
4949
return ResponseEntity.ok(response);
5050
}
5151

52-
=======
53-
>>>>>>> 4841b43f8923c68f2eb28eab9dc9c02310165544
5452
}

polling-app-server/src/main/java/com/example/polls/service/PollService.java

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class PollService {
5050
@Autowired
5151
private GroupMemberRepository groupMemberRepository;
5252

53-
<<<<<<< HEAD
53+
5454
private PagedResponse<PollResponse> mapPollPagetoPageResponse(UserPrincipal currentUser, Page<Poll> polls) {
5555
if(polls.getNumberOfElements() == 0) {
5656
return new PagedResponse<>(Collections.emptyList(), polls.getNumber(),
@@ -72,8 +72,7 @@ private PagedResponse<PollResponse> mapPollPagetoPageResponse(UserPrincipal curr
7272
return new PagedResponse<>(pollResponses, polls.getNumber(),
7373
polls.getSize(), polls.getTotalElements(), polls.getTotalPages(), polls.isLast());
7474
}
75-
=======
76-
>>>>>>> 4841b43f8923c68f2eb28eab9dc9c02310165544
75+
7776

7877
public PagedResponse<PollResponse> getAllPolls(UserPrincipal currentUser, int page, int size) {
7978
validatePageNumberAndSize(page, size);
@@ -103,44 +102,6 @@ public PagedResponse<PollResponse> getAllPollsInGroup(Long groupId, UserPrincipa
103102
return mapPollPagetoPageResponse(userPrincipal, polls);
104103
}
105104

106-
public PagedResponse<PollResponse> getAllPollsInGroup(Long groupId, UserPrincipal userPrincipal, int page, int size) {
107-
//그룹 유효성검사
108-
Group group = groupRepository.findById(groupId)
109-
.orElseThrow(() -> new ResourceNotFoundException("Group", "id", groupId));
110-
111-
//그룹 멤버 인증
112-
if(!groupMemberRepository.existsByUserIdAndGroupId(userPrincipal.getId(), groupId)) {
113-
throw new BadRequestException("그룹에 가입된 사용자만 투표를 조회할 수 있습니다.");
114-
}
115-
116-
//page 표시 정보 설정하기
117-
Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending());
118-
//결과 데이터 가져오기
119-
Page<Poll> polls = pollRepository.findByGroupId(groupId, pageable);
120-
121-
if(polls.getNumberOfElements() == 0) {
122-
return new PagedResponse<>(Collections.emptyList(), polls.getNumber(),
123-
polls.getSize(), polls.getTotalElements(), polls.getTotalPages(), polls.isLast());
124-
}
125-
126-
// Map Polls to PollResponses containing vote counts and poll creator details
127-
List<Long> pollIds = polls.map(Poll::getId).getContent();
128-
Map<Long, Long> choiceVoteCountMap = getChoiceVoteCountMap(pollIds);
129-
Map<Long, Long> pollUserVoteMap = getPollUserVoteMap(userPrincipal, pollIds);
130-
Map<Long, User> creatorMap = getPollCreatorMap(polls.getContent());
131-
132-
133-
List<PollResponse> pollResponses = polls.map(poll -> {
134-
return ModelMapper.mapPollToPollResponse(poll,
135-
choiceVoteCountMap,
136-
creatorMap.get(poll.getCreatedBy()),
137-
pollUserVoteMap == null ? null : pollUserVoteMap.getOrDefault(poll.getId(), null));
138-
}).getContent();
139-
140-
return new PagedResponse<>(pollResponses, polls.getNumber(),
141-
polls.getSize(), polls.getTotalElements(), polls.getTotalPages(), polls.isLast());
142-
143-
}
144105

145106
public PagedResponse<PollResponse> getPollsCreatedBy(String username, UserPrincipal currentUser, int page, int size) {
146107
validatePageNumberAndSize(page, size);
@@ -235,41 +196,6 @@ private Poll createPollInternal(PollRequest request, Long createdBy, Group group
235196
return pollRepository.save(poll);
236197
}
237198

238-
<<<<<<< HEAD
239-
=======
240-
//그룹 투표 생성
241-
public Poll createPollInGroup(Long groupId, PollRequest request, UserPrincipal userPrincipal) {
242-
//그룹 엔티티 조회
243-
Group group = groupRepository.findById(groupId)
244-
.orElseThrow(() -> new ResourceNotFoundException("Group", "id", groupId));
245-
//투표 객체 생성
246-
Poll poll = new Poll();
247-
poll.setQuestion(request.getQuestion());
248-
poll.setGroup(group);
249-
poll.setCreatedBy(userPrincipal.getId());
250-
251-
//선택지 추가
252-
request.getChoices().forEach(choiceRequest -> {
253-
poll.addChoice(new Choice(choiceRequest.getText()));
254-
});
255-
256-
//종료시간 계산
257-
Instant now = Instant.now();
258-
Instant expirationDateTime = now.plus(Duration.ofDays(request.getPollLength().getDays()))
259-
.plus(Duration.ofHours(request.getPollLength().getHours()));
260-
poll.setExpirationDateTime(expirationDateTime);
261-
262-
263-
//저장
264-
return pollRepository.save(poll);
265-
}
266-
267-
268-
public PollResponse getPollById(Long pollId, UserPrincipal currentUser) {
269-
Poll poll = pollRepository.findById(pollId).orElseThrow(
270-
() -> new ResourceNotFoundException("Poll", "id", pollId));
271-
>>>>>>> 4841b43f8923c68f2eb28eab9dc9c02310165544
272-
273199
public Poll createPoll(PollRequest pollRequest) {
274200
return createPollInternal(pollRequest, null, null);
275201
}

0 commit comments

Comments
 (0)