Skip to content

Commit a200642

Browse files
committed
merge: 충돌 해결
2 parents 4611065 + 5e5d115 commit a200642

File tree

4 files changed

+99
-90
lines changed

4 files changed

+99
-90
lines changed

src/main/java/com/oronaminc/join/answer/dao/AnswerRepository.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,62 @@
22

33
import com.oronaminc.join.answer.domain.Answer;
44
import com.oronaminc.join.question.domain.Question;
5-
import java.time.LocalDateTime;
6-
import java.util.List;
7-
import java.util.Optional;
85
import org.springframework.data.domain.Pageable;
96
import org.springframework.data.jpa.repository.JpaRepository;
107
import org.springframework.data.jpa.repository.Query;
118
import org.springframework.data.repository.query.Param;
129

10+
import java.time.LocalDateTime;
11+
import java.util.List;
12+
import java.util.Optional;
13+
1314
public interface AnswerRepository extends JpaRepository<Answer, Long> {
1415

1516
Optional<Answer> findByQuestionId(Long questionId);
1617

1718
@Query("""
18-
SELECT a
19-
FROM Answer a
20-
JOIN FETCH a.member m
21-
WHERE a.question.id = :questionId
22-
ORDER BY a.createdAt DESC, a.id DESC
23-
""")
19+
SELECT a
20+
FROM Answer a
21+
JOIN FETCH a.member m
22+
WHERE a.question.id = :questionId
23+
ORDER BY a.createdAt ASC, a.id ASC
24+
""")
2425
List<Answer> findFirstPageByQuestionId(
25-
@Param("questionId") Long questionId,
26-
Pageable pageable
26+
@Param("questionId") Long questionId,
27+
Pageable pageable
2728
);
2829

2930
@Query("""
30-
SELECT a
31-
FROM Answer a
32-
JOIN FETCH a.member m
33-
WHERE a.question.id = :questionId
34-
AND (a.createdAt < :lastCreatedAt OR (a.createdAt = :lastCreatedAt AND a.id < :lastId))
35-
ORDER BY a.createdAt DESC, a.id DESC
36-
""")
31+
SELECT a
32+
FROM Answer a
33+
JOIN FETCH a.member m
34+
WHERE a.question.id = :questionId
35+
AND (a.createdAt > :lastCreatedAt OR (a.createdAt = :lastCreatedAt AND a.id > :lastId))
36+
ORDER BY a.createdAt ASC, a.id ASC
37+
""")
3738
List<Answer> findByQuestionIdWithCursor(
38-
@Param("questionId") Long questionId,
39-
@Param("lastCreatedAt") LocalDateTime lastCreatedAt,
40-
@Param("lastId") Long lastId,
41-
Pageable pageable
39+
@Param("questionId") Long questionId,
40+
@Param("lastCreatedAt") LocalDateTime lastCreatedAt,
41+
@Param("lastId") Long lastId,
42+
Pageable pageable
4243
);
4344

4445
void deleteByQuestionId(Long questionId);
4546

4647
void deleteByQuestionIn(List<Question> questions);
4748

4849
@Query("""
49-
select count(distinct a.question.id)
50-
from Answer a
51-
where a.question.room.id = :roomId
52-
""")
50+
select count(distinct a.question.id)
51+
from Answer a
52+
where a.question.room.id = :roomId
53+
""")
5354
Long countAnsweredQuestionsByRoomId(@Param("roomId") Long roomId);
5455

5556
@Query("""
56-
select a
57-
from Answer a
58-
where a.question.id in :questionIds
59-
""")
57+
select a
58+
from Answer a
59+
where a.question.id in :questionIds
60+
""")
6061
List<Answer> findAllByQuestionIds(@Param("questionIds") List<Long> questionIds);
6162

6263
}

src/main/java/com/oronaminc/join/member/util/MyPageMapper.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,44 @@
44
import com.oronaminc.join.member.dto.MyRoomsGetResponse;
55
import com.oronaminc.join.member.dto.ParticipationType;
66
import com.oronaminc.join.participant.domain.Participant;
7+
import com.oronaminc.join.participant.domain.ParticipantType;
78
import com.oronaminc.join.room.domain.Room;
8-
import java.util.Map;
99
import lombok.AccessLevel;
1010
import lombok.NoArgsConstructor;
1111
import org.springframework.data.domain.Page;
1212

13+
import java.time.LocalDate;
14+
import java.util.Map;
15+
1316
@NoArgsConstructor(access = AccessLevel.PRIVATE)
1417
public class MyPageMapper {
1518
public static MyRoomsGetResponse toMyRoomsGetResponse(Page<MyRoomsDto> response) {
1619
return MyRoomsGetResponse.builder()
17-
.content(response.getContent())
18-
.currentPage(response.getNumber())
19-
.size(response.getSize())
20-
.totalElements(response.getTotalElements())
21-
.totalPages(response.getTotalPages())
22-
.build();
20+
.content(response.getContent())
21+
.currentPage(response.getNumber())
22+
.size(response.getSize())
23+
.totalElements(response.getTotalElements())
24+
.totalPages(response.getTotalPages())
25+
.build();
2326
}
2427

2528
public static MyRoomsDto toMyRoomsDto(Participant p, Map<Long, Long> countMap) {
2629
Room room = p.getRoom();
30+
LocalDate date;
31+
if (p.getParticipantType() == ParticipantType.PRESENTER) {
32+
date = room.getCreatedAt().toLocalDate();
33+
} else {
34+
date = p.getCreatedAt().toLocalDate();
35+
}
2736
return MyRoomsDto.builder()
28-
.roomId(room.getId())
29-
.title(room.getTitle())
30-
.emojiCount(room.getEmojiCount())
31-
.status(room.getRoomStatus())
32-
.startedAt(room.getCreatedAt().toLocalDate())
33-
.participationType(ParticipationType.from(p.getParticipantType()))
34-
.questions(countMap.getOrDefault(room.getId(), 0L))
35-
.build();
37+
.roomId(room.getId())
38+
.title(room.getTitle())
39+
.emojiCount(room.getEmojiCount())
40+
.status(room.getRoomStatus())
41+
.startedAt(date)
42+
.participationType(ParticipationType.from(p.getParticipantType()))
43+
.questions(countMap.getOrDefault(room.getId(), 0L))
44+
.build();
3645
}
3746
}
3847

src/main/java/com/oronaminc/join/room/service/RoomService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ private List<TopQnAResponse> getTopQnA(Long roomId) {
218218
}
219219

220220
private Double calculateAnswerRate(Long totalQuestions, Long totalAnswerByQuestion) {
221-
return (totalQuestions == 0)
222-
? 0.0
223-
: ((double)totalAnswerByQuestion / totalQuestions) * 100;
221+
if (totalQuestions == 0) {
222+
return 0.0;
223+
}
224+
225+
double rate = ((double) totalAnswerByQuestion / totalQuestions) * 100;
226+
return Math.round(rate * 10.0) / 10.0;
224227

225228
}
226229

src/test/java/com/oronaminc/join/member/service/MyPageServiceTests.java

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.oronaminc.join.member.service;
22

3-
import static org.assertj.core.api.Assertions.*;
4-
import static org.mockito.Mockito.*;
5-
6-
import java.time.LocalDateTime;
7-
import java.util.List;
8-
3+
import com.oronaminc.join.member.domain.Member;
4+
import com.oronaminc.join.member.dto.*;
5+
import com.oronaminc.join.participant.domain.Participant;
6+
import com.oronaminc.join.participant.domain.ParticipantType;
7+
import com.oronaminc.join.participant.service.ParticipantReader;
8+
import com.oronaminc.join.question.service.QuestionReader;
9+
import com.oronaminc.join.room.domain.Room;
910
import org.junit.jupiter.api.DisplayName;
1011
import org.junit.jupiter.api.Test;
1112
import org.junit.jupiter.api.extension.ExtendWith;
@@ -18,18 +19,11 @@
1819
import org.springframework.data.domain.Pageable;
1920
import org.springframework.test.util.ReflectionTestUtils;
2021

21-
import com.oronaminc.join.member.domain.Member;
22-
import com.oronaminc.join.member.dto.MyPageType;
23-
import com.oronaminc.join.member.dto.MyProfileGetResponse;
24-
import com.oronaminc.join.member.dto.MyProfileUpdateRequest;
25-
import com.oronaminc.join.member.dto.MyRoomsGetResponse;
26-
import com.oronaminc.join.member.dto.ParticipantCountDto;
27-
import com.oronaminc.join.member.dto.ParticipationType;
28-
import com.oronaminc.join.participant.domain.Participant;
29-
import com.oronaminc.join.participant.domain.ParticipantType;
30-
import com.oronaminc.join.participant.service.ParticipantReader;
31-
import com.oronaminc.join.question.service.QuestionReader;
32-
import com.oronaminc.join.room.domain.Room;
22+
import java.time.LocalDateTime;
23+
import java.util.List;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
import static org.mockito.Mockito.when;
3327

3428
@ExtendWith(MockitoExtension.class)
3529
class MyPageServiceTests {
@@ -54,14 +48,14 @@ void getMyProfile_success_test() {
5448
Member member = Member.builder().build();
5549

5650
List<ParticipantCountDto> pc = List.of(
57-
new ParticipantCountDto(ParticipantType.PRESENTER, 1L),
58-
new ParticipantCountDto(ParticipantType.TEAM, 1L),
59-
new ParticipantCountDto(ParticipantType.GUEST, 1L)
51+
new ParticipantCountDto(ParticipantType.PRESENTER, 1L),
52+
new ParticipantCountDto(ParticipantType.TEAM, 1L),
53+
new ParticipantCountDto(ParticipantType.GUEST, 1L)
6054
);
6155

6256
when(memberReader.getById(member.getId())).thenReturn(member);
6357
when(participantReader.countByMemberIdGroupByParticipantType(member.getId()))
64-
.thenReturn(pc);
58+
.thenReturn(pc);
6559

6660
// when
6761
MyProfileGetResponse myProfile = myPageService.getMyProfile(member.getId());
@@ -84,7 +78,7 @@ void getMyProfile_success_test2() {
8478

8579
when(memberReader.getById(member.getId())).thenReturn(member);
8680
when(participantReader.countByMemberIdGroupByParticipantType(member.getId()))
87-
.thenReturn(pc);
81+
.thenReturn(pc);
8882

8983
// when
9084
MyProfileGetResponse myProfile = myPageService.getMyProfile(member.getId());
@@ -127,8 +121,8 @@ void getMyRooms_success_test() {
127121
Pageable pageable = PageRequest.of(0, 10);
128122

129123
Room room1 = Room.builder()
130-
.title("~1~의 정석")
131-
.build();
124+
.title("~1~의 정석")
125+
.build();
132126
Room room2 = Room.builder().title("~2~의 정석").build();
133127
Room room3 = Room.builder().title("~3~의 정석").build();
134128
ReflectionTestUtils.setField(room1, "id", 100L);
@@ -139,33 +133,35 @@ void getMyRooms_success_test() {
139133
ReflectionTestUtils.setField(room3, "createdAt", LocalDateTime.now());
140134

141135
Participant participant1 = Participant.builder()
142-
.room(room1)
143-
.member(member)
144-
.participantType(ParticipantType.PRESENTER)
145-
.build();
136+
.room(room1)
137+
.member(member)
138+
.participantType(ParticipantType.PRESENTER)
139+
.build();
146140
Participant participant2 = Participant.builder()
147-
.room(room2)
148-
.member(member)
149-
.participantType(ParticipantType.TEAM)
150-
.build();
141+
.room(room2)
142+
.member(member)
143+
.participantType(ParticipantType.TEAM)
144+
.build();
151145
Participant participant3 = Participant.builder()
152-
.room(room3)
153-
.member(member)
154-
.participantType(ParticipantType.GUEST)
155-
.build();
146+
.room(room3)
147+
.member(member)
148+
.participantType(ParticipantType.GUEST)
149+
.build();
150+
ReflectionTestUtils.setField(participant2, "createdAt", LocalDateTime.now());
151+
ReflectionTestUtils.setField(participant3, "createdAt", LocalDateTime.now());
156152

157153
List<Participant> pc = List.of(participant1, participant2, participant3);
158154
Page<Participant> participantPage = new PageImpl<>(pc, pageable, 1);
159155

160156
List<Long> roomIds = List.of(room1.getId(), room2.getId(), room3.getId());
161157
List<Object[]> questions = List.of(
162-
new Object[]{room1.getId(), 1L},
163-
new Object[]{room2.getId(), 2L},
164-
new Object[]{room3.getId(), 3L}
158+
new Object[]{room1.getId(), 1L},
159+
new Object[]{room2.getId(), 2L},
160+
new Object[]{room3.getId(), 3L}
165161
);
166162

167163
when(participantReader.findByMemberId(memberId, pageable))
168-
.thenReturn(participantPage);
164+
.thenReturn(participantPage);
169165
when(questionReader.countByRoomIds(roomIds)).thenReturn(questions);
170166

171167
// when
@@ -176,7 +172,7 @@ void getMyRooms_success_test() {
176172
assertThat(result.content().getFirst().roomId()).isEqualTo(100L);
177173
assertThat(result.content().getFirst().title()).isEqualTo("~1~의 정석");
178174
assertThat(result.content().getFirst().participationType()).isEqualTo(
179-
ParticipationType.CREATED);
175+
ParticipationType.CREATED);
180176
assertThat(result.content().get(1).participationType()).isEqualTo(ParticipationType.JOINED);
181177

182178
}

0 commit comments

Comments
 (0)