jpablog : delete post
This commit is contained in:
@@ -9,9 +9,7 @@ import com.example.jpablog.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@@ -28,6 +26,12 @@ public class BoardApiController {
|
||||
return new ResponseDto<>(1, HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/board/{id}")
|
||||
public ResponseDto<Integer> deleteById(@PathVariable Long id) {
|
||||
boardService.글삭제하기(id);
|
||||
return new ResponseDto<>(1, HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
/*// 기본 로그인
|
||||
@PostMapping("/user/login")
|
||||
public ResponseDto<Integer> login(@RequestBody User user, HttpSession session) {
|
||||
|
||||
@@ -36,4 +36,9 @@ public class BoardService {
|
||||
return boardRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("글 상세보기 실패 : 아이디를 찾을 수 없습니다."));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void 글삭제하기(Long id) {
|
||||
boardRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ let index = {
|
||||
init : function () {
|
||||
$("#btn-save").on("click", () => {
|
||||
this.save();
|
||||
});
|
||||
})
|
||||
$("#btn-delete").on("click", () => {
|
||||
this.deleteById();
|
||||
})
|
||||
},
|
||||
save : function () {
|
||||
let data = {
|
||||
@@ -22,6 +25,19 @@ let index = {
|
||||
alert(JSON.stringify(error));
|
||||
});
|
||||
},
|
||||
deleteById : function () {
|
||||
const id = $("#id").text();
|
||||
$.ajax({
|
||||
type: "delete",
|
||||
url: "/api/board/" + id,
|
||||
dataType: "json"
|
||||
}).done(function (resp){
|
||||
alert("삭제 완료!");
|
||||
location.href = "/";
|
||||
}).fail(function (error){
|
||||
alert(JSON.stringify(error));
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
index.init();
|
||||
@@ -4,9 +4,16 @@
|
||||
|
||||
<div class="container">
|
||||
<button class="btn btn-secondary" onclick="history.back()">돌아가기</button>
|
||||
<button id="btn-update" class="btn btn-warning">수정</button>
|
||||
<button id="btn-delete" class="btn btn-danger">삭제</button>
|
||||
<c:if test="${board.user.id == principal.user.id}" >
|
||||
<button id="btn-update" class="btn btn-warning">수정</button>
|
||||
<button id="btn-delete" class="btn btn-danger">삭제</button>
|
||||
</c:if>
|
||||
<br/><br/>
|
||||
<div>
|
||||
글 번호 : <span id="id"><i>${board.id}</i></span>
|
||||
작성자 : <span><i>${board.user.username}</i></span>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-group">
|
||||
<h3 id="title">${board.title}</h3>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user