Skip to content

Commit

Permalink
[FEAT] member Ticket 감소 로직 추가(decreaseMemberTicketCount) 및 createUniv…
Browse files Browse the repository at this point in the history
…ersityExamRecord 에러 처리 수정
  • Loading branch information
sung-silver committed Jan 12, 2024
1 parent 395f960 commit 294481d
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static com.nonsoolmate.nonsoolmateServer.external.aws.FolderName.EXAM_SHEET_FOLDER_NAME;

import com.nonsoolmate.nonsoolmateServer.domain.member.entity.Member;
import com.nonsoolmate.nonsoolmateServer.domain.member.exception.MemberException;
import com.nonsoolmate.nonsoolmateServer.domain.member.repository.MemberRepository;
import com.nonsoolmate.nonsoolmateServer.domain.university.entity.UniversityExam;
import com.nonsoolmate.nonsoolmateServer.domain.university.exception.UniversityExamException;
import com.nonsoolmate.nonsoolmateServer.domain.university.repository.UniversityExamRepository;
Expand All @@ -18,6 +20,7 @@
import com.nonsoolmate.nonsoolmateServer.domain.universityExamRecord.exception.UniversityExamRecordException;
import com.nonsoolmate.nonsoolmateServer.domain.universityExamRecord.exception.UniversityExamRecordExceptionType;
import com.nonsoolmate.nonsoolmateServer.domain.universityExamRecord.repository.UniversityExamRecordRepository;
import com.nonsoolmate.nonsoolmateServer.external.aws.error.AWSException;
import com.nonsoolmate.nonsoolmateServer.external.aws.service.CloudFrontService;
import com.nonsoolmate.nonsoolmateServer.external.aws.service.S3Service;
import lombok.RequiredArgsConstructor;
Expand All @@ -32,6 +35,7 @@ public class UniversityExamRecordService {
private final UniversityExamRepository universityExamRepository;
private final CloudFrontService cloudFrontService;
private final S3Service s3Service;
private final MemberRepository memberRepository;

public UniversityExamRecordResponseDTO getUniversityExamRecord(Long universityExamId, Member member) {

Expand Down Expand Up @@ -61,21 +65,33 @@ public UniversityExamRecordResultResponseDTO getUniversityExamRecordResult(Long
public UniversityExamRecordIdResponse createUniversityExamRecord(
CreateUniversityExamRequestDTO request, Member member) {
UniversityExam universityExam = getUniversityExam(request.universityExamId());
String fileName = s3Service.validateURL(EXAM_SHEET_FOLDER_NAME, request.memberSheetFileName());
try {
String fileName = s3Service.validateURL(EXAM_SHEET_FOLDER_NAME, request.memberSheetFileName());
UniversityExamRecord universityexamRecord = createUniversityExamRecord(universityExam, member,
request.memberTakeTimeExam(),
fileName);
UniversityExamRecord saveUniversityUniversityExamRecord = universityExamRecordRepository.save(
universityexamRecord);
decreaseMemberTicketCount(member);
return UniversityExamRecordIdResponse.of(saveUniversityUniversityExamRecord.getUniversityExamRecordId());
} catch (AWSException | MemberException e) {
throw e;
} catch (RuntimeException e) {
s3Service.deleteFile(EXAM_SHEET_FOLDER_NAME, request.memberSheetFileName());
throw new UniversityExamRecordException(
UniversityExamRecordExceptionType.CREATE_UNIVERSITY_EXAM_RECORD_FAIL);
}
}

private void decreaseMemberTicketCount(Member member) {
try {
member.decreaseTicket();
memberRepository.save(member);
} catch (MemberException e) {
throw e;
}
}

private UniversityExamRecord createUniversityExamRecord(UniversityExam universityExam, Member member,
int takeTimeExam, String sheetFileName) {
return UniversityExamRecord.builder()
Expand Down

0 comments on commit 294481d

Please sign in to comment.