File tree Expand file tree Collapse file tree
src/main/java/com/devkor/ifive/nadab/domain/test/application Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4444import org .springframework .stereotype .Service ;
4545import org .springframework .transaction .annotation .Transactional ;
4646
47+ import java .util .Optional ;
48+
4749@ Service
4850@ RequiredArgsConstructor
4951public class TestReportService {
@@ -211,8 +213,13 @@ public void deleteThisMonthMonthlyReport(Long userId) {
211213
212214 MonthRangeDto range = MonthRangeCalculator .getLastMonthRange ();
213215
214- MonthlyReportV2 report = monthlyReportV2Repository .findByUserIdAndMonthStartDate (user .getId (), range .monthStartDate ())
215- .orElseThrow (() -> new NotFoundException (ErrorCode .MONTHLY_REPORT_NOT_FOUND ));
216+ Optional <MonthlyReportV2 > reportV2 = monthlyReportV2Repository .findByUserIdAndMonthStartDate (user .getId (), range .monthStartDate ());
217+ if (reportV2 .isEmpty ()) {
218+ deleteMonthMonthlyReportV1 (user .getEmail ());
219+ return ;
220+ }
221+
222+ MonthlyReportV2 report = reportV2 .get ();
216223
217224 if (report .getStatus () != MonthlyReportStatus .COMPLETED ) {
218225 throw new BadRequestException (ErrorCode .MONTHLY_REPORT_NOT_COMPLETED );
You can’t perform that action at this time.
0 commit comments