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 @@ -17,6 +17,8 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mentorings")
@RequiredArgsConstructor
Expand All @@ -43,6 +45,20 @@ public RsData<MentoringPagingResponse> getMentorings(
);
}

@GetMapping("/my")
@PreAuthorize("hasRole('MENTOR')")
@Operation(summary = "나의 멘토링 목록 조회", description = "나의 멘토링 목록을 조회합니다. 로그인한 멘토만 접근할 수 있습니다.")
public RsData<List<MentoringWithTagsDto>> getMyMentorings() {
Mentor mentor = memberStorage.findMentorByMember(rq.getActor());
List<MentoringWithTagsDto> resDto = mentoringService.getMyMentorings(mentor);

return new RsData<>(
"200",
"나의 멘토링 목록을 조회하였습니다.",
resDto
);
}

@GetMapping("/{mentoringId}")
@Operation(summary = "멘토링 상세 조회", description = "특정 멘토링을 상세 조회합니다.")
public RsData<MentoringResponse> getMentoring(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public interface MentoringRepository extends JpaRepository<Mentoring, Long>, MentoringRepositoryCustom {
List<Mentoring> findByMentorId(Long mentorId);
List<Mentoring> findByMentorIdOrderByIdDesc(Long mentorId);
Optional<Mentoring> findTopByOrderByIdDesc();
boolean existsByMentorIdAndTitle(Long mentorId, String title);
boolean existsByMentorIdAndTitleAndIdNot(Long mentorId, String title, Long MentoringId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public Page<MentoringWithTagsDto> getMentorings(String keyword, int page, int si
.map(MentoringWithTagsDto::from);
}

@Transactional(readOnly = true)
public List<MentoringWithTagsDto> getMyMentorings(Mentor mentor) {
return mentoringRepository.findByMentorIdOrderByIdDesc(mentor.getId())
.stream()
.map(MentoringWithTagsDto::from)
.toList();
}

@Transactional(readOnly = true)
public MentoringResponse getMentoring(Long mentoringId) {
Mentoring mentoring = mentoringStorage.findMentoring(mentoringId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ void returnEmptyPage() {
}
}

@Test
@DisplayName("나의 멘토링 목록 조회")
void getMentorings() {
// given
Mentoring mentoring2 = MentoringFixture.create(2L, mentor2);

List<Mentoring> mentorings = List.of(mentoring1);

when(mentoringRepository.findByMentorIdOrderByIdDesc(mentor1.getId()))
.thenReturn(mentorings);

// when
List<MentoringWithTagsDto> result = mentoringService.getMyMentorings(mentor1);

// then
assertThat(result).hasSize(1);
verify(mentoringRepository).findByMentorIdOrderByIdDesc(mentor1.getId());
}

@Nested
@DisplayName("멘토링 조회")
class Describe_getMentoring {
Expand Down