Skip to content
Merged
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
package com.example.solidconnection.admin.controller;

import com.example.solidconnection.admin.dto.MentorApplicationAssignUniversityRequest;
import com.example.solidconnection.admin.dto.MentorApplicationCountResponse;
import com.example.solidconnection.admin.dto.MentorApplicationRejectRequest;
import com.example.solidconnection.admin.dto.MentorApplicationSearchCondition;
Expand DownExpand Up@@ -40,17 +41,17 @@ public ResponseEntity<PageResponse<MentorApplicationSearchResponse>> searchMento
return ResponseEntity.ok(PageResponse.of(page));
}

@PostMapping("/{mentorApplicationId}/approve")
@PostMapping("/{mentor-application-id}/approve")
public ResponseEntity<Void> approveMentorApplication(
@PathVariable("mentorApplicationId") Long mentorApplicationId
@PathVariable("mentor-application-id") Long mentorApplicationId
) {
adminMentorApplicationService.approveMentorApplication(mentorApplicationId);
return ResponseEntity.ok().build();
}

@PostMapping("/{mentorApplicationId}/reject")
@PostMapping("/{mentor-application-id}/reject")
public ResponseEntity<Void> rejectMentorApplication(
@PathVariable("mentorApplicationId") Long mentorApplicationId,
@PathVariable("mentor-application-id") Long mentorApplicationId,
@Valid @RequestBody MentorApplicationRejectRequest request
) {
adminMentorApplicationService.rejectMentorApplication(mentorApplicationId, request);
Expand All@@ -62,4 +63,14 @@ public ResponseEntity<MentorApplicationCountResponse> getMentorApplicationCount(
MentorApplicationCountResponse response = adminMentorApplicationService.getMentorApplicationCount();
return ResponseEntity.ok(response);
}

@PostMapping("/{mentor-application-id}/assign-university")
public ResponseEntity<Void> assignUniversity(
@PathVariable("mentor-application-id") Long mentorApplicationId,
@Valid @RequestBody MentorApplicationAssignUniversityRequest request
) {
Long universityId = request.universityId();
adminMentorApplicationService.assignUniversity(mentorApplicationId, universityId);
return ResponseEntity.ok().build();
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
package com.example.solidconnection.admin.dto;

import jakarta.validation.constraints.NotNull;

public record MentorApplicationAssignUniversityRequest(
@NotNull(message = "대학 ID 는 필수입니다.")
Long universityId
) {

}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
package com.example.solidconnection.admin.dto;

import com.example.solidconnection.mentor.domain.MentorApplicationStatus;
import com.example.solidconnection.mentor.domain.UniversitySelectType;
import java.time.ZonedDateTime;

public record MentorApplicationResponse(
long id,
String region,
String country,
String university,
UniversitySelectType universitySelectType,
String mentorProofUrl,
MentorApplicationStatus mentorApplicationStatus,
String rejectedReason,
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
package com.example.solidconnection.admin.dto;

import com.example.solidconnection.mentor.domain.MentorApplicationStatus;
import com.example.solidconnection.mentor.domain.UniversitySelectType;
import java.time.LocalDate;

public record MentorApplicationSearchCondition(
MentorApplicationStatus mentorApplicationStatus,
String keyword,
LocalDate createdAt
LocalDate createdAt,
UniversitySelectType universitySelectType
) {

}
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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;
Expand All@@ -11,6 +10,8 @@
import com.example.solidconnection.mentor.domain.MentorApplication;
import com.example.solidconnection.mentor.domain.MentorApplicationStatus;
import com.example.solidconnection.mentor.repository.MentorApplicationRepository;
import com.example.solidconnection.university.domain.University;
import com.example.solidconnection.university.repository.UniversityRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All@@ -22,6 +23,7 @@
public class AdminMentorApplicationService {

private final MentorApplicationRepository mentorApplicationRepository;
private final UniversityRepository universityRepository;

@Transactional(readOnly = true)
public Page<MentorApplicationSearchResponse> searchMentorApplications(
Expand All@@ -36,15 +38,14 @@ 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) {
public void rejectMentorApplication(
long mentorApplicationId,
MentorApplicationRejectRequest request
) {
MentorApplication mentorApplication = mentorApplicationRepository.findById(mentorApplicationId)
.orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND));

Expand All@@ -63,4 +64,19 @@ public MentorApplicationCountResponse getMentorApplicationCount() {
rejectedCount
);
}

@Transactional
public void assignUniversity(
Long mentorApplicationId,
Long universityId
) {
MentorApplication mentorApplication = mentorApplicationRepository.findById(mentorApplicationId)
.orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND));

mentorApplication.validateCanAssignUniversity();

University university = universityRepository.getUniversityById(universityId);

mentorApplication.assignUniversity(university.getId());
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,6 +131,7 @@ public enum ErrorCode {
MENTOR_ALREADY_EXISTS(HttpStatus.BAD_REQUEST.value(), "이미 존재하는 멘토입니다."),
MENTOR_APPLICATION_ALREADY_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "이미 승인 또는 거절된 멘토 승격 요청 입니다."),
MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED(HttpStatus.BAD_REQUEST.value(), "승인하려는 멘토 신청에 대학교가 선택되지 않았습니다."),
MENTOR_APPLICATION_NOT_OTHER_STATUS(HttpStatus.BAD_REQUEST.value(), "대학 선택 타입이 OTHER이 아닌 멘토 지원서 입니다."),

// socket
UNAUTHORIZED_SUBSCRIBE(HttpStatus.FORBIDDEN.value(), "구독 권한이 없습니다."),
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
package com.example.solidconnection.mentor.domain;

import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_CONFIRMED;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_OTHER_STATUS;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED;
import static java.time.ZoneOffset.UTC;
import static java.time.temporal.ChronoUnit.MICROS;

Expand DownExpand Up@@ -122,18 +124,39 @@ private void validateExchangeStatus(ExchangeStatus exchangeStatus) {
}

public void approve(){
if(this.mentorApplicationStatus != MentorApplicationStatus.PENDING) {
throw new CustomException(MENTOR_APPLICATION_ALREADY_CONFIRMED);
}
validatePending();
validateCanApprove();
this.mentorApplicationStatus = MentorApplicationStatus.APPROVED;
this.approvedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS);
}

private void validateCanApprove(){
if(this.universitySelectType != UniversitySelectType.CATALOG){
throw new CustomException(MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED);
}
}

public void reject(String rejectedReason){
validatePending();
this.mentorApplicationStatus = MentorApplicationStatus.REJECTED;
this.rejectedReason = rejectedReason;
}

public void assignUniversity(long universityId) {
this.universityId = universityId;
this.universitySelectType = UniversitySelectType.CATALOG;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

도메인 메서드와 이를 사용하는 서비스 메서드 모두 APPROVED, REJECTED 인 지원서에도 대학 추가가 가능한 것으로 보입니다(관련 검증을 찾을 수 없습니다). 만약 PENDING 상태의 지원서만 대학이 추가되어야 한다면 관련 검증이 있어야 할 거 같습니다.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whqtker 말씀 하신 내용 적용 하였습니다!


public void validateCanAssignUniversity(){
validatePending();
if(this.universitySelectType != UniversitySelectType.OTHER){
throw new CustomException(MENTOR_APPLICATION_NOT_OTHER_STATUS);
}
}

private void validatePending(){
if(this.mentorApplicationStatus != MentorApplicationStatus.PENDING) {
throw new CustomException(MENTOR_APPLICATION_ALREADY_CONFIRMED);
}
this.mentorApplicationStatus = MentorApplicationStatus.REJECTED;
this.rejectedReason = rejectedReason;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
import com.example.solidconnection.admin.dto.MentorApplicationSearchResponse;
import com.example.solidconnection.admin.dto.SiteUserResponse;
import com.example.solidconnection.mentor.domain.MentorApplicationStatus;
import com.example.solidconnection.mentor.domain.UniversitySelectType;
import com.querydsl.core.types.ConstructorExpression;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
Expand DownExpand Up@@ -48,6 +49,7 @@ public class MentorApplicationFilterRepositoryImpl implements MentorApplicationF
region.koreanName,
country.koreanName,
university.koreanName,
mentorApplication.universitySelectType,
mentorApplication.mentorProofUrl,
mentorApplication.mentorApplicationStatus,
mentorApplication.rejectedReason,
Expand DownExpand Up@@ -81,7 +83,8 @@ public Page<MentorApplicationSearchResponse> searchMentorApplications(MentorAppl
.where(
verifyMentorStatusEq(condition.mentorApplicationStatus()),
keywordContains(condition.keyword()),
createdAtEq(condition.createdAt())
createdAtEq(condition.createdAt()),
universitySelectTypeEq(condition.universitySelectType())
)
.orderBy(mentorApplication.createdAt.desc())
.offset(pageable.getOffset())
Expand DownExpand Up@@ -110,7 +113,8 @@ private JPAQuery<Long> createCountQuery(MentorApplicationSearchCondition conditi
return query.where(
verifyMentorStatusEq(condition.mentorApplicationStatus()),
keywordContains(condition.keyword()),
createdAtEq(condition.createdAt())
createdAtEq(condition.createdAt()),
universitySelectTypeEq(condition.universitySelectType())
);
}

Expand DownExpand Up@@ -142,4 +146,8 @@ private BooleanExpression createdAtEq(LocalDate createdAt) {
endOfDay.atZone(SYSTEM_ZONE_ID)
);
}

private BooleanExpression universitySelectTypeEq(UniversitySelectType universitySelectType) {
return universitySelectType != null ? mentorApplication.universitySelectType.eq(universitySelectType) : null;
}
}
Loading
Loading