From 456f6767383cba61f4f19da5b3e1a4ed51382bae Mon Sep 17 00:00:00 2001
From: suhyeon <suhyeon@ajou.ac.kr>
Date: Mon, 17 Jul 2023 17:49:14 +0900
Subject: [PATCH] Add delete Favorite

---
 .../ajousw/myspringweb/controller/MyWebController.java |  7 +++++++
 .../kr/ajousw/myspringweb/service/MusicService.java    | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java b/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java
index 5d11a47..6346200 100644
--- a/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java
+++ b/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java
@@ -15,6 +15,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;
@@ -51,4 +52,10 @@ public class MyWebController {
     public int postLikes(@RequestBody FavoriteMusicRequestDto favorite) {
         return service.saveFavorite(favorite);
     }
+
+    @DeleteMapping(value="/likes/{id}")
+    @Transactional
+    public int deleteById(@PathVariable String id) {
+        return service.deleteFavorite(id);
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/kr/ajousw/myspringweb/service/MusicService.java b/src/main/java/kr/ajousw/myspringweb/service/MusicService.java
index e640bb7..91fee75 100644
--- a/src/main/java/kr/ajousw/myspringweb/service/MusicService.java
+++ b/src/main/java/kr/ajousw/myspringweb/service/MusicService.java
@@ -68,6 +68,16 @@ public class MusicService {
         }
     }
 
+    public int deleteFavorite(@PathVariable String id) {
 
+        try {
+            albumsRepo.deleteById(id);
+            return 1;
+
+        } catch (Exception e) {
+            System.out.println(e.toString());
+            return 0;
 
+        }
+    }
 }
\ No newline at end of file
-- 
GitLab