File tree Expand file tree Collapse file tree 3 files changed +35
-14
lines changed
main/java/com/example/solidconnection/mentor/domain
test/java/com/example/solidconnection/mentor/service Expand file tree Collapse file tree 3 files changed +35
-14
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,9 @@ public void updateMentor(Mentor mentor) {
5555 this .mentor = mentor ;
5656 }
5757
58- public void updateType (ChannelType type ) {
59- this .type = type ;
60- }
61-
62- public void updateUrl (String url ) {
63- this .url = url ;
58+ public void update (Channel channel ) {
59+ this .sequence = channel .sequence ;
60+ this .type = channel .type ;
61+ this .url = channel .url ;
6462 }
6563}
Original file line number Diff line number Diff line change @@ -64,16 +64,20 @@ public void updatePassTip(String passTip) {
6464 this .passTip = passTip ;
6565 }
6666
67- public void updateChannels (List <Channel > newChannels ) {
68- for (int i = 0 ; i < newChannels .size (); i ++) {
69- Channel newChannel = newChannels .get (i );
70- if (i < this .channels .size ()) {
67+ public void updateChannels (List <Channel > channels ) {
68+ int newChannelSize = Math .max (channels .size (), this .channels .size ());
69+ int originalChannelSize = this .channels .size ();
70+ for (int i = 0 ; i < newChannelSize ; i ++) {
71+ if (i < channels .size () && i < this .channels .size ()) { // 기존 채널 수정
7172 Channel existing = this .channels .get (i );
72- existing .updateType (newChannel .getType ());
73- existing .updateUrl (newChannel .getUrl ());
74- } else {
73+ Channel newChannel = channels .get (i );
74+ existing .update (newChannel );
75+ } else if (i < channels .size ()) { // 채널 갯수 늘어남 - 새로운 채널 추가
76+ Channel newChannel = channels .get (i );
7577 newChannel .updateMentor (this );
7678 this .channels .add (newChannel );
79+ } else if (i < originalChannelSize ) { // 채널 갯수 줄어듦 - 기존 채널 삭제
80+ this .channels .remove (this .channels .size () - 1 );
7781 }
7882 }
7983 }
Original file line number Diff line number Diff line change @@ -110,7 +110,26 @@ class 멘토의_마이_페이지를_수정한다 {
110110 }
111111
112112 @ Test
113- void 채널_정보를_수정한다 () {
113+ void 기존보다_적게_채널_정보를_수정한다 () {
114+ // given
115+ channelFixture .채널 (1 , mentor );
116+ channelFixture .채널 (2 , mentor );
117+ channelFixture .채널 (3 , mentor );
118+ channelFixture .채널 (4 , mentor );
119+ List <ChannelRequest > newChannels = List .of (new ChannelRequest (BLOG , "https://blog.com" ));
120+ MentorMyPageUpdateRequest request = new MentorMyPageUpdateRequest ("introduction" , "passTip" , newChannels );
121+
122+ // when
123+ mentorMyPageService .updateMentorMyPage (mentorUser .getId (), request );
124+
125+ // then
126+ List <Channel > updatedChannels = channelRepositoryForTest .findAllByMentorId (mentor .getId ());
127+ assertThat (updatedChannels ).extracting (Channel ::getSequence , Channel ::getType , Channel ::getUrl )
128+ .containsExactlyInAnyOrder (tuple (1 , BLOG , "https://blog.com" ));
129+ }
130+
131+ @ Test
132+ void 기존보다_많게_채널_정보를_수정한다 () {
114133 // given
115134 channelFixture .채널 (1 , mentor );
116135 List <ChannelRequest > newChannels = List .of (
You can’t perform that action at this time.
0 commit comments