From 35c98af73f89d0c5598234a2e3fa38b875156278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Thu, 8 Aug 2024 10:51:07 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=20qna=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/qna/controller/QnaController.java | 13 ++++++++----- .../edufocus/qna/service/QnaServiceImpl.java | 14 ++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java index c4c2a0a..6a20a67 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java @@ -49,17 +49,20 @@ public class QnaController { public ResponseEntity createAnswer(@PathVariable("qna_id") Long qna_id, @RequestBody QnaRequestDto qnaRequestDto, HttpServletRequest request) { try { String token = request.getHeader("Authorization"); + System.out.println(token); Long userId = Long.parseLong(jwtUtil.getUserId(token)); User findUser = userRepository.findById(userId).orElse(null); if (findUser.getRole() != UserRole.ADMIN) { - throw new RuntimeException(); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); + } QnaResponseDto responseDto = qnaService.createAnswer(qna_id, qnaRequestDto); return new ResponseEntity<>(responseDto, HttpStatus.ACCEPTED); } catch (Exception e) { - throw new RuntimeException(e); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); + } } @@ -91,12 +94,12 @@ public class QnaController { System.out.println("delete answer"); if (findUser.getRole() != UserRole.ADMIN) { - throw new RuntimeException(); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } qnaService.deleteAnswer(qna_id); return new ResponseEntity<>(HttpStatus.ACCEPTED); } catch (Exception e) { - throw new RuntimeException(e); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } } @@ -110,7 +113,7 @@ public class QnaController { return new ResponseEntity<>(qnaResponseDto, HttpStatus.ACCEPTED); } catch (Exception e) { - throw new RuntimeException(e); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } } diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java index 3454e27..6180416 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaServiceImpl.java @@ -57,18 +57,15 @@ public class QnaServiceImpl implements QnaService { System.out.println("userId:" + userId); - Qna qna = qnaRepository.findById(id).orElse(null); - System.out.println("quesiton에 있는거: " + qna.getUser().getId()); + Qna findQna = qnaRepository.findById(id).orElse(null); + System.out.println("quesiton에 있는거: " + findQna.getUser().getId()); User user = userRepository.findById(userId).orElse(null); - if (qna.getUser().getId() != userId) { + if (findQna.getUser().getId() != userId || user.getRole() != UserRole.STUDENT) { throw new RuntimeException(); } - Qna findQna = qnaRepository.findById(id) - .orElseThrow(() -> new RuntimeException("QnA not found")); - findQna.setModifiedAt(new Date()); findQna.setTitle(qnaRequestDto.getTitle()); findQna.setContent(qnaRequestDto.getContent()); @@ -129,11 +126,12 @@ public class QnaServiceImpl implements QnaService { public QnaResponseDto createAnswer(Long id, QnaRequestDto qnaRequestDto) throws SQLException { Qna findQna = qnaRepository.findById(id).orElse(null); - findQna.setAnswer(qnaRequestDto.getAnswer()); - if (findQna.getAnswer() != null) { throw new RuntimeException(); } + findQna.setAnswer(qnaRequestDto.getAnswer()); + + qnaRepository.save(findQna); return QnaResponseDto.toEntity(findQna); From 026e4c376647cedeef71b07f455efb24c02cb8f2 Mon Sep 17 00:00:00 2001 From: yulmam <70622601+yulmam@users.noreply.github.com> Date: Thu, 8 Aug 2024 10:54:17 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90?= =?UTF-8?q?=20=EC=A0=95=EB=A0=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/edufocus/edufocus/board/service/BoardServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java index a357de2..de97761 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java @@ -40,7 +40,7 @@ public class BoardServiceImpl implements BoardService { @Transactional public List findBoards(int pageNo, String category, long lectureId) { - Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE, Sort.by("created_at").descending()); + Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE, Sort.by("id").descending()); List boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable).getContent(); From 1567e6ce078ea7dbd000c514e5eed3e8066a0bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Thu, 8 Aug 2024 13:05:08 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20qna=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/qna/controller/QnaController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java index 6a20a67..51d816b 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/controller/QnaController.java @@ -75,13 +75,13 @@ public class QnaController { if (findUser.getRole() != UserRole.ADMIN) { System.out.println("role 안맞음"); - throw new RuntimeException("update 실패"); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } QnaResponseDto responseDto = qnaService.updateAnswer(qna_id, qnaRequestDto); return new ResponseEntity<>(responseDto, HttpStatus.ACCEPTED); } catch (Exception e) { - throw new RuntimeException(e); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } } @@ -126,7 +126,7 @@ public class QnaController { return new ResponseEntity<>(HttpStatus.ACCEPTED); } catch (SQLException e) { - throw new RuntimeException(e); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } } @@ -137,7 +137,7 @@ public class QnaController { return new ResponseEntity<>(findQna, HttpStatus.ACCEPTED); } catch (SQLException e) { - throw new RuntimeException(e); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } } @@ -150,7 +150,7 @@ public class QnaController { return new ResponseEntity<>(qnaList, HttpStatus.ACCEPTED); } catch (SQLException e) { - throw new RuntimeException(e); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } }