feat : reportSet delete 추가

This commit is contained in:
yulmam 2024-08-08 22:04:47 +09:00
parent 0f60c9c4cf
commit 5dfbcb3dd2
4 changed files with 22 additions and 0 deletions

View File

@ -87,4 +87,13 @@ public class ReportController {
return new ResponseEntity<>(reportResponses, HttpStatus.OK);
}
@DeleteMapping("/teacher/report/{reportSetId}")
public ResponseEntity<?> deleteReportSet(@PathVariable("reportSetId") UUID reportSetId, HttpServletRequest request){
String token = request.getHeader("Authorization");
long userId = Long.parseLong(jwtUtil.getUserId(token));
reportService.deleteReportSet(reportSetId, userId);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -55,4 +55,8 @@ public class ReportSet {
.testAt(createAt)
.build();
}
public long findUserId(){
return lecture.getUser().getId();
}
}

View File

@ -20,4 +20,6 @@ public interface ReportService {
List<ReportResponse> findReports(long lectureId, long userid);
UUID initReportSet(long lectureId, long quizSetId);
void deleteReportSet(UUID reportSetId, long userId);
}

View File

@ -172,4 +172,11 @@ public class ReportServiceImpl implements ReportService {
return reportSet.getId();
}
@Override
public void deleteReportSet(UUID reportSetId, long userId) {
ReportSet reportSet = reportSetRepository.findById(reportSetId).orElseThrow(NoSuchElementException::new);
if(reportSet.findUserId() == userId)
reportSetRepository.delete(reportSet);
}
}