Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import es.princip.ringus.domain.mentee.MenteeRepository;
import es.princip.ringus.domain.mentor.Mentor;
import es.princip.ringus.domain.mentor.MentorRepository;
import es.princip.ringus.domain.mentoring.MentoringRepository;
import es.princip.ringus.domain.serviceTerm.ServiceTermAgreement;
import es.princip.ringus.global.exception.CustomRuntimeException;
import es.princip.ringus.global.util.UniversityDomainUtil;
Expand All @@ -32,6 +33,7 @@ public class MemberService {
private final MentorRepository mentorRepository;
private final MenteeRepository menteeRepository;
private final PasswordEncoder passwordEncoder;
private final MentoringRepository mentoringRepository;

/**
* 회원 저장 (이메일 인증 후 회원가입 진행)
Expand Down Expand Up @@ -68,7 +70,7 @@ public MemberResponse getMember(Long memberId) {
Mentor mentor = mentorRepository.findByMemberId(memberId)
.orElseThrow(() -> new CustomRuntimeException(MemberErrorCode.MEMBER_NOT_FOUND));

MentorProfileResponse profile = MentorProfileResponse.from(mentor);
MentorProfileResponse profile = MentorProfileResponse.from(mentor, mentoringRepository.findMentoringCountBy(mentor.getId()));
return MemberResponse.of(member, profile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import es.princip.ringus.domain.member.MemberRepository;
import es.princip.ringus.domain.mentor.Mentor;
import es.princip.ringus.domain.mentor.MentorRepository;
import es.princip.ringus.domain.mentoring.MentoringRepository;
import es.princip.ringus.domain.support.CursorResponse;
import es.princip.ringus.global.exception.CustomRuntimeException;
import es.princip.ringus.presentation.mentor.dto.*;
Expand All @@ -25,6 +26,7 @@ public class MentorService {

private final MemberRepository memberRepository;
private final MentorRepository mentorRepository;
private final MentoringRepository mentoringRepository;

@Transactional
public Long register(Long memberId, MentorRequest request) {
Expand All @@ -47,7 +49,7 @@ public Long register(Long memberId, MentorRequest request) {

@Transactional
public Long edit(Long memberId, EditMentorRequest request) {
Mentor mentor = mentorRepository.findById(memberId)
Mentor mentor = mentorRepository.findByMemberId(memberId)
.orElseThrow(() -> new CustomRuntimeException(MentorErrorCode.MENTOR_PROFILE_NOT_FOUND));
mentor.edit(request);
return mentor.getId();
Expand All @@ -57,6 +59,7 @@ public CursorResponse<MentorCardResponse> getMentorBy(CursorRequest request, Pag
if(request.isBookmarked()) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new CustomRuntimeException(MemberErrorCode.MEMBER_NOT_FOUND));
Long menteeId = member.getId();

if (member.isNotMentee()) {
throw new CustomRuntimeException(MemberErrorCode.MEMBER_TYPE_DIFFERENT);
Expand All @@ -71,6 +74,9 @@ public CursorResponse<MentorCardResponse> getMentorBy(CursorRequest request, Pag
public MentorDetailResponse getDetailBy(Long mentorId) {
Mentor mentor = mentorRepository.findById(mentorId)
.orElseThrow(() -> new CustomRuntimeException(MentorErrorCode.MENTOR_PROFILE_NOT_FOUND));
return MentorDetailResponse.from(mentor);
return MentorDetailResponse.from(
mentor,
mentoringRepository.findMentoringCountBy(mentorId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import es.princip.ringus.domain.exception.MentorErrorCode;
import es.princip.ringus.domain.mentor.Mentor;
import es.princip.ringus.domain.mentor.MentorRepository;
import es.princip.ringus.domain.mentoring.MentoringRepository;
import es.princip.ringus.global.exception.CustomRuntimeException;
import es.princip.ringus.presentation.mentor.dto.MyMentorResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,10 +15,11 @@
@Transactional(readOnly = true)
public class MyMentorService {
private final MentorRepository mentorRepository;
private final MentoringRepository mentoringRepository;

public MyMentorResponse getDetailBy(Long memberId) {
Mentor mentor = mentorRepository.findByMemberId(memberId)
.orElseThrow(() -> new CustomRuntimeException(MentorErrorCode.MENTOR_PROFILE_NOT_FOUND));
return MyMentorResponse.from(mentor);
return MyMentorResponse.from(mentor, mentoringRepository.findMentoringCountBy(mentor.getId()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package es.princip.ringus.domain.bookmark;

public interface BookmarkQueryDslRepository {
Boolean isBookmarked(Long memberId, Long mentorId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package es.princip.ringus.domain.bookmark;

import es.princip.ringus.domain.support.QueryDslSupport;

import static es.princip.ringus.domain.mentoring.QMentoring.mentoring;

public class BookmarkQueryDslRepositoryImpl extends QueryDslSupport implements BookmarkQueryDslRepository {
@Override
public Boolean isBookmarked(Long memberId, Long mentorId) {
return queryFactory.select()
.from(mentoring)
.where(mentoring.mentor.id.eq(mentorId).and(mentoring.mentee.memberId.eq(memberId)))
.fetchCount() > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Optional;

@Repository
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {
public interface BookmarkRepository extends JpaRepository<Bookmark, Long>, BookmarkQueryDslRepository {
Optional<Bookmark> findByMentorAndMentee(Mentor mentor, Mentee mentee);

Optional<Bookmark> findByMentee(Mentee mentee);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.querydsl.core.Tuple;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.jpa.impl.JPAQuery;
import es.princip.ringus.domain.bookmark.BookmarkRepository;
import es.princip.ringus.domain.mentoring.MentoringQueryDslRepository;
import es.princip.ringus.domain.support.QueryDslSupport;
import es.princip.ringus.presentation.mentor.dto.CursorRequest;
import es.princip.ringus.presentation.mentor.dto.MentorCardResponse;
Expand All @@ -23,6 +25,9 @@
@RequiredArgsConstructor
public class MentorQueryDslRepositoryImpl extends QueryDslSupport implements MentorQueryDslRepository{

private final MentoringQueryDslRepository mentoringQueryDslRepository;
private final BookmarkRepository bookmarkRepository;

private List<Tuple> fetchMentor(
final Pageable pageable,
final CursorRequest request,
Expand All @@ -31,33 +36,33 @@ private List<Tuple> fetchMentor(
JPAQuery<Tuple> query;
if (request.isSuggested()) {
query = queryFactory.select(
mentor.id,
mentor.nickname,
mentor.profileImage,
mentor.introduction,
mentor.organization,
mentor.message,
mentoring.mentoringStatus
)
.from(mentor);
mentor.id,
mentor.nickname,
mentor.profileImage,
mentor.introduction,
mentor.organization,
mentor.message,
mentoring.mentoringStatus
)
.from(mentor);
}
else {
query = queryFactory.select(
mentor.id,
mentor.nickname,
mentor.profileImage,
mentor.introduction,
mentor.organization,
mentor.message
)
.from(mentor);
mentor.id,
mentor.nickname,
mentor.profileImage,
mentor.introduction,
mentor.organization,
mentor.message
)
.from(mentor);
}
queryFilter(query, request, memberId);

query
.where(request.cursor() != null ? mentor.id.goe(request.cursor()) : mentor.id.isNotNull())
.orderBy(new OrderSpecifier<>(ASC, mentor.id))
.limit(pageable.getPageSize() + 1);
.where(request.cursor() != null ? mentor.id.goe(request.cursor()) : mentor.id.isNotNull())
.orderBy(new OrderSpecifier<>(ASC, mentor.id))
.limit(pageable.getPageSize() + 1);

return query.fetch();
}
Expand All @@ -67,33 +72,33 @@ private List<MentorCardResponse> fetchContent(
final CursorRequest request,
final Long memberId
) {

return fetchMentor(pageable, request, memberId).stream()
.map(tuple -> {
if (request.isSuggested()) {
// 🔥 북마크된 멘토 조회 (멘토 목록 조회)
return MentorCardResponse.of(
tuple.get(mentor.id),
tuple.get(mentor.nickname),
tuple.get(mentor.profileImage),
tuple.get(mentor.introduction),
tuple.get(mentor.organization),
tuple.get(mentoring.mentoringStatus.stringValue())

);
} else {
return MentorCardResponse.of(
tuple.get(mentor.id),
tuple.get(mentor.nickname),
tuple.get(mentor.profileImage),
tuple.get(mentor.introduction),
tuple.get(mentor.organization),
tuple.get(mentor.message),
0
);
}
})
.toList();
.map(tuple -> {
if (request.isSuggested()) {
return MentorCardResponse.of(
tuple.get(mentor.id),
tuple.get(mentor.nickname),
tuple.get(mentor.profileImage),
tuple.get(mentor.introduction),
tuple.get(mentor.organization),
tuple.get(mentor.message),
tuple.get(mentoring.mentoringStatus.stringValue()),
mentoringQueryDslRepository.findMentoringCountBy(tuple.get(mentor.id))
);
} else {
return MentorCardResponse.of(
tuple.get(mentor.id),
tuple.get(mentor.nickname),
tuple.get(mentor.profileImage),
tuple.get(mentor.introduction),
tuple.get(mentor.organization),
tuple.get(mentor.message),
mentoringQueryDslRepository.findMentoringCountBy(tuple.get(mentor.id)),
bookmarkRepository.isBookmarked(memberId, tuple.get(mentor.id))
);
}
})
.toList();
}

private void queryFilter(
Expand All @@ -103,18 +108,18 @@ private void queryFilter(
) {
if(request.isBookmarked() && memberId != null){
query
.join(mentee).on(mentee.memberId.eq(memberId))
.join(bookmark).on(mentor.id.eq(bookmark.mentor.id))
.where(
bookmark.mentee.id.eq(mentee.id)
);
.join(mentee).on(mentee.memberId.eq(memberId))
.join(bookmark).on(mentor.id.eq(bookmark.mentor.id))
.where(
bookmark.mentee.id.eq(mentee.id)
);
}
// 멘토링 상태 필터 적용 (멘토링 신청 현황 조회 시)

if (request.isSuggested()) {
query.join(mentoring).on(mentoring.mentor.id.eq(mentor.id))
.where(
mentoring.mentoringStatus.isNotNull()
);
.where(
mentoring.mentoringStatus.isNotNull()
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package es.princip.ringus.domain.mentoring;

public interface MentoringQueryDslRepository {
Long findMentoringCountBy(Long mentorId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package es.princip.ringus.domain.mentoring;

import es.princip.ringus.domain.support.QueryDslSupport;

import static es.princip.ringus.domain.mentoring.QMentoring.mentoring;

public class MentoringQueryDslRepositoryImpl extends QueryDslSupport implements MentoringQueryDslRepository {

@Override
public Long findMentoringCountBy(Long mentorId) {
return queryFactory.select()
.from(mentoring)
.where(mentoring.mentor.id.eq(mentorId).and(mentoring.mentoringStatus.eq(MentoringStatus.COMPLETED)))
.fetchCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
import java.util.Optional;

@Repository
public interface MentoringRepository extends JpaRepository<Mentoring, Long> {
public interface MentoringRepository extends JpaRepository<Mentoring, Long>, MentoringQueryDslRepository {
Optional<Mentoring> findByMenteeIdAndMentorId(Long menteeId, Long mentorId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ public record MentorProfileResponse(
String nickname,
ProfileImageResponse image,
OrganizationResponse organization,
int mentoringCount
Long mentoringCount
) {
public static MentorProfileResponse from(final Mentor mentor){
return new MentorProfileResponse(mentor.getNickname(), ProfileImageResponse.from(mentor.getProfileImage()), OrganizationResponse.from(mentor.getOrganization()),0);
public static MentorProfileResponse from(final Mentor mentor, Long mentoringCount){
return new MentorProfileResponse(
mentor.getNickname(),
ProfileImageResponse.from(mentor.getProfileImage()),
OrganizationResponse.from(mentor.getOrganization()),
mentoringCount
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/mentor")
Expand Down Expand Up @@ -55,14 +54,11 @@ public ResponseEntity<ApiResponseWrapper<CursorResponse<MentorCardResponse>>> ge
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse
) {

Long memberId = Optional.ofNullable(request)
.filter(CursorRequest::isBookmarked)
.map(req -> SessionToMemberId.getSessionMemberId(httpServletRequest, httpServletResponse))
.orElse(null);

log.info(request.toString());
log.info(pageable.toString());
CursorResponse<MentorCardResponse> response = mentorService.getMentorBy(request, pageable, memberId);
return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "성공", response));
}
Expand Down
Loading