Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ application*.yml

gradle.properties
src/main/resources/firebase-key.json
*.lck
*.part
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.projectlyrics.server.domain.note.dto.response.NoteDetailResponse;
import com.projectlyrics.server.domain.note.dto.response.NoteGetResponse;
import com.projectlyrics.server.domain.note.dto.response.NoteUpdateResponse;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.service.NoteCommandService;
import com.projectlyrics.server.domain.note.service.NoteQueryService;
import com.projectlyrics.server.domain.view.service.ViewCommandService;
Expand Down Expand Up @@ -96,10 +97,11 @@ public ResponseEntity<CursorBasePaginatedResponse<NoteGetResponse>> getNotesOfUs
@Authenticated AuthContext authContext,
@RequestParam(name = "hasLyrics") boolean hasLyrics,
@RequestParam(name = "artistId", required = false) Long artistId,
@RequestParam(name = "noteType", required = false) NoteType noteType,
@RequestParam(name = "cursor", required = false) Long cursor,
@RequestParam(name = "size", defaultValue = "10") int size
) {
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotesByUserId(hasLyrics, artistId, authContext.getId(), cursor, size);
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotesByUserId(hasLyrics, artistId, noteType, authContext.getId(), cursor, size);

return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -111,10 +113,11 @@ public ResponseEntity<CursorBasePaginatedResponse<NoteGetResponse>> getNotes(
@Authenticated AuthContext authContext,
@RequestParam(name = "hasLyrics") boolean hasLyrics,
@RequestParam(name = "isFavoriteArtistsOnly", defaultValue = "false") boolean isFavoriteArtistsOnly,
@RequestParam(name = "noteType", required = false) NoteType noteType,
@RequestParam(name = "cursor", required = false) Long cursor,
@RequestParam(name = "size", defaultValue = "10") int size
) {
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotes(hasLyrics, isFavoriteArtistsOnly, authContext.getId(), cursor, size);
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotes(hasLyrics, isFavoriteArtistsOnly, noteType, authContext.getId(), cursor, size);

return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -126,10 +129,11 @@ public ResponseEntity<CursorBasePaginatedResponse<NoteGetResponse>> getNotesOfAr
@Authenticated AuthContext authContext,
@RequestParam(name = "hasLyrics") boolean hasLyrics,
@RequestParam(name = "artistId") Long artistId,
@RequestParam(name = "noteType", required = false) NoteType noteType,
@RequestParam(name = "cursor", required = false) Long cursor,
@RequestParam(name = "size", defaultValue = "10") int size
) {
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotesByArtistId(hasLyrics, artistId, authContext.getId(), cursor, size);
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotesByArtistId(hasLyrics, artistId, noteType, authContext.getId(), cursor, size);

return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -141,10 +145,11 @@ public ResponseEntity<CursorBasePaginatedResponse<NoteGetResponse>> getNotesOfSo
@Authenticated AuthContext authContext,
@RequestParam(name = "hasLyrics") boolean hasLyrics,
@RequestParam(name = "songId") Long songId,
@RequestParam(name = "noteType", required = false) NoteType noteType,
@RequestParam(name = "cursor", required = false) Long cursor,
@RequestParam(name = "size", defaultValue = "10") int size
) {
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotesBySongId(hasLyrics, songId, authContext.getId(), cursor, size);
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getNotesBySongId(hasLyrics, songId, noteType, authContext.getId(), cursor, size);

return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -156,10 +161,11 @@ public ResponseEntity<CursorBasePaginatedResponse<NoteGetResponse>> getNotesBook
@Authenticated AuthContext authContext,
@RequestParam(name = "hasLyrics") boolean hasLyrics,
@RequestParam(name = "artistId", required = false) Long artistId,
@RequestParam(name = "noteType", required = false) NoteType noteType,
@RequestParam(name = "cursor", required = false) Long cursor,
@RequestParam(name = "size", defaultValue = "10") int size
) {
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getBookmarkedNotes(hasLyrics, artistId, authContext.getId(), cursor, size);
CursorBasePaginatedResponse<NoteGetResponse> response = noteQueryService.getBookmarkedNotes(hasLyrics, artistId, noteType, authContext.getId(), cursor, size);

return ResponseEntity
.status(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public String getType() {
@JsonCreator
public static NoteType of(String type) {
return Arrays.stream(NoteType.values())
.filter(noteType -> noteType.type.equals(type))
.filter(noteType -> noteType.type.equalsIgnoreCase(type))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Invalid NoteType: " + type));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.projectlyrics.server.domain.note.repository;

import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.entity.Note;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
Expand All @@ -10,12 +11,12 @@ public interface NoteQueryRepository {

Note findById(Long id);

Slice<Note> findAllByUserId(boolean hasLyrics, Long artistId, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllByArtistIds(boolean hasLyrics, List<Long> artistsIds, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAll(boolean hasLyrics, List<Long> artistsIds, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllByArtistId(boolean hasLyrics, Long artistId, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllBookmarkedAndByArtistId(boolean hasLyrics, Long artistId, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllBySongId(boolean hasLyrics, Long songId, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllByUserId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllByArtistIds(boolean hasLyrics, List<Long> artistsIds, NoteType noteType, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAll(boolean hasLyrics, List<Long> artistsIds, NoteType noteType, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllByArtistId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllBookmarkedAndByArtistId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursorId, Pageable pageable);
Slice<Note> findAllBySongId(boolean hasLyrics, Long songId, NoteType noteType, Long userId, Long cursorId, Pageable pageable);

long countDraftNotesByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.projectlyrics.server.domain.common.util.QueryDslUtils;
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.exception.NoteNotFoundException;
import com.projectlyrics.server.domain.note.repository.NoteQueryRepository;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;

Expand Down Expand Up @@ -50,7 +52,7 @@ public Note findById(Long id) {
}

@Override
public Slice<Note> findAllByUserId(boolean hasLyrics, Long artistId, Long userId, Long cursorId, Pageable pageable) {
public Slice<Note> findAllByUserId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursorId, Pageable pageable) {
List<Note> content = jpaQueryFactory
.selectFrom(note)
.leftJoin(note.lyrics).fetchJoin()
Expand All @@ -61,6 +63,7 @@ public Slice<Note> findAllByUserId(boolean hasLyrics, Long artistId, Long userId
.where(
hasLyrics(hasLyrics),
artistId == null ? null : artist.id.eq(artistId),
hasNoteType(noteType),
note.publisher.deletedAt.isNull(),
note.publisher.id.eq(userId),
note.deletedAt.isNull(),
Expand All @@ -79,7 +82,7 @@ public Slice<Note> findAllByUserId(boolean hasLyrics, Long artistId, Long userId
}

@Override
public Slice<Note> findAllByArtistIds(boolean hasLyrics, List<Long> artistsIds, Long userId, Long cursorId, Pageable pageable) {
public Slice<Note> findAllByArtistIds(boolean hasLyrics, List<Long> artistsIds, NoteType noteType, Long userId, Long cursorId, Pageable pageable) {
List<Note> content = jpaQueryFactory
.selectFrom(note)
.leftJoin(note.lyrics).fetchJoin()
Expand All @@ -90,6 +93,7 @@ public Slice<Note> findAllByArtistIds(boolean hasLyrics, List<Long> artistsIds,
.where(
hasLyrics(hasLyrics),
note.song.artist.id.in(artistsIds),
hasNoteType(noteType),
note.deletedAt.isNull(),
QueryDslUtils.ltCursorId(cursorId, note.id),
note.publisher.notIn(
Expand All @@ -106,7 +110,7 @@ public Slice<Note> findAllByArtistIds(boolean hasLyrics, List<Long> artistsIds,
}

@Override
public Slice<Note> findAll(boolean hasLyrics, List<Long> artistsIds, Long userId, Long cursorId, Pageable pageable) {
public Slice<Note> findAll(boolean hasLyrics, List<Long> artistsIds, NoteType noteType, Long userId, Long cursorId, Pageable pageable) {
List<Note> content = jpaQueryFactory
.selectFrom(note)
.leftJoin(note.lyrics).fetchJoin()
Expand All @@ -117,6 +121,7 @@ public Slice<Note> findAll(boolean hasLyrics, List<Long> artistsIds, Long userId
.where(
hasLyrics(hasLyrics),
artistsIds == null || artistsIds.isEmpty() ? null : note.song.artist.id.in(artistsIds),
hasNoteType(noteType),
note.deletedAt.isNull(),
QueryDslUtils.ltCursorId(cursorId, note.id),
note.publisher.notIn(
Expand All @@ -133,7 +138,7 @@ public Slice<Note> findAll(boolean hasLyrics, List<Long> artistsIds, Long userId
}

@Override
public Slice<Note> findAllByArtistId(boolean hasLyrics, Long artistId, Long userId, Long cursorId, Pageable pageable) {
public Slice<Note> findAllByArtistId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursorId, Pageable pageable) {
List<Note> content = jpaQueryFactory
.selectFrom(note)
.leftJoin(note.lyrics).fetchJoin()
Expand All @@ -144,6 +149,7 @@ public Slice<Note> findAllByArtistId(boolean hasLyrics, Long artistId, Long user
.where(
hasLyrics(hasLyrics),
note.song.artist.id.eq(artistId),
hasNoteType(noteType),
note.deletedAt.isNull(),
QueryDslUtils.ltCursorId(cursorId, note.id),
note.publisher.notIn(
Expand All @@ -160,7 +166,7 @@ public Slice<Note> findAllByArtistId(boolean hasLyrics, Long artistId, Long user
}

@Override
public Slice<Note> findAllBySongId(boolean hasLyrics, Long songId, Long userId, Long cursorId, Pageable pageable) {
public Slice<Note> findAllBySongId(boolean hasLyrics, Long songId, NoteType noteType, Long userId, Long cursorId, Pageable pageable) {
List<Note> content = jpaQueryFactory
.selectFrom(note)
.leftJoin(note.lyrics).fetchJoin()
Expand All @@ -171,6 +177,7 @@ public Slice<Note> findAllBySongId(boolean hasLyrics, Long songId, Long userId,
.where(
hasLyrics(hasLyrics),
note.song.id.eq(songId),
hasNoteType(noteType),
note.deletedAt.isNull(),
QueryDslUtils.ltCursorId(cursorId, note.id),
note.publisher.notIn(
Expand All @@ -187,7 +194,7 @@ public Slice<Note> findAllBySongId(boolean hasLyrics, Long songId, Long userId,
}

@Override
public Slice<Note> findAllBookmarkedAndByArtistId(boolean hasLyrics, Long artistId, Long userId, Long cursorId, Pageable pageable) {
public Slice<Note> findAllBookmarkedAndByArtistId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursorId, Pageable pageable) {
List<Note> content = jpaQueryFactory
.selectFrom(note)
.leftJoin(note.lyrics).fetchJoin()
Expand All @@ -200,6 +207,7 @@ public Slice<Note> findAllBookmarkedAndByArtistId(boolean hasLyrics, Long artist
.and(bookmark.deletedAt.isNull()),
hasLyrics(hasLyrics),
artistId == null ? null : note.song.artist.id.eq(artistId),
hasNoteType(noteType),
note.deletedAt.isNull(),
QueryDslUtils.ltCursorId(cursorId, note.id),
note.publisher.notIn(
Expand Down Expand Up @@ -229,4 +237,8 @@ public long countDraftNotesByUserId(Long userId) {
.fetchOne()
).orElse(0L);
}

private BooleanExpression hasNoteType(NoteType noteType) {
return noteType == null ? null : note.noteType.eq(noteType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.projectlyrics.server.domain.note.dto.response.NoteDetailResponse;
import com.projectlyrics.server.domain.note.dto.response.NoteGetResponse;
import com.projectlyrics.server.domain.note.entity.Note;
import com.projectlyrics.server.domain.note.entity.NoteType;
import com.projectlyrics.server.domain.note.repository.NoteQueryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
Expand All @@ -32,14 +33,14 @@ public NoteDetailResponse getNoteById(Long noteId, Long userId) {
return NoteDetailResponse.of(note, comments, userId);
}

public CursorBasePaginatedResponse<NoteGetResponse> getNotesByUserId(boolean hasLyrics, Long artistId, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllByUserId(hasLyrics, artistId, userId, cursor, PageRequest.ofSize(size))
public CursorBasePaginatedResponse<NoteGetResponse> getNotesByUserId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllByUserId(hasLyrics, artistId, noteType, userId, cursor, PageRequest.ofSize(size))
.map(note -> NoteGetResponse.of(note, userId));

return CursorBasePaginatedResponse.of(notes);
}

public CursorBasePaginatedResponse<NoteGetResponse> getNotes(boolean hasLyrics, boolean isFavoriteArtistsOnly, Long userId, Long cursor, int size) {
public CursorBasePaginatedResponse<NoteGetResponse> getNotes(boolean hasLyrics, boolean isFavoriteArtistsOnly, NoteType noteType, Long userId, Long cursor, int size) {
List<Long> artistsIds = null;
if (isFavoriteArtistsOnly) {
artistsIds = favoriteArtistQueryRepository.findAllByUserIdFetchArtist(userId)
Expand All @@ -48,28 +49,28 @@ public CursorBasePaginatedResponse<NoteGetResponse> getNotes(boolean hasLyrics,
.toList();
}

Slice<NoteGetResponse> notes = noteQueryRepository.findAll(hasLyrics, artistsIds, userId, cursor, PageRequest.ofSize(size))
Slice<NoteGetResponse> notes = noteQueryRepository.findAll(hasLyrics, artistsIds, noteType, userId, cursor, PageRequest.ofSize(size))
.map(note -> NoteGetResponse.of(note, userId));

return CursorBasePaginatedResponse.of(notes);
}

public CursorBasePaginatedResponse<NoteGetResponse> getNotesByArtistId(boolean hasLyrics, Long artistId, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllByArtistId(hasLyrics, artistId, userId, cursor, PageRequest.ofSize(size))
public CursorBasePaginatedResponse<NoteGetResponse> getNotesByArtistId(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllByArtistId(hasLyrics, artistId, noteType, userId, cursor, PageRequest.ofSize(size))
.map(note -> NoteGetResponse.of(note, userId));

return CursorBasePaginatedResponse.of(notes);
}

public CursorBasePaginatedResponse<NoteGetResponse> getNotesBySongId(boolean hasLyrics, Long songId, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllBySongId(hasLyrics, songId, userId, cursor, PageRequest.ofSize(size))
public CursorBasePaginatedResponse<NoteGetResponse> getNotesBySongId(boolean hasLyrics, Long songId, NoteType noteType, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllBySongId(hasLyrics, songId, noteType, userId, cursor, PageRequest.ofSize(size))
.map(note -> NoteGetResponse.of(note, userId));

return CursorBasePaginatedResponse.of(notes);
}

public CursorBasePaginatedResponse<NoteGetResponse> getBookmarkedNotes(boolean hasLyrics, Long artistId, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllBookmarkedAndByArtistId(hasLyrics, artistId, userId, cursor, PageRequest.ofSize(size))
public CursorBasePaginatedResponse<NoteGetResponse> getBookmarkedNotes(boolean hasLyrics, Long artistId, NoteType noteType, Long userId, Long cursor, int size) {
Slice<NoteGetResponse> notes = noteQueryRepository.findAllBookmarkedAndByArtistId(hasLyrics, artistId, noteType, userId, cursor, PageRequest.ofSize(size))
.map(note -> NoteGetResponse.of(note, userId));

return CursorBasePaginatedResponse.of(notes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.projectlyrics.server.global.slack.interceptor.SlackInterceptor;
import com.projectlyrics.server.domain.auth.authentication.interceptor.AdminInterceptor;
import com.projectlyrics.server.domain.auth.authentication.interceptor.VersionVerificationInterceptor;
import com.projectlyrics.server.global.converter.NoteTypeConverter;
import com.projectlyrics.server.global.converter.ProfileCharacterConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)

@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new NoteTypeConverter());
registry.addConverter(new ProfileCharacterConverter());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.projectlyrics.server.global.converter;

import com.projectlyrics.server.domain.note.entity.NoteType;
import org.springframework.core.convert.converter.Converter;

public class NoteTypeConverter implements Converter<String, NoteType> {
@Override
public NoteType convert(String source) {
return NoteType.of(source);
}
}
Loading
Loading