diff --git a/src/main/java/site/balpyo/script/controller/EveryScriptController.java b/src/main/java/site/balpyo/script/controller/EveryScriptController.java index 5503bbf..f0229a1 100644 --- a/src/main/java/site/balpyo/script/controller/EveryScriptController.java +++ b/src/main/java/site/balpyo/script/controller/EveryScriptController.java @@ -50,4 +50,12 @@ public ResponseEntity patchDetailScript(@RequestBody ScriptReque return scriptService.patchScript(scriptRequest, uid,scriptId); } + @DeleteMapping("/script/detail/{scriptId}") + public ResponseEntity deleteDetailScript(@RequestHeader(value = "UID", required = false) String uid, + @PathVariable Long scriptId){ + + if(CommonUtils.isAnyParameterNullOrBlank(uid)) return CommonResponse.error(ErrorEnum.BALPYO_UID_KEY_MISSING); + return scriptService.deleteScript(uid,scriptId); + } + } diff --git a/src/main/java/site/balpyo/script/service/ScriptService.java b/src/main/java/site/balpyo/script/service/ScriptService.java index 1039b2f..2e9c4d7 100644 --- a/src/main/java/site/balpyo/script/service/ScriptService.java +++ b/src/main/java/site/balpyo/script/service/ScriptService.java @@ -130,4 +130,16 @@ public ResponseEntity patchScript(ScriptRequest scriptRequest, S } + public ResponseEntity deleteScript(String uid, Long scriptId) { + Optional optionalScriptEntity = scriptRepository.findScriptByGuestUidAndScriptId(uid, scriptId); + + if(optionalScriptEntity.isEmpty())return CommonResponse.error(ErrorEnum.SCRIPT_DETAIL_NOT_FOUND); + + ScriptEntity scriptEntity = optionalScriptEntity.get(); + + scriptRepository.delete(scriptEntity); + + return CommonResponse.success(""); + + } }