feat: user

This commit is contained in:
박정민 2024-07-19 09:40:59 +09:00
parent f6e601c9f9
commit ff9dad72f4
4 changed files with 15 additions and 5 deletions

View File

@ -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<Qna> createQna(@RequestBody Qna qna) {
public ResponseEntity<Qna> 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){

View File

@ -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;

View File

@ -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);
}

View File

@ -32,6 +32,8 @@ public class User {
private UserRole role;
private String refreshToken;
private String name;