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
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ public Channel(int sequence, ChannelType type, String url) {
public void updateMentor(Mentor mentor) {
this.mentor = mentor;
}

public void update(Channel channel) {
this.sequence = channel.sequence;
this.type = channel.type;
this.url = channel.url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,20 @@ public void updatePassTip(String passTip) {
}

public void updateChannels(List<Channel> channels) {
this.channels.clear();
if (channels == null || channels.isEmpty()) {
return;
}
for (Channel channel : channels) {
channel.updateMentor(this);
this.channels.add(channel);
int newChannelSize = Math.max(channels.size(), this.channels.size());
int originalChannelSize = this.channels.size();
for (int i = 0; i < newChannelSize; i++) {
if (i < channels.size() && i < this.channels.size()) { // 기존 채널 수정
Channel existing = this.channels.get(i);
Channel newChannel = channels.get(i);
existing.update(newChannel);
} else if (i < channels.size()) { // 채널 갯수 늘어남 - 새로운 채널 추가
Channel newChannel = channels.get(i);
newChannel.updateMentor(this);
this.channels.add(newChannel);
} else if (i < originalChannelSize) { // 채널 갯수 줄어듦 - 기존 채널 삭제
this.channels.remove(this.channels.size() - 1);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.example.solidconnection.mentor.domain.ChannelType.BLOG;
import static com.example.solidconnection.mentor.domain.ChannelType.INSTAGRAM;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.junit.jupiter.api.Assertions.assertAll;

import com.example.solidconnection.mentor.domain.Channel;
Expand Down Expand Up @@ -109,8 +110,28 @@ class 멘토의_마이_페이지를_수정한다 {
}

@Test
void 채널_정보를_수정한다() {
void 기존보다_적게_채널_정보를_수정한다() {
// given
channelFixture.채널(1, mentor);
channelFixture.채널(2, mentor);
channelFixture.채널(3, mentor);
channelFixture.채널(4, mentor);
List<ChannelRequest> newChannels = List.of(new ChannelRequest(BLOG, "https://blog.com"));
MentorMyPageUpdateRequest request = new MentorMyPageUpdateRequest("introduction", "passTip", newChannels);

// when
mentorMyPageService.updateMentorMyPage(mentorUser.getId(), request);

// then
List<Channel> updatedChannels = channelRepositoryForTest.findAllByMentorId(mentor.getId());
assertThat(updatedChannels).extracting(Channel::getSequence, Channel::getType, Channel::getUrl)
.containsExactlyInAnyOrder(tuple(1, BLOG, "https://blog.com"));
}

@Test
void 기존보다_많게_채널_정보를_수정한다() {
// given
channelFixture.채널(1, mentor);
List<ChannelRequest> newChannels = List.of(
new ChannelRequest(BLOG, "https://blog.com"),
new ChannelRequest(INSTAGRAM, "https://instagram.com")
Expand All @@ -122,12 +143,11 @@ class 멘토의_마이_페이지를_수정한다 {

// then
List<Channel> updatedChannels = channelRepositoryForTest.findAllByMentorId(mentor.getId());
assertAll(
() -> assertThat(updatedChannels).extracting(Channel::getType)
.containsExactly(BLOG, INSTAGRAM),
() -> assertThat(updatedChannels).extracting(Channel::getUrl)
.containsExactly("https://blog.com", "https://instagram.com")
);
assertThat(updatedChannels).extracting(Channel::getSequence, Channel::getType, Channel::getUrl)
.containsExactlyInAnyOrder(
tuple(1, BLOG, "https://blog.com"),
tuple(2, INSTAGRAM, "https://instagram.com")
);
}
}
}
Loading