Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
get songs by genre&vibe
get songs by sort
update song
delete song by id
  • Loading branch information
rojae1339 committed Nov 26, 2024
1 parent 23f663a commit 6bb5728
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface AuctionRepository extends JpaRepository<Auction, Long> {
List<Auction> findAuctionsByOrderByEndDateAsc();
}
5 changes: 5 additions & 0 deletions moun/src/main/java/io/moun/api/common/domain/SortType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.moun.api.common.domain;

public enum SortType {
EXPIRED_DATE,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.moun.api.common.domain;

public class StaticVariables {
public static final String getURL = "GET /api/songs/{id}/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@ public MounFile getMounFileByFileName(String fileName) {
return mounFileRepository.findMounFileByGeneratedFileName(fileName).orElseThrow(
() -> new RuntimeException("Id not founded"));
}


public void deleteById(Long fileId) {
mounFileRepository.deleteById(fileId);
}
}
33 changes: 30 additions & 3 deletions moun/src/main/java/io/moun/api/song/controller/SongController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.moun.api.song.controller;

import io.moun.api.song.controller.dto.SongAuctionVO;
import io.moun.api.song.controller.dto.SongRequest;
import io.moun.api.song.controller.dto.SongResponse;
import io.moun.api.song.domain.Song;
import io.moun.api.song.service.SongService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -47,9 +50,23 @@ public ResponseEntity<List<SongResponse>> getSongInformationByMember(@PathVariab
return songService.findAllSongByMemberId(id);
}

@GetMapping("/songs") //find all songs - read
public ResponseEntity<List<SongResponse>> getAllSongs() {
return songService.findAllSongs();
@GetMapping("/songs") // find all songs / by genre & vibe / sortby - read
public ResponseEntity<List<SongResponse>> getAllSongs(@RequestParam(name = "genre", required = false) String genre,
@RequestParam(name = "vibe", required = false) String vibe,
@RequestParam(name = "sort", required = false) String sortType) {

// 모든 필터가 없는 경우
if (genre == null && vibe == null && sortType == null) {
return songService.findAllSongs();
}

// 정렬만 요청된 경우
if (genre == null && vibe == null && !sortType.isEmpty()) {
return songService.findSongsBySortType(sortType);
}

// 장르와 분위기 요청된 경우 (정렬 포함 가능)
return songService.findSongsByGenreAndVibe(genre, vibe);
}

@GetMapping("/songs/{id}/audio") //download song file - read
Expand All @@ -61,4 +78,14 @@ public ResponseEntity<byte[]> downloadSongFileBySongId(@PathVariable Long id) th
public ResponseEntity<byte[]> downloadImageFileBySongId(@PathVariable Long id) throws IOException {
return songService.downloadImageFileBySongId(id);
}

@PatchMapping("/songs/{id}")
public ResponseEntity<String> updateSongEntity(@PathVariable Long id, @RequestBody SongRequest request) {
return songService.updateSong(id, request);
}

@DeleteMapping("/songs/{id}")
public ResponseEntity<String> deleteSongById(@PathVariable Long id) {
return songService.deleteSongsById(id);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.moun.api.song.controller.dto;

import io.moun.api.song.domain.GenreType;
import io.moun.api.song.domain.VibeType;
import lombok.Data;

import java.util.Set;
Expand All @@ -11,6 +9,6 @@ public class SongRequest {

private String title;
private String description;
private Set<GenreType> songGenres;
private Set<VibeType> songVibes;
private Set<String> songGenres;
private Set<String> songVibes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import io.moun.api.auction.domain.Auction;
import io.moun.api.common.BaseEntityResponse;
import io.moun.api.common.domain.StaticVariables;
import io.moun.api.song.domain.GenreType;
import io.moun.api.song.domain.Song;
import io.moun.api.song.domain.VibeType;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -45,5 +47,19 @@ public SongResponse(LocalDateTime createdDate, LocalDateTime lastModifiedDate, L
this.auction = auction;
}


public static SongResponse create(Song song) {
return SongResponse.builder()
.id(song.getId())
.title(song.getTitle())
.description(song.getDescription())
.songGenres(song.getSongGenres())
.songVibes(song.getSongVibes())
.songFileURL(StaticVariables.getURL + "audio")
.coverFileURL(StaticVariables.getURL + "image")
.createdDate(song.getCreatedDate())
.lastModifiedDate(song.getLastModifiedDate())
.memberId(song.getMember().getId())
.auction(song.getAuction())
.build();
}
}
9 changes: 8 additions & 1 deletion moun/src/main/java/io/moun/api/song/domain/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ public Song(String title, String description, Set<GenreType> songGenres, Set<Vib
this.auction = auction;
}

public void update(MounFile songFile, MounFile coverImageFile) {
public void addFile(MounFile songFile, MounFile coverImageFile) {
this.songFile = songFile;
this.coverImageFile = coverImageFile;
}

public void update(String title, String description, Set<GenreType> genreTypes, Set<VibeType> vibeTypes) {
this.title = title;
this.description = description;
this.songGenres = genreTypes;
this.songVibes = vibeTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public interface SongRepository extends JpaRepository<Song, Long> {


List<Song> findAllByMember(Member member);
List<Song> findSongsByMember_Id(Long memberId);
List<Song> findSongsBySongGenresAndSongVibes(GenreType genre, VibeType vibe);
}
Loading

0 comments on commit 6bb5728

Please sign in to comment.