Skip to content
Snippets Groups Projects
Commit dff1ac9b authored by 찬주 이's avatar 찬주 이
Browse files

Add delete Favorite

parent 344b763b
Branches
No related tags found
No related merge requests found
Pipeline #8340 canceled
...@@ -3,6 +3,7 @@ package kr.ajousw.myspringweb.controller; ...@@ -3,6 +3,7 @@ package kr.ajousw.myspringweb.controller;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -49,5 +50,10 @@ public class MyspringwebController { ...@@ -49,5 +50,10 @@ public class MyspringwebController {
public int postLikes(@RequestBody FavoriteMusicRequestDto favorite){ public int postLikes(@RequestBody FavoriteMusicRequestDto favorite){
return service.saveFavorite(favorite); return service.saveFavorite(favorite);
} }
@DeleteMapping(value = "/likes/{id}")
public void deleteLikes(@PathVariable String id) {
service.deleteFavorite(id);
}
} }
...@@ -8,4 +8,5 @@ import kr.ajousw.myspringweb.entity.FavoriteMusic; ...@@ -8,4 +8,5 @@ import kr.ajousw.myspringweb.entity.FavoriteMusic;
public interface FavoriteRepository extends JpaRepository<FavoriteMusic, String> { public interface FavoriteRepository extends JpaRepository<FavoriteMusic, String> {
List<FavoriteMusic> findAll(); List<FavoriteMusic> findAll();
void deleteById(String collectionId);
} }
...@@ -3,6 +3,7 @@ package kr.ajousw.myspringweb.service; ...@@ -3,6 +3,7 @@ package kr.ajousw.myspringweb.service;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -55,4 +56,13 @@ public class MusicService { ...@@ -55,4 +56,13 @@ public class MusicService {
return 0; return 0;
} }
} }
public void deleteFavorite(String id) {
boolean exists = albumsRepo.existsById(id);
if (!exists) {
throw new IllegalArgumentException("Invalid favorite ID: " + id);
}
albumsRepo.deleteById(id);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment