44import java .util .List ;
55import java .util .stream .Collectors ;
66
7- import org .springframework .http .HttpStatus ;
87import org .springframework .http .ResponseEntity ;
98import org .springframework .web .bind .annotation .*;
109
1716import lombok .RequiredArgsConstructor ;
1817import lombok .extern .slf4j .Slf4j ;
1918import team3 .kummit .api .*;
19+ import team3 .kummit .api .profile .MemberBandResponse ;
20+ import team3 .kummit .api .profile .MemberBandResponseDto ;
21+ import team3 .kummit .api .profile .MemberProfileResponse ;
22+ import team3 .kummit .controller .parser .MemberApiParser ;
2023import team3 .kummit .domain .EmotionBand ;
2124import team3 .kummit .domain .Member ;
2225import team3 .kummit .service .EmotionBandArchiveService ;
@@ -36,6 +39,7 @@ public class MemberController {
3639 private final EmotionBandService emotionBandService ;
3740 private final EmotionBandLikeService emotionBandLikeService ;
3841 private final EmotionBandArchiveService emotionBandArchiveService ;
42+ private final MemberApiParser memberApiParser ;
3943
4044
4145 @ Operation (
@@ -50,9 +54,8 @@ public class MemberController {
5054 public ResponseEntity <MemberLoginResponse > memberLogin (
5155 @ Parameter (description = "로그인 요청 데이터 (이메일과 비밀번호 포함)" )
5256 @ RequestBody MemberLoginRequest memberLoginRequest ) {
53- return memberService .findByName (memberLoginRequest .name ())
54- .map (member -> ResponseEntity .ok (new MemberLoginResponse (member .getId ())))
55- .orElse (ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ());
57+ Member member = memberService .findByName (memberLoginRequest .name ());
58+ return ResponseEntity .ok (new MemberLoginResponse (member .getId ()));
5659 }
5760
5861 @ Operation (
@@ -70,13 +73,7 @@ public ResponseEntity<MemberLoginResponse> memberLogin(
7073 public ResponseEntity <MemberProfileResponse > memberProfileGet (
7174 @ Parameter (description = "사용자 ID" ) @ RequestParam Long memberId ) {
7275 Member member = memberService .findById (memberId );
73- return ResponseEntity .status (HttpStatus .CREATED ).body (new MemberProfileResponse (
74- member .getName (),
75- member .getSignUpDate (),
76- member .getBandCreateCount () != null ? member .getBandCreateCount () : 0 ,
77- member .getBandJoinCount () != null ? member .getBandJoinCount () : 0 ,
78- member .getLikeCount () != null ? member .getLikeCount () : 0 ,
79- member .getSongAddCount () != null ? member .getSongAddCount () : 0 ));
76+ return ResponseEntity .ok (memberApiParser .mapToMemberProfileResponse (member ));
8077 }
8178
8279 @ Operation (
@@ -93,9 +90,9 @@ public ResponseEntity<MemberProfileResponse> memberProfileGet(
9390 @ GetMapping ("/my-band" )
9491 public ResponseEntity <MemberBandResponse > memberMyBand (
9592 @ Parameter (description = "사용자 ID" ) @ RequestParam Long memberId ) {
96- List <Long > bandIdListOfMember = emotionBandService .findEmotionBandIdListByCreator (memberId );
97- List <EmotionBand > allByEmotionBandIdList = emotionBandService .findAllByEmotionBandIdList (bandIdListOfMember );
98- List <MemberBandResponseDto > collect = allByEmotionBandIdList .stream ().map (this :: toDto ).collect (Collectors .toList ());
93+ List <Long > bandIdListOfMember = emotionBandService .findEmotionBandIdListByMemberId (memberId );
94+ List <EmotionBand > allByEmotionBandIdList = emotionBandService .findAllByEmotionBandIdListWithSongs (bandIdListOfMember );
95+ List <MemberBandResponseDto > collect = allByEmotionBandIdList .stream ().map (memberApiParser :: mapToMemberBandResponse ).collect (Collectors .toList ());
9996 return ResponseEntity .ok (new MemberBandResponse (collect ));
10097 }
10198
@@ -114,8 +111,8 @@ public ResponseEntity<MemberBandResponse> memberMyBand(
114111 public ResponseEntity <MemberBandResponse > memberLikeBand (
115112 @ Parameter (description = "사용자 ID" ) @ RequestParam Long memberId ) {
116113 List <Long > bandIdListOfMember = emotionBandLikeService .findEmotionBandListByMemberId (memberId );
117- List <EmotionBand > allByEmotionBandIdList = emotionBandService .findAllByEmotionBandIdList (bandIdListOfMember );
118- List <MemberBandResponseDto > collect = allByEmotionBandIdList .stream ().map (this :: toDto ).collect (Collectors .toList ());
114+ List <EmotionBand > allByEmotionBandIdList = emotionBandService .findAllByEmotionBandIdListWithSongs (bandIdListOfMember );
115+ List <MemberBandResponseDto > collect = allByEmotionBandIdList .stream ().map (memberApiParser :: mapToMemberBandResponse ).collect (Collectors .toList ());
119116 return ResponseEntity .ok (new MemberBandResponse (collect ));
120117 }
121118
@@ -135,46 +132,10 @@ public ResponseEntity<MemberBandResponse> memberLikeBand(
135132 public ResponseEntity <MemberBandResponse > memberArchiveBand (
136133 @ Parameter (description = "사용자 ID" ) @ RequestParam Long memberId ) {
137134 List <Long > bandIdListOfMember = emotionBandArchiveService .findArchivedEmotionBandIdsByMember (memberId );
138- List <EmotionBand > allByEmotionBandIdList = emotionBandService .findAllByEmotionBandIdList (bandIdListOfMember );
139- List <MemberBandResponseDto > collect = allByEmotionBandIdList .stream ().map (this :: toDto ).collect (Collectors .toList ());
135+ List <EmotionBand > allByEmotionBandIdList = emotionBandService .findAllByEmotionBandIdListWithSongs (bandIdListOfMember );
136+ List <MemberBandResponseDto > collect = allByEmotionBandIdList .stream ().map (memberApiParser :: mapToMemberBandResponse ).collect (Collectors .toList ());
140137 return ResponseEntity .ok (new MemberBandResponse (collect ));
141138 }
142139
143140
144- private MemberBandResponseDto toDto (EmotionBand band ) {
145- return new MemberBandResponseDto (
146- band .getEmotion (),
147- band .getCreatorName (),
148- band .getDescription (),
149- band .getSongs ().stream ()
150- .map (song -> new MemberBandResponseDto .Music (
151- song .getAlbumImageLink (),
152- song .getTitle (),
153- song .getArtist (),
154- song .getPreviewLink ()
155- ))
156- .collect (Collectors .toList ()),
157- band .getLikeCount (),
158- band .getPeopleCount (),
159- band .getSongCount (),
160- band .getCommentCount (),
161- band .getEndTime ()
162- );
163- }
164-
165-
166-
167-
168-
169-
170-
171-
172-
173-
174-
175-
176-
177-
178-
179-
180141}
0 commit comments