Skip to content

Commit 89d452b

Browse files
committed
fix: conflict
2 parents c8cc13b + 335e987 commit 89d452b

12 files changed

Lines changed: 89 additions & 102 deletions

src/main/java/team3/kummit/api/MemberBandResponse.java renamed to src/main/java/team3/kummit/api/profile/MemberBandResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package team3.kummit.api;
1+
package team3.kummit.api.profile;
22

33
import java.util.List;
44

src/main/java/team3/kummit/api/MemberBandResponseDto.java renamed to src/main/java/team3/kummit/api/profile/MemberBandResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package team3.kummit.api;
1+
package team3.kummit.api.profile;
22

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

src/main/java/team3/kummit/api/MemberProfileResponse.java renamed to src/main/java/team3/kummit/api/profile/MemberProfileResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package team3.kummit.api;
1+
package team3.kummit.api.profile;
22

33
import java.time.LocalDate;
44

‎src/main/java/team3/kummit/controller/MemberController.java‎

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.List;
55
import java.util.stream.Collectors;
66

7-
import org.springframework.http.HttpStatus;
87
import org.springframework.http.ResponseEntity;
98
import org.springframework.web.bind.annotation.*;
109

@@ -17,6 +16,10 @@
1716
import lombok.RequiredArgsConstructor;
1817
import lombok.extern.slf4j.Slf4j;
1918
import 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;
2023
import team3.kummit.domain.EmotionBand;
2124
import team3.kummit.domain.Member;
2225
import 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
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package team3.kummit.controller.parser;
2+
3+
import java.util.stream.Collectors;
4+
5+
import org.springframework.stereotype.Component;
6+
7+
import team3.kummit.api.profile.MemberBandResponseDto;
8+
import team3.kummit.api.profile.MemberProfileResponse;
9+
import team3.kummit.domain.EmotionBand;
10+
import team3.kummit.domain.Member;
11+
12+
@Component
13+
public class MemberApiParser {
14+
15+
public MemberProfileResponse mapToMemberProfileResponse(Member member){
16+
return new MemberProfileResponse(
17+
member.getName(),
18+
member.getSignUpDate(),
19+
member.getBandCreateCount(),
20+
member.getBandJoinCount(),
21+
member.getLikeCount(),
22+
member.getSongAddCount());
23+
}
24+
25+
public MemberBandResponseDto mapToMemberBandResponse(EmotionBand band){
26+
return new MemberBandResponseDto(
27+
band.getEmotion(),
28+
band.getCreatorName(),
29+
band.getDescription(),
30+
band.getSongs().stream()
31+
.map(song -> new MemberBandResponseDto.Music(
32+
song.getAlbumImageLink(),
33+
song.getTitle(),
34+
song.getArtist(),
35+
song.getPreviewLink()
36+
))
37+
.collect(Collectors.toList()),
38+
band.getLikeCount(),
39+
band.getPeopleCount(),
40+
band.getSongCount(),
41+
band.getCommentCount(),
42+
band.getEndTime()
43+
);
44+
}
45+
}

‎src/main/java/team3/kummit/domain/Member.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ public class Member {
3030
public void incrementBandCreateCount() {
3131
this.bandCreateCount++;
3232
}
33-
public void incrementSongAddCount() {
34-
this.songAddCount++;
35-
}
3633
public void incrementBandJoinCount() {
3734
this.bandJoinCount++;
3835
}
36+
public void incrementLikeCount() {
37+
this.likeCount++;
38+
}
39+
public void incrementSongAddCount() {
40+
this.songAddCount++;
41+
}
3942
public void decrementBandJoinCount() {
4043
this.bandJoinCount--;
4144
}

‎src/main/java/team3/kummit/repository/EmotionBandArchiveRepository.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ public interface EmotionBandArchiveRepository extends JpaRepository<EmotionBandA
1717
@Query("SELECT eba.emotionBand.id FROM EmotionBandArchive eba WHERE eba.creator.id = :memberId")
1818
List<Long> findEmotionBandIdListByMemberId(@Param("memberId") Long memberId);
1919

20-
@Query("SELECT eb.id FROM EmotionBand eb where eb.creator.id =:memberId")
21-
List<Long> findEmotionBandIdListByCreator(Long memberId);
2220
}

‎src/main/java/team3/kummit/repository/EmotionBandLikeRepository.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111

1212
public interface EmotionBandLikeRepository extends JpaRepository<EmotionBandLike, Long> {
1313
Optional<EmotionBandLike> findByCreatorIdAndEmotionBandId(Long memberId, Long emotionBandId);
14-
Long countByEmotionBandId(Long emotionBandId);
1514

1615
// 사용자가 공감한 밴드 ID 목록 조회
1716
@Query("SELECT ebl.emotionBand.id FROM EmotionBandLike ebl WHERE ebl.creator.id = :memberId")
1817
List<Long> findEmotionBandIdListByMemberId(@Param("memberId") Long memberId);
1918

20-
@Query("SELECT eb.id FROM EmotionBand eb where eb.creator.id =:memberId")
21-
List<Long> findEmotionBandIdListByCreator(Long memberId);
2219
}

‎src/main/java/team3/kummit/repository/EmotionBandRepository.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@
55

66
import org.springframework.data.jpa.repository.JpaRepository;
77
import org.springframework.data.jpa.repository.Query;
8-
import org.springframework.data.repository.query.Param;
98

109
import team3.kummit.domain.EmotionBand;
1110

1211
public interface EmotionBandRepository extends JpaRepository<EmotionBand, Long> {
1312

1413
// 현재 시간이 endTime을 지나지 않은 밴드들 중 좋아요 수 기준 상위 3개
1514
@Query("SELECT e FROM EmotionBand e WHERE e.endTime > :currentTime ORDER BY e.likeCount DESC")
16-
List<EmotionBand> findTop3ByLikeCountAndEndTimeAfter(@Param("currentTime") LocalDateTime currentTime);
15+
List<EmotionBand> findAllByLikeCountAndEndTimeAfter(LocalDateTime currentTime);
1716

18-
// 현재 시간이 endTime을 지나지 않은 밴드들 중 endTime 기준 최신순 상위 10개
17+
// 현재 시간이 endTime을 지나지 않은 밴드들 중 endTime 기준 최신순
1918
@Query("SELECT e FROM EmotionBand e WHERE e.endTime > :currentTime ORDER BY e.endTime DESC")
20-
List<EmotionBand> findTop10ByEndTimeDescAndEndTimeAfter(@Param("currentTime") LocalDateTime currentTime);
19+
List<EmotionBand> findAllByEndTimeDescAndEndTimeAfter(LocalDateTime currentTime);
2120

2221
@Query("SELECT eb.id FROM EmotionBand eb where eb.creator.id =:memberId")
23-
List<Long> findEmotionBandIdListByCreator(Long memberId);
22+
List<Long> findPkListByCreator(Long memberId);
2423

2524
@Query("SELECT eb FROM EmotionBand eb left join fetch eb.songs ebs " +
2625
"WHERE eb.endTime > :currentTime and eb.id in :emotionBandIdList")
27-
List<EmotionBand> findAllByEmotionBandIdList(List<Long> emotionBandIdList, LocalDateTime currentTime);
26+
List<EmotionBand> findAllByEmotionBandIdListWithSongs(List<Long> emotionBandIdList, LocalDateTime currentTime);
2827

2928

3029
}

‎src/main/java/team3/kummit/service/EmotionBandService.java‎

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public EmotionBandListResponse getEmotionBandLists(Long memberId) {
5959
LocalDateTime currentTime = LocalDateTime.now();
6060

6161
// 인기 밴드 조회 (좋아요 수 기준 상위 3개)
62-
List<EmotionBand> popularBands = emotionBandRepository.findTop3ByLikeCountAndEndTimeAfter(currentTime);
62+
List<EmotionBand> popularBands = emotionBandRepository.findAllByLikeCountAndEndTimeAfter(currentTime);
6363
List<EmotionBandResponse> popularBandResponses = popularBands.stream()
6464
.limit(3) // 최대 3개만
6565
.map(band -> {
@@ -73,7 +73,7 @@ public EmotionBandListResponse getEmotionBandLists(Long memberId) {
7373
.collect(Collectors.toList());
7474

7575
// 전체 밴드 조회 (최신순 상위 10개)
76-
List<EmotionBand> allBands = emotionBandRepository.findTop10ByEndTimeDescAndEndTimeAfter(currentTime);
76+
List<EmotionBand> allBands = emotionBandRepository.findAllByEndTimeDescAndEndTimeAfter(currentTime);
7777
List<EmotionBandResponse> allBandResponses = allBands.stream()
7878
.limit(10) // 최대 10개만
7979
.map(band -> {
@@ -92,19 +92,6 @@ public EmotionBandListResponse getEmotionBandLists(Long memberId) {
9292
.build();
9393
}
9494

95-
@Transactional(readOnly = true)
96-
public EmotionBandResponse getEmotionBand(Long emotionBandId, Long memberId) {
97-
EmotionBand band = emotionBandRepository.findById(emotionBandId)
98-
.orElseThrow(() -> new ResourceNotFoundException("감정밴드를 찾을 수 없습니다."));
99-
100-
boolean isLiked = memberId != null && emotionBandLikeService.isLiked(emotionBandId, memberId);
101-
List<SongResponse> songs = songRepository.findByEmotionBandIdOrderByCreatedAtDesc(emotionBandId)
102-
.stream()
103-
.map(SongResponse::from)
104-
.collect(Collectors.toList());
105-
return EmotionBandResponse.from(band, isLiked, songs);
106-
}
107-
10895
@Transactional(readOnly = true)
10996
public EmotionBandDetailResponse getEmotionBandDetail(Long emotionBandId, Long memberId) {
11097
// 감정밴드 조회
@@ -129,12 +116,11 @@ public EmotionBandDetailResponse getEmotionBandDetail(Long emotionBandId, Long m
129116
return EmotionBandDetailResponse.from(emotionBand, songs, comments, isArchived, isLiked);
130117
}
131118

132-
133-
public List<Long> findEmotionBandIdListByCreator(Long memberId){
134-
return emotionBandRepository.findEmotionBandIdListByCreator(memberId);
119+
public List<Long> findEmotionBandIdListByMemberId(Long memberId){
120+
return emotionBandRepository.findPkListByCreator(memberId);
135121
}
136122

137-
public List<EmotionBand> findAllByEmotionBandIdList(List<Long> emotionBandIdList){
138-
return emotionBandRepository.findAllByEmotionBandIdList(emotionBandIdList, LocalDateTime.now());
123+
public List<EmotionBand> findAllByEmotionBandIdListWithSongs(List<Long> emotionBandIdList){
124+
return emotionBandRepository.findAllByEmotionBandIdListWithSongs(emotionBandIdList, LocalDateTime.now());
139125
}
140126
}

0 commit comments

Comments
 (0)