Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/main/java/com/oronaminc/join/member/util/MyPageMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,44 @@
import com.oronaminc.join.member.dto.MyRoomsGetResponse;
import com.oronaminc.join.member.dto.ParticipationType;
import com.oronaminc.join.participant.domain.Participant;
import com.oronaminc.join.participant.domain.ParticipantType;
import com.oronaminc.join.room.domain.Room;
import java.util.Map;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.time.LocalDate;
import java.util.Map;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MyPageMapper {
public static MyRoomsGetResponse toMyRoomsGetResponse(Page<MyRoomsDto> response) {
return MyRoomsGetResponse.builder()
.content(response.getContent())
.currentPage(response.getNumber())
.size(response.getSize())
.totalElements(response.getTotalElements())
.totalPages(response.getTotalPages())
.build();
.content(response.getContent())
.currentPage(response.getNumber())
.size(response.getSize())
.totalElements(response.getTotalElements())
.totalPages(response.getTotalPages())
.build();
}

public static MyRoomsDto toMyRoomsDto(Participant p, Map<Long, Long> countMap) {
Room room = p.getRoom();
LocalDate date;
if (p.getParticipantType() == ParticipantType.PRESENTER) {
date = room.getCreatedAt().toLocalDate();
} else {
date = p.getCreatedAt().toLocalDate();
}
return MyRoomsDto.builder()
.roomId(room.getId())
.title(room.getTitle())
.emojiCount(room.getEmojiCount())
.status(room.getRoomStatus())
.startedAt(room.getCreatedAt().toLocalDate())
.participationType(ParticipationType.from(p.getParticipantType()))
.questions(countMap.getOrDefault(room.getId(), 0L))
.build();
.roomId(room.getId())
.title(room.getTitle())
.emojiCount(room.getEmojiCount())
.status(room.getRoomStatus())
.startedAt(date)
.participationType(ParticipationType.from(p.getParticipantType()))
.questions(countMap.getOrDefault(room.getId(), 0L))
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.oronaminc.join.member.service;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.time.LocalDateTime;
import java.util.List;

import com.oronaminc.join.member.domain.Member;
import com.oronaminc.join.member.dto.*;
import com.oronaminc.join.participant.domain.Participant;
import com.oronaminc.join.participant.domain.ParticipantType;
import com.oronaminc.join.participant.service.ParticipantReader;
import com.oronaminc.join.question.service.QuestionReader;
import com.oronaminc.join.room.domain.Room;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -18,18 +19,11 @@
import org.springframework.data.domain.Pageable;
import org.springframework.test.util.ReflectionTestUtils;

import com.oronaminc.join.member.domain.Member;
import com.oronaminc.join.member.dto.MyPageType;
import com.oronaminc.join.member.dto.MyProfileGetResponse;
import com.oronaminc.join.member.dto.MyProfileUpdateRequest;
import com.oronaminc.join.member.dto.MyRoomsGetResponse;
import com.oronaminc.join.member.dto.ParticipantCountDto;
import com.oronaminc.join.member.dto.ParticipationType;
import com.oronaminc.join.participant.domain.Participant;
import com.oronaminc.join.participant.domain.ParticipantType;
import com.oronaminc.join.participant.service.ParticipantReader;
import com.oronaminc.join.question.service.QuestionReader;
import com.oronaminc.join.room.domain.Room;
import java.time.LocalDateTime;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class MyPageServiceTests {
Expand All @@ -54,14 +48,14 @@ void getMyProfile_success_test() {
Member member = Member.builder().build();

List<ParticipantCountDto> pc = List.of(
new ParticipantCountDto(ParticipantType.PRESENTER, 1L),
new ParticipantCountDto(ParticipantType.TEAM, 1L),
new ParticipantCountDto(ParticipantType.GUEST, 1L)
new ParticipantCountDto(ParticipantType.PRESENTER, 1L),
new ParticipantCountDto(ParticipantType.TEAM, 1L),
new ParticipantCountDto(ParticipantType.GUEST, 1L)
);

when(memberReader.getById(member.getId())).thenReturn(member);
when(participantReader.countByMemberIdGroupByParticipantType(member.getId()))
.thenReturn(pc);
.thenReturn(pc);

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

when(memberReader.getById(member.getId())).thenReturn(member);
when(participantReader.countByMemberIdGroupByParticipantType(member.getId()))
.thenReturn(pc);
.thenReturn(pc);

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

Room room1 = Room.builder()
.title("~1~의 정석")
.build();
.title("~1~의 정석")
.build();
Room room2 = Room.builder().title("~2~의 정석").build();
Room room3 = Room.builder().title("~3~의 정석").build();
ReflectionTestUtils.setField(room1, "id", 100L);
Expand All @@ -139,33 +133,35 @@ void getMyRooms_success_test() {
ReflectionTestUtils.setField(room3, "createdAt", LocalDateTime.now());

Participant participant1 = Participant.builder()
.room(room1)
.member(member)
.participantType(ParticipantType.PRESENTER)
.build();
.room(room1)
.member(member)
.participantType(ParticipantType.PRESENTER)
.build();
Participant participant2 = Participant.builder()
.room(room2)
.member(member)
.participantType(ParticipantType.TEAM)
.build();
.room(room2)
.member(member)
.participantType(ParticipantType.TEAM)
.build();
Participant participant3 = Participant.builder()
.room(room3)
.member(member)
.participantType(ParticipantType.GUEST)
.build();
.room(room3)
.member(member)
.participantType(ParticipantType.GUEST)
.build();
ReflectionTestUtils.setField(participant2, "createdAt", LocalDateTime.now());
ReflectionTestUtils.setField(participant3, "createdAt", LocalDateTime.now());

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

List<Long> roomIds = List.of(room1.getId(), room2.getId(), room3.getId());
List<Object[]> questions = List.of(
new Object[]{room1.getId(), 1L},
new Object[]{room2.getId(), 2L},
new Object[]{room3.getId(), 3L}
new Object[]{room1.getId(), 1L},
new Object[]{room2.getId(), 2L},
new Object[]{room3.getId(), 3L}
);

when(participantReader.findByMemberId(memberId, pageable))
.thenReturn(participantPage);
.thenReturn(participantPage);
when(questionReader.countByRoomIds(roomIds)).thenReturn(questions);

// when
Expand All @@ -176,7 +172,7 @@ void getMyRooms_success_test() {
assertThat(result.content().getFirst().roomId()).isEqualTo(100L);
assertThat(result.content().getFirst().title()).isEqualTo("~1~의 정석");
assertThat(result.content().getFirst().participationType()).isEqualTo(
ParticipationType.CREATED);
ParticipationType.CREATED);
assertThat(result.content().get(1).participationType()).isEqualTo(ParticipationType.JOINED);

}
Expand Down