-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteCreate.java
More file actions
43 lines (37 loc) · 1.39 KB
/
NoteCreate.java
File metadata and controls
43 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.projectlyrics.server.domain.note.entity;
import com.projectlyrics.server.domain.note.dto.request.NoteCreateRequest;
import com.projectlyrics.server.domain.note.exception.NoLyricsForNoteException;
import com.projectlyrics.server.domain.song.entity.Song;
import com.projectlyrics.server.domain.user.entity.User;
import static com.projectlyrics.server.domain.common.util.DomainUtils.checkNull;
public record NoteCreate(
String content,
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);
validateLyricsForType(request.noteType(), request.lyrics());
return new NoteCreate(
request.content(),
request.lyrics(),
request.background(),
request.status(),
request.noteType(),
publisher,
song
);
}
private static void validateLyricsForType(NoteType noteType, String lyrics) {
if (noteType == NoteType.LYRICS_ANALYSIS && (lyrics == null || lyrics.isBlank())) {
throw new NoLyricsForNoteException();
}
}
}