Merge branch 'backend' of https://lab.ssafy.com/s11-webmobile1-sub2/S11P12A701 into be/quiz
This commit is contained in:
commit
8c37e13cce
@ -40,7 +40,7 @@ public class BoardServiceImpl implements BoardService {
|
||||
|
||||
@Transactional
|
||||
public List<ResponseBoardSummaryDto> 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<Board> boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable).getContent();
|
||||
|
||||
|
@ -49,17 +49,20 @@ public class QnaController {
|
||||
public ResponseEntity<QnaResponseDto> 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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +126,7 @@ public class QnaController {
|
||||
return new ResponseEntity<>(HttpStatus.ACCEPTED);
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,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);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user