Merge branch 'BE/userinfo' into 'backend'

Be/userinfo

See merge request s11-webmobile1-sub2/S11P12A701!128
This commit is contained in:
박정민 2024-08-09 10:23:44 +09:00
commit 5c63fb2362
6 changed files with 45 additions and 23 deletions

View File

@ -131,9 +131,11 @@ public class QnaController {
} }
@GetMapping("/{id}") @GetMapping("/{id}")
public ResponseEntity<QnaResponseDto> getQna(@PathVariable Long id) { public ResponseEntity<QnaResponseDto> getQna(@PathVariable Long id, HttpServletRequest request) {
try { try {
QnaResponseDto findQna = qnaService.getQna(id); String token = request.getHeader("Authorization");
long userId = Long.parseLong(jwtUtil.getUserId(token));
QnaResponseDto findQna = qnaService.getQna(id, userId);
return new ResponseEntity<>(findQna, HttpStatus.ACCEPTED); return new ResponseEntity<>(findQna, HttpStatus.ACCEPTED);
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -52,5 +52,7 @@ public class Qna {
@JoinColumn(name = "lecture_id") @JoinColumn(name = "lecture_id")
private Lecture lecture; private Lecture lecture;
private boolean isMine;
} }

View File

@ -1,6 +1,7 @@
package com.edufocus.edufocus.qna.entity; package com.edufocus.edufocus.qna.entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -11,6 +12,7 @@ import java.util.Date;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder
public class QnaResponseDto { public class QnaResponseDto {
@ -20,15 +22,17 @@ public class QnaResponseDto {
private String content; private String content;
private Date createtAt; private Date createtAt;
private String answer; private String answer;
public static QnaResponseDto toEntity(Qna qna) private boolean isMine;
{
public static QnaResponseDto toEntity(Qna qna) {
return new QnaResponseDto( return new QnaResponseDto(
qna.getId(), qna.getId(),
qna.getTitle(), qna.getTitle(),
qna.getUser().getName(), qna.getUser().getName(),
qna.getContent(), qna.getContent(),
qna.getCreatedAt(), qna.getCreatedAt(),
qna.getAnswer() qna.getAnswer(),
qna.isMine()
); );
} }

View File

@ -20,7 +20,7 @@ public interface QnaService {
void deleteQna(Long id, Long userId) throws SQLException; void deleteQna(Long id, Long userId) throws SQLException;
QnaResponseDto getQna(Long id) throws SQLException; QnaResponseDto getQna(Long id, Long userId) throws SQLException;
List<QnaResponseDto> getAllQnasByLecture(Long lectureId, int pageNumber) throws SQLException; List<QnaResponseDto> getAllQnasByLecture(Long lectureId, int pageNumber) throws SQLException;

View File

@ -91,11 +91,12 @@ public class QnaServiceImpl implements QnaService {
} }
@Override @Override
public QnaResponseDto getQna(Long id) { public QnaResponseDto getQna(Long id, Long userId) {
Optional<Qna> qna;
Qna qna;
try { try {
qna = qnaRepository.findById(id); qna = qnaRepository.findById(id).orElse(null);
} catch (Exception e) { } catch (Exception e) {
@ -103,8 +104,18 @@ public class QnaServiceImpl implements QnaService {
throw new RuntimeException("Qna 없음 " + id, e); throw new RuntimeException("Qna 없음 " + id, e);
} }
QnaResponseDto dto = QnaResponseDto.builder()
.id(qna.getId())
.title(qna.getTitle())
.username(qna.getUser().getName())
.content(qna.getContent())
.createtAt(qna.getCreatedAt())
.answer(qna.getAnswer())
.isMine(userId == qna.getUser().getId())
.build();
return QnaResponseDto.toEntity(qna.get());
return dto;
} }

View File

@ -29,7 +29,7 @@ public class ReportController {
@PostMapping("/submit/quizSet/{reportSetId}") @PostMapping("/submit/quizSet/{reportSetId}")
public ResponseEntity<?> submit(@PathVariable("reportSetId") UUID reportSetId, @RequestBody ReportRequest reportRequest, HttpServletRequest request) { public ResponseEntity<?> submit(@PathVariable("reportSetId") UUID reportSetId, @RequestBody ReportRequest reportRequest, HttpServletRequest request) {
String token = request.getHeader("Authorization"); String token = request.getHeader("Authoriza]tion");
long userId = Long.parseLong(jwtUtil.getUserId(token)); long userId = Long.parseLong(jwtUtil.getUserId(token));
if (userService.isTeacher(userId)) if (userService.isTeacher(userId))
@ -49,38 +49,41 @@ public class ReportController {
List<ReportResponse> reportResponses = reportService.findReports(lectureId, userId); List<ReportResponse> reportResponses = reportService.findReports(lectureId, userId);
if(reportResponses.isEmpty()) if (reportResponses.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(reportResponses, HttpStatus.OK); return new ResponseEntity<>(reportResponses, HttpStatus.OK);
} }
@GetMapping("/reportDetail/{reportId}") @GetMapping("/reportDetail/{reportId}")
public ResponseEntity<ReportDetailResponseDto> searchDetailReport(@PathVariable("reportId") long reportId){ public ResponseEntity<ReportDetailResponseDto> searchDetailReport(@PathVariable("reportId") long reportId) {
ReportDetailResponseDto detailReport = reportService.reportDetail(reportId); ReportDetailResponseDto detailReport = reportService.reportDetail(reportId);
return new ResponseEntity<>(detailReport, HttpStatus.OK); return new ResponseEntity<>(detailReport, HttpStatus.OK);
} }
<<<<<<< HEAD
=======
>>>>>>> 935331e7e93d9c25ec6f32ba6155ed19b5fd60f9
@GetMapping("/teacher/reportSet/{lectureId}") @GetMapping("/teacher/reportSet/{lectureId}")
public ResponseEntity<List<ReportSetResponse>> searchReportSets(@PathVariable("lectureId") long lectureId){ public ResponseEntity<List<ReportSetResponse>> searchReportSets(@PathVariable("lectureId") long lectureId) {
List<ReportSetResponse> reportSetResponses = reportService.findReportSets(lectureId); List<ReportSetResponse> reportSetResponses = reportService.findReportSets(lectureId);
if(reportSetResponses.isEmpty()) if (reportSetResponses.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(reportSetResponses, HttpStatus.OK); return new ResponseEntity<>(reportSetResponses, HttpStatus.OK);
} }
@GetMapping("/teacher/report/{reportSetId}") @GetMapping("/teacher/report/{reportSetId}")
public ResponseEntity<?> searchReports(@PathVariable("reportSetId") UUID reportSetId){ public ResponseEntity<?> searchReports(@PathVariable("reportSetId") UUID reportSetId) {
List<ReportResponse> reportResponses = reportService.findReports(reportSetId); List<ReportResponse> reportResponses = reportService.findReports(reportSetId);
if(reportResponses.isEmpty()) if (reportResponses.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(reportResponses, HttpStatus.OK); return new ResponseEntity<>(reportResponses, HttpStatus.OK);
} }