Skip to content

Commit 8680d40

Browse files
authored
merge: pull request #34 from feat/emotionRecord/main
Feat/emotion record/main
2 parents e817ea0 + 43849f1 commit 8680d40

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

src/main/java/org/dfbf/soundlink/domain/emotionRecord/dto/request/EmotionRecordRequestDTO.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import jakarta.validation.constraints.Size;
66
import org.dfbf.soundlink.global.comm.enums.Emotions;
77

8-
import java.sql.Timestamp;
9-
108
public record EmotionRecordRequestDTO(
119

1210
@NotNull(message = "spotifyId 필요")
13-
Long spotifyId,
11+
String spotifyId,
1412

1513
@NotBlank(message = "title 필요")
1614
String title,
@@ -25,8 +23,6 @@ public record EmotionRecordRequestDTO(
2523

2624
@NotBlank(message = "comment 필요")
2725
@Size(max = 200, message = "comment는 200자 이내여야 합니다.")
28-
String comment,
29-
30-
Timestamp createAt
26+
String comment
3127
) {
3228
}

src/main/java/org/dfbf/soundlink/domain/emotionRecord/dto/request/EmotionRecordUpdateRequestDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.dfbf.soundlink.domain.emotionRecord.dto.request;
22

33
public record EmotionRecordUpdateRequestDTO(
4-
Long spotifyId,
4+
String spotifyId,
55
String title,
66
String artist,
77
String albumImage,

src/main/java/org/dfbf/soundlink/domain/emotionRecord/dto/response/EmotionRecordResponseWithOwnerDTO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public record EmotionRecordResponseWithOwnerDTO(
99
Long recordId,
1010
String nickName,
11+
String loginId,
1112
String emotion,
1213
SpotifyMusicResponseDTO spotifyMusic,
1314
String comment,
@@ -18,6 +19,7 @@ public static EmotionRecordResponseWithOwnerDTO fromEntity(EmotionRecord record,
1819
return new EmotionRecordResponseWithOwnerDTO(
1920
record.getRecordId(),
2021
record.getUser().getNickname(),
22+
record.getUser().getLoginId(),
2123
record.getEmotion().name(),
2224
record.getSpotifyMusic() != null ? SpotifyMusicResponseDTO.fromEntity(record.getSpotifyMusic()) : null,
2325
record.getComment(),

src/main/java/org/dfbf/soundlink/domain/emotionRecord/dto/response/EmotionRecordUpdateResponseDTO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public record EmotionRecordUpdateResponseDTO(
66
Long recordId,
7-
String spotifyId,
7+
Long spotifyId,
88
String title,
99
String artist,
1010
String albumImage,
@@ -14,7 +14,7 @@ public record EmotionRecordUpdateResponseDTO(
1414
public static EmotionRecordUpdateResponseDTO fromEntity(EmotionRecord record) {
1515
return new EmotionRecordUpdateResponseDTO(
1616
record.getRecordId(),
17-
String.valueOf(record.getSpotifyMusic().getSpotifyId()),
17+
record.getSpotifyMusic().getSpotifyId(),
1818
record.getSpotifyMusic().getTitle(),
1919
record.getSpotifyMusic().getArtist(),
2020
record.getSpotifyMusic().getAlbumImage(),

src/main/java/org/dfbf/soundlink/domain/emotionRecord/dto/response/SpotifyMusicResponseDTO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import org.dfbf.soundlink.domain.emotionRecord.entity.SpotifyMusic;
44

5-
public record SpotifyMusicResponseDTO(String spotifyId, String title, String artist, String albumImage) {
5+
public record SpotifyMusicResponseDTO(Long spotifyId, String title, String artist, String albumImage) {
66
public static SpotifyMusicResponseDTO fromEntity(SpotifyMusic music) {
77
return new SpotifyMusicResponseDTO(
8-
String.valueOf(music.getSpotifyId()),
8+
music.getSpotifyId(),
99
music.getTitle(),
1010
music.getArtist(),
1111
music.getAlbumImage()

src/main/java/org/dfbf/soundlink/domain/emotionRecord/entity/EmotionRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class EmotionRecord {
2828
private Emotions emotion;
2929

3030
@ManyToOne
31-
@JoinColumn(name = "spotify_music_id")
31+
@JoinColumn(name = "spotify_id")
3232
private SpotifyMusic spotifyMusic;
3333

3434
@Column(name = "comment")

src/main/java/org/dfbf/soundlink/domain/emotionRecord/service/EmotionRecordService.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,24 @@ public ResponseResult saveEmotionRecordWithMusic(Long userId, EmotionRecordReque
4141
.orElseThrow(UserNotFoundException::new);
4242

4343
try {
44-
// 감정 기록 저장
45-
EmotionRecord emotionRecord = EmotionRecord.builder()
46-
.user(loggedInUser)
47-
.emotion(request.emotion())
48-
.comment(request.comment())
49-
.build();
50-
emotionRecordRepository.save(emotionRecord);
51-
5244
// 음악 저장
5345
SpotifyMusic spotifyMusic = SpotifyMusic.builder()
54-
.spotifyId(request.spotifyId())
46+
.spotifyId(Long.valueOf(request.spotifyId()))
5547
.title(request.title())
5648
.artist(request.artist())
5749
.albumImage(request.albumImage())
5850
.build();
5951
spotifyMusicRepository.save(spotifyMusic);
6052

53+
// 감정 기록 저장
54+
EmotionRecord emotionRecord = EmotionRecord.builder()
55+
.user(loggedInUser)
56+
.emotion(request.emotion())
57+
.comment(request.comment())
58+
.spotifyMusic(spotifyMusic)
59+
.build();
60+
emotionRecordRepository.save(emotionRecord);
61+
6162
return new ResponseResult(ErrorCode.SUCCESS);
6263
} catch (UserNotFoundException e) {
6364
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
@@ -133,10 +134,10 @@ public ResponseResult updateEmotionRecord(Long recordId, EmotionRecordUpdateRequ
133134
// SpotifyMusic이 DB에 있는지 먼저 확인
134135
// SpotifyMusic 엔티티가 저장되지 않은 상태에서 EmotionRecord 저장 시 영속성 컨텍스트 미저장 오류 발생
135136
// EmotionRecord를 업데이트하기 전에 SpotifyMusic이 없다면 생성 후 먼저 저장해줘야 함
136-
SpotifyMusic spotifyMusic = spotifyMusicRepository.findById(updateDTO.spotifyId())
137+
SpotifyMusic spotifyMusic = spotifyMusicRepository.findById(Long.valueOf(updateDTO.spotifyId()))
137138
.orElseGet(() -> {
138139
SpotifyMusic newMusic = new SpotifyMusic(
139-
updateDTO.spotifyId(),
140+
Long.valueOf(updateDTO.spotifyId()),
140141
updateDTO.title(),
141142
updateDTO.artist(),
142143
updateDTO.albumImage()

0 commit comments

Comments
 (0)