● ReplyController ( 댓글 삭제 )
페이지 정보
본문
package web.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.MediaType;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
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;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import web.dto.PageRequestDTO;
import web.dto.PageResponseDTO;
import web.dto.ReplyDTO;
import web.service.ReplyService;
@RestController
@Log4j2
@RequestMapping("/replies")
@RequiredArgsConstructor
public class ReplyController {
private final ReplyService replyService;
@Operation(summary = "Replies POST", description = "POST 방식으로 댓글 등록")
@PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Long> register(@Valid @RequestBody ReplyDTO replyDTO, BindingResult bindingResult) throws BindException {
log.info(replyDTO);
if(bindingResult.hasErrors()) {
throw new BindException(bindingResult);
}
Map<String, Long> resultMap = new HashMap<>();
Long rno = replyService.register(replyDTO);
resultMap.put("rno", rno);
return resultMap;
}
@Operation(summary = "Replies of Board", description = "GET 방식으로 댓글 목록")
@GetMapping(value = "/list/{bno}")
public PageResponseDTO<ReplyDTO> getList(@PathVariable("bno") Long bno, PageRequestDTO pageRequestDTO){
PageResponseDTO<ReplyDTO> responseDTO = replyService.getListOfBoard(bno, pageRequestDTO);
return responseDTO;
}
@Operation(summary = "Read Reply", description = "GET 방식으로 댓글 조회")
@GetMapping(value = "/{rno}")
public ReplyDTO getReplyDTO(@PathVariable("rno") Long rno) {
ReplyDTO replyDTO = replyService.read(rno);
return replyDTO;
}
@Operation(summary = "Delete Reply", description = "DELETE 방식으로 댓글 삭제")
@DeleteMapping("/{rno}")
public Map<String, Long> remove(@PathVariable("rno") Long rno) {
replyService.remove(rno);
Map<String, Long> resultMap = new HashMap<>();
resultMap.put("rno", rno);
return resultMap;
}
}
- 이전글▲ localhost:8080/swagger-ui/index.html 24.06.23
- 다음글▲ localhost:8080/swagger-ui/index.html 24.06.23
댓글목록
등록된 댓글이 없습니다.