forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminMentorApplicationService.java
More file actions
66 lines (54 loc) · 3.04 KB
/
AdminMentorApplicationService.java
File metadata and controls
66 lines (54 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.example.solidconnection.admin.service;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_FOUND;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED;
import com.example.solidconnection.admin.dto.MentorApplicationCountResponse;
import com.example.solidconnection.admin.dto.MentorApplicationRejectRequest;
import com.example.solidconnection.admin.dto.MentorApplicationSearchCondition;
import com.example.solidconnection.admin.dto.MentorApplicationSearchResponse;
import com.example.solidconnection.common.exception.CustomException;
import com.example.solidconnection.mentor.domain.MentorApplication;
import com.example.solidconnection.mentor.domain.MentorApplicationStatus;
import com.example.solidconnection.mentor.repository.MentorApplicationRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
@Service
public class AdminMentorApplicationService {
private final MentorApplicationRepository mentorApplicationRepository;
@Transactional(readOnly = true)
public Page<MentorApplicationSearchResponse> searchMentorApplications(
MentorApplicationSearchCondition mentorApplicationSearchCondition,
Pageable pageable
) {
return mentorApplicationRepository.searchMentorApplications(mentorApplicationSearchCondition, pageable);
}
@Transactional
public void approveMentorApplication(Long mentorApplicationId) {
MentorApplication mentorApplication = mentorApplicationRepository.findById(mentorApplicationId)
.orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND));
if(mentorApplication.getUniversityId() == null){
throw new CustomException(MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED);
}
mentorApplication.approve();
}
@Transactional
public void rejectMentorApplication(long mentorApplicationId, MentorApplicationRejectRequest request) {
MentorApplication mentorApplication = mentorApplicationRepository.findById(mentorApplicationId)
.orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND));
mentorApplication.reject(request.rejectedReason());
}
@Transactional(readOnly = true)
public MentorApplicationCountResponse getMentorApplicationCount() {
long approvedCount = mentorApplicationRepository.countByMentorApplicationStatus(MentorApplicationStatus.APPROVED);
long pendingCount = mentorApplicationRepository.countByMentorApplicationStatus(MentorApplicationStatus.PENDING);
long rejectedCount = mentorApplicationRepository.countByMentorApplicationStatus(MentorApplicationStatus.REJECTED);
return new MentorApplicationCountResponse(
approvedCount,
pendingCount,
rejectedCount
);
}
}