Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.projectlyrics.server.domain.note.entity.NoteBackground;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

Expand All @@ -12,6 +13,8 @@ public record NoteCreateRequest(
NoteBackground background,
@NotNull
NoteStatus status,
@NotNull(message = "노트 유형이 입력되지 않았습니다.")
NoteType noteType,
Long songId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record NoteDetailResponse(
Long id,
String content,
String status,
String noteType,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
LocalDateTime createdAt,
LyricsGetResponse lyrics,
Expand All @@ -31,6 +32,7 @@ public static NoteDetailResponse of(Note note, List<Comment> comments, Long user
note.getId(),
note.getContent(),
note.getNoteStatus().name(),
note.getNoteType().name(),
note.getCreatedAt(),
LyricsGetResponse.from(note.getLyrics()),
UserGetResponse.from(note.getPublisher()),
Expand All @@ -50,6 +52,7 @@ public static NoteDetailResponse of(Note note, List<Comment> comments, Long user
note.getId(),
note.getContent(),
note.getNoteStatus().name(),
note.getNoteType().name(),
createdAt,
LyricsGetResponse.from(note.getLyrics()),
UserGetResponse.from(note.getPublisher()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public record NoteGetResponse(
Long id,
String content,
String status,
String noteType,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
LocalDateTime createdAt,
LyricsGetResponse lyrics,
Expand All @@ -28,6 +29,7 @@ public static NoteGetResponse of(Note note, Long userId) {
note.getId(),
note.getContent(),
note.getNoteStatus().name(),
note.getNoteType().name(),
note.getCreatedAt(),
LyricsGetResponse.from(note.getLyrics()),
UserGetResponse.from(note.getPublisher()),
Expand All @@ -44,6 +46,7 @@ public static NoteGetResponse of(Note note, Long userId, LocalDateTime createdAt
note.getId(),
note.getContent(),
note.getNoteStatus().name(),
note.getNoteType().name(),
createdAt,
LyricsGetResponse.from(note.getLyrics()),
UserGetResponse.from(note.getPublisher()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class Note extends BaseEntity {
@Enumerated(EnumType.STRING)
private NoteStatus noteStatus;

@Enumerated(EnumType.STRING)
@Column(nullable = false, columnDefinition = "VARCHAR(50) DEFAULT 'FREE'")
private NoteType noteType;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name="lyrics_id")
private Lyrics lyrics;
Expand All @@ -58,12 +62,14 @@ private Note(
String content,
Lyrics lyrics,
NoteStatus noteStatus,
NoteType noteType,
User publisher,
Song song
) {
this.id = id;
this.content = content;
this.noteStatus = noteStatus;
this.noteType = noteType;
this.publisher = publisher;
this.song = song;
addLyrics(lyrics);
Expand All @@ -73,17 +79,19 @@ private Note(
String content,
Lyrics lyrics,
NoteStatus noteStatus,
NoteType noteType,
User publisher,
Song song
) {
this(null, content, lyrics, noteStatus, publisher, song);
this(null, content, lyrics, noteStatus, noteType, publisher, song);
}

public static Note create(NoteCreate noteCreate) {
return new Note(
noteCreate.content(),
Lyrics.of(noteCreate.lyrics(), noteCreate.background()),
noteCreate.status(),
noteCreate.noteType(),
noteCreate.publisher(),
noteCreate.song()
);
Expand All @@ -95,6 +103,7 @@ public static Note createWithId(Long id, NoteCreate noteCreate) {
noteCreate.content(),
Lyrics.of(noteCreate.lyrics(), noteCreate.background()),
noteCreate.status(),
noteCreate.noteType(),
noteCreate.publisher(),
noteCreate.song()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public record NoteCreate(
String lyrics,
NoteBackground background,
NoteStatus status,
NoteType noteType,
User publisher,
Song song
) {

public static NoteCreate from(NoteCreateRequest request, User publisher, Song song) {
checkNull(request.status());
checkNull(request.noteType());
checkNull(publisher);
checkNull(song);

Expand All @@ -25,6 +27,7 @@ public static NoteCreate from(NoteCreateRequest request, User publisher, Song so
request.lyrics(),
request.background(),
request.status(),
request.noteType(),
publisher,
song
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.projectlyrics.server.domain.note.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

@RequiredArgsConstructor
public enum NoteType {

FREE("FREE"),
QUESTION("QUESTION"),
LYRICS_ANALYSIS("LYRICS_ANALYSIS"),
;

private final String type;

@JsonValue
public String getType() {
return type;
}

@JsonCreator
public static NoteType of(String type) {
return Arrays.stream(NoteType.values())
.filter(noteType -> noteType.type.equals(type))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Invalid NoteType: " + type));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.projectlyrics.server.domain.note.dto.request.NoteCreateRequest;
import com.projectlyrics.server.domain.note.entity.Note;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.repository.NoteQueryRepository;
import com.projectlyrics.server.domain.note.service.NoteCommandService;
import com.projectlyrics.server.domain.song.entity.Song;
Expand Down Expand Up @@ -339,6 +340,7 @@ private Note writeNote(Long userId) {
null,
null,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);
return noteCommandService.create(noteCreateRequest, userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.projectlyrics.server.domain.note.entity.NoteBackground;
import com.projectlyrics.server.domain.note.entity.NoteCreate;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.repository.NoteCommandRepository;
import com.projectlyrics.server.domain.note.repository.NoteQueryRepository;
import com.projectlyrics.server.domain.song.entity.Song;
Expand Down Expand Up @@ -75,6 +76,7 @@ void setUp() {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);
note = noteCommandRepository.save(Note.create(NoteCreate.from(noteCreateRequest, user, song)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.projectlyrics.server.domain.note.entity.NoteBackground;
import com.projectlyrics.server.domain.note.entity.NoteCreate;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.repository.NoteCommandRepository;
import com.projectlyrics.server.domain.note.repository.NoteQueryRepository;
import com.projectlyrics.server.domain.song.entity.Song;
Expand Down Expand Up @@ -76,6 +77,7 @@ void setUp() {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);
note = noteCommandRepository.save(Note.create(NoteCreate.from(noteCreateRequest, user, song)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.projectlyrics.server.domain.note.entity.Note;
import com.projectlyrics.server.domain.note.entity.NoteBackground;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.service.NoteCommandService;
import com.projectlyrics.server.domain.song.entity.Song;
import com.projectlyrics.server.domain.song.repository.SongCommandRepository;
Expand Down Expand Up @@ -74,6 +75,7 @@ void setUp() {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song1.getId()
);

Expand All @@ -82,6 +84,7 @@ void setUp() {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song2.getId()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.projectlyrics.server.domain.note.entity.NoteBackground;
import com.projectlyrics.server.domain.note.entity.NoteCreate;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.repository.NoteCommandRepository;
import com.projectlyrics.server.domain.note.repository.NoteQueryRepository;
import com.projectlyrics.server.domain.song.entity.Song;
Expand Down Expand Up @@ -73,6 +74,7 @@ void setUp() {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);
note = noteCommandRepository.save(Note.create(NoteCreate.from(noteCreateRequest, user, song)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.projectlyrics.server.domain.note.entity.NoteBackground;
import com.projectlyrics.server.domain.note.entity.NoteCreate;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.repository.NoteCommandRepository;
import com.projectlyrics.server.domain.note.repository.NoteQueryRepository;
import com.projectlyrics.server.domain.song.entity.Song;
Expand Down Expand Up @@ -67,6 +68,7 @@ void setUp() {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);
note = noteCommandRepository.save(Note.create(NoteCreate.from(noteCreateRequest, user1, song)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.projectlyrics.server.domain.note.entity.Note;
import com.projectlyrics.server.domain.note.entity.NoteBackground;
import com.projectlyrics.server.domain.note.entity.NoteStatus;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.user.entity.ProfileCharacter;
import com.projectlyrics.server.domain.user.entity.User;
import com.projectlyrics.server.support.RestDocsTest;
Expand Down Expand Up @@ -55,6 +56,7 @@ class NoteControllerTest extends RestDocsTest {
"나의 꽃이 피는 날이 올 수 있을까",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
1L
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class NoteCreateTest {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);

Expand All @@ -39,6 +40,7 @@ class NoteCreateTest {
() -> assertThat(result.lyrics()).isEqualTo(request.lyrics()),
() -> assertThat(result.background()).isEqualTo(request.background()),
() -> assertThat(result.status()).isEqualTo(request.status()),
() -> assertThat(result.noteType()).isEqualTo(request.noteType()),
() -> assertThat(result.publisher()).isEqualTo(publisher),
() -> assertThat(result.song()).isEqualTo(song)
);
Expand All @@ -55,6 +57,7 @@ class NoteCreateTest {
null,
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);

Expand All @@ -67,6 +70,7 @@ class NoteCreateTest {
() -> assertThat(result.lyrics()).isEqualTo(request.lyrics()),
() -> assertThat(result.background()).isEqualTo(request.background()),
() -> assertThat(result.status()).isEqualTo(request.status()),
() -> assertThat(result.noteType()).isEqualTo(request.noteType()),
() -> assertThat(result.publisher()).isEqualTo(publisher),
() -> assertThat(result.song()).isEqualTo(song)
);
Expand All @@ -83,6 +87,7 @@ class NoteCreateTest {
"lyrics",
NoteBackground.DEFAULT,
null,
NoteType.FREE,
song.getId()
);

Expand All @@ -102,6 +107,7 @@ class NoteCreateTest {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
song.getId()
);

Expand All @@ -121,11 +127,32 @@ class NoteCreateTest {
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
NoteType.FREE,
1L
);

// when & then
assertThatThrownBy(() -> NoteCreate.from(request, publisher, song))
.isInstanceOf(DomainNullFieldException.class);
}

@Test
void 널_노트_유형에_대해_예외를_발생시켜야_한다() {
// given
Artist artist = ArtistFixture.create();
User publisher = UserFixture.create();
Song song = SongFixture.create(artist);
NoteCreateRequest request = new NoteCreateRequest(
"content",
"lyrics",
NoteBackground.DEFAULT,
NoteStatus.PUBLISHED,
null,
song.getId()
);

// when & then
assertThatThrownBy(() -> NoteCreate.from(request, publisher, song))
.isInstanceOf(DomainNullFieldException.class);
}
}
Loading