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 fb3356f..0a4c1d2 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 @@ -2,6 +2,8 @@ package com.edufocus.edufocus.qna.controller; import com.edufocus.edufocus.qna.entity.Qna; import com.edufocus.edufocus.qna.service.QnaService; +import com.edufocus.edufocus.user.util.JWTUtil; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import okhttp3.Response; @@ -18,12 +20,17 @@ import java.util.List; @RequiredArgsConstructor public class QnaController { private final QnaService qnaService; - + private final JWTUtil jwtUtil; @PostMapping - public ResponseEntity createQna(@RequestBody Qna qna) { + public ResponseEntity createQna(@RequestBody Qna qna , HttpServletRequest request) { + + try{ - qnaService.createQna(qna); + String token = request.getHeader("Authorization"); + Long userId = Long.parseLong(jwtUtil.getUserId(token)); + + qnaService.createQna(userId,qna); return new ResponseEntity<>(qna, HttpStatus.CREATED); }catch (Exception e){ diff --git a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java index a1b8d94..8acf0f5 100644 --- a/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java +++ b/backend/src/main/java/com/edufocus/edufocus/qna/service/QnaService.java @@ -11,7 +11,7 @@ import java.util.List; @Service public interface QnaService { - void createQna(Qna qna) throws SQLException; + void createQna(Long id,Qna qna) throws SQLException; void updateQna(Long id,Qna qna) throws SQLException; void deleteQna(Long id) throws SQLException; Qna getQna(Long id) throws SQLException; 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 18a59c1..4e6cdc2 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 @@ -20,9 +20,10 @@ public class QnaServiceImpl implements QnaService{ @Override - public void createQna(Qna qna) { + public void createQna(Long id,Qna qna) { + qna.setId(id); qnaRepository.save(qna); } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/User.java b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/User.java index 74cff10..8bc7952 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/entity/User.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/entity/User.java @@ -32,6 +32,8 @@ public class User { private UserRole role; private String refreshToken; + private String name; +