Skip to content
Snippets Groups Projects
Commit b6e327ce authored by lucple's avatar lucple
Browse files

[Add] delete Favorite

parent 6074ce98
Branches
No related tags found
No related merge requests found
Pipeline #8348 failed
......@@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.List;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -49,7 +50,18 @@ public class MyWebController {
return service.saveFavorite(favorite);
}
@DeleteMapping(value = "/likes/{id}")
public void deleteLikes(@PathVariable String id) {
service.deleteFavorite(id);
}
}
/*
* curl -X POST http://localhost:8098/likes -d '@postSong.json' -H
* "Content-Type:application/json"
* Invoke-WebRequest -Uri "http://localhost:8098/likes" -Method POST -InFile
* 'postSong.json' -ContentType "application/json"
*/
// @RestController
// public class MyWebController {
......
......@@ -7,4 +7,6 @@ import kr.ajousw.myspringweb.entity.FavoriteMusic;
public interface FavoriteRepository extends
JpaRepository<FavoriteMusic, String> {
List<FavoriteMusic> findAll();
void deleteById(String id);
}
\ No newline at end of file
......@@ -60,4 +60,12 @@ public class MusicService {
return 0;
}
}
public void deleteFavorite(String id) {
try {
albumsRepo.deleteById(id);
} catch (Exception e) {
System.out.println("Exception occurred while deleting the favorite: " + e.toString());
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment